public boolean moveAndDeleteRelativePath ( String volume , String pathName ) throws IOException { volume = normalizePath ( volume ) ; // Move the file right now, so that it can be deleted later String newPathName = format . format ( new Date ( ) ) + "_" + uniqueId . getAndIncrement ( ) ; newPathName = TOBEDELETED + Path . SEPARATOR_CHAR + newPathName ; Path source = new Path ( volume , pathName ) ; Path target = new Path ( volume , newPathName ) ; try { if ( ! localFileSystem . rename ( source , target ) ) { // If the source does not exists, return false. // This is necessary because rename can return false if the source // does not exists. if ( ! localFileSystem . exists ( source ) ) { return false ; } // Try to recreate the parent directory just in case it gets deleted. if ( ! localFileSystem . mkdirs ( new Path ( volume , TOBEDELETED ) ) ) { throw new IOException ( "Cannot create " + TOBEDELETED + " under " + volume ) ; } // Try rename again. If it fails, return false. if ( ! localFileSystem . rename ( source , target ) ) { throw new IOException ( "Cannot rename " + source + " to " + target ) ; } } } catch ( FileNotFoundException e ) { // Return false in case that the file is not found. return false ; } DeleteTask task = new DeleteTask ( volume , pathName , newPathName ) ; execute ( volume , task ) ; return true ; }
Move the path name on one volume to a temporary location and then delete them .