private void copy ( AlluxioURI srcPath , AlluxioURI dstPath , boolean recursive ) throws AlluxioException , IOException { URIStatus srcStatus = mFileSystem . getStatus ( srcPath ) ; URIStatus dstStatus = null ; try { dstStatus = mFileSystem . getStatus ( dstPath ) ; } catch ( FileDoesNotExistException e ) { // if the destination does not exist, it will be created } if ( ! srcStatus . isFolder ( ) ) { if ( dstStatus != null && dstStatus . isFolder ( ) ) { dstPath = new AlluxioURI ( PathUtils . concatPath ( dstPath . getPath ( ) , srcPath . getName ( ) ) ) ; } copyFile ( srcPath , dstPath ) ; } else { if ( ! recursive ) { throw new IOException ( srcPath . getPath ( ) + " is a directory, to copy it please use \"cp -R <src> <dst>\"" ) ; } List < URIStatus > statuses ; statuses = mFileSystem . listStatus ( srcPath ) ; if ( dstStatus != null ) { if ( ! dstStatus . isFolder ( ) ) { throw new InvalidPathException ( ExceptionMessage . DESTINATION_CANNOT_BE_FILE . getMessage ( ) ) ; } // if copying a directory to an existing directory, the copied directory will become a // subdirectory of the destination if ( srcStatus . isFolder ( ) ) { dstPath = new AlluxioURI ( PathUtils . concatPath ( dstPath . getPath ( ) , srcPath . getName ( ) ) ) ; mFileSystem . createDirectory ( dstPath ) ; System . out . println ( "Created directory: " + dstPath ) ; } } if ( dstStatus == null ) { mFileSystem . createDirectory ( dstPath ) ; System . out . println ( "Created directory: " + dstPath ) ; } preserveAttributes ( srcPath , dstPath ) ; List < String > errorMessages = new ArrayList <> ( ) ; for ( URIStatus status : statuses ) { try { copy ( new AlluxioURI ( srcPath . getScheme ( ) , srcPath . getAuthority ( ) , status . getPath ( ) ) , new AlluxioURI ( dstPath . getScheme ( ) , dstPath . getAuthority ( ) , PathUtils . concatPath ( dstPath . getPath ( ) , status . getName ( ) ) ) , recursive ) ; } catch ( IOException e ) { errorMessages . add ( e . getMessage ( ) ) ; } } if ( errorMessages . size ( ) != 0 ) { throw new IOException ( Joiner . on ( ' ' ) . join ( errorMessages ) ) ; } } }
Copies a file or a directory in the Alluxio filesystem .