[ 
https://issues.apache.org/jira/browse/HDFS-15341?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17102540#comment-17102540
 ] 

Vince.Feng commented on HDFS-15341:
-----------------------------------

Maybe the new method shoud be added to org.apache.hadoop.fs.Trash :
{code:java}
// code placeholder
public static boolean moveToAppropriateTrash(FileSystem fs, Path p,
    Configuration conf,String user) throws IOException, InterruptedException {
    Path fullyResolvedPath = fs.resolvePath(p);
    // Get FileSystem by user.
    FileSystem fullyResolvedFs =
        FileSystem.get(fullyResolvedPath.toUri(), conf, user);
    // If the trash interval is configured server side then clobber this
    // configuration so that we always respect the server configuration.
    try {
        long trashInterval = fullyResolvedFs.getServerDefaults(
            fullyResolvedPath).getTrashInterval();
        if (0 != trashInterval) {
            Configuration confCopy = new Configuration(conf);
            
confCopy.setLong(CommonConfigurationKeysPublic.FS_TRASH_INTERVAL_KEY,
                trashInterval);
            conf = confCopy;
        }
    } catch (Exception e) {
        // If we can not determine that trash is enabled server side then
        // bail rather than potentially deleting a file when trash is enabled.
        LOG.warn("Failed to get server trash configuration", e);
        throw new IOException("Failed to get server trash configuration", e);
    }
    Trash trash = new Trash(fullyResolvedFs, conf);
    boolean success = trash.moveToTrash(fullyResolvedPath);
    if (success) {
        System.out.println("Moved: '" + p + "' to trash at: " +
            trash.getCurrentTrashDir() );
    }
    return success;
}
{code}

> HDFS Move viewfs path to trash failed.
> --------------------------------------
>
>                 Key: HDFS-15341
>                 URL: https://issues.apache.org/jira/browse/HDFS-15341
>             Project: Hadoop HDFS
>          Issue Type: Bug
>          Components: hdfs-client
>    Affects Versions: 2.10.0, 3.3.1
>            Reporter: Vince.Feng
>            Priority: Minor
>
> When HDFS client with viewfs want to move file/directory to trash by 
> RemoteUser or
> ProxyUser , it will fail. Codes like below:
> {code:java}
> // code placeholder
> Trash.moveToAppropriateTrash(fileSystem, path, conf);
> {code}
>  
>  
> 'fullyResolvedFs' will return a FileSystem with ugi of system user. But the 
> source fileSystem ugi was specified account. So the moving to trash operation 
> will fail. Because of trashRoot mismatch the real baseTrashPath.
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to