Skip to content

Commit 72ccb3a

Browse files
authored
HDDS-14177. OFS#getTrashRoot should use the internal FS username instead of current UGI (#9502)
1 parent 03cc8fa commit 72ccb3a

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/OFSPath.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,13 +365,25 @@ public static String getTempMountBucketNameOfCurrentUser()
365365
* @return trash root for the given path.
366366
*/
367367
public Path getTrashRoot() {
368+
return getTrashRoot(null);
369+
}
370+
371+
/**
372+
* Return trash root for the given path and username.
373+
* The username can be specified to use the proxy user instead of {@link UserGroupInformation#getCurrentUser()}.
374+
* @param username the username used to get the trash root path. If it is not specified,
375+
* will fall back to {@link UserGroupInformation#getCurrentUser()}.
376+
* @return trash root for the given path and username.
377+
*/
378+
public Path getTrashRoot(String username) {
368379
if (!this.isKey()) {
369380
throw new RuntimeException("Recursive rm of volume or bucket with trash" +
370381
" enabled is not permitted. Consider using the -skipTrash option.");
371382
}
372383
try {
373-
final String username =
374-
UserGroupInformation.getCurrentUser().getShortUserName();
384+
if (StringUtils.isEmpty(username)) {
385+
username = UserGroupInformation.getCurrentUser().getShortUserName();
386+
}
375387
final Path pathRoot = new Path(
376388
OZONE_OFS_URI_SCHEME, authority, OZONE_URI_DELIMITER);
377389
final Path pathToVolume = new Path(pathRoot, volumeName);

hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractRootedOzoneFileSystemTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,6 +1719,14 @@ private void checkFileStatusOwner(int expectedSize, String expectedOwner,
17191719
res.forEach(e -> assertEquals(expectedOwner, e.getOwner()));
17201720
}
17211721

1722+
@Test
1723+
void testGetTrashRoot() {
1724+
String testKeyName = "keyToBeDeleted";
1725+
Path keyPath1 = new Path(bucketPath, testKeyName);
1726+
assertEquals(new Path(rootPath + volumeName + "/" + bucketName + "/" +
1727+
TRASH_PREFIX + "/" + USER1 + "/"), userOfs.getTrashRoot(keyPath1));
1728+
}
1729+
17221730
/**
17231731
* Test getTrashRoots() in OFS. Different from the existing test for o3fs.
17241732
*/

hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicRootedOzoneFileSystem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ public String getUsername() {
10181018
public Path getTrashRoot(Path path) {
10191019
OFSPath ofsPath = new OFSPath(path,
10201020
ozoneConfiguration);
1021-
return this.makeQualified(ofsPath.getTrashRoot());
1021+
return this.makeQualified(ofsPath.getTrashRoot(getUsername()));
10221022
}
10231023

10241024
/**

0 commit comments

Comments
 (0)