sunithabeeram commented on a change in pull request #3671: Make different
PinotFS concrete classes have the same behaviors
URL: https://github.com/apache/incubator-pinot/pull/3671#discussion_r246639047
##########
File path:
pinot-hadoop-filesystem/src/main/java/com/linkedin/pinot/filesystem/HadoopPinotFS.java
##########
@@ -97,39 +109,93 @@ public boolean move(URI srcUri, URI dstUri, boolean
overwrite) throws IOExceptio
*/
@Override
public boolean copy(URI srcUri, URI dstUri) throws IOException {
- Path source = new Path(srcUri);
- Path target = new Path(dstUri);
- RemoteIterator<LocatedFileStatus> sourceFiles =
_hadoopFS.listFiles(source, true);
- if (sourceFiles != null) {
- while (sourceFiles.hasNext()) {
- boolean succeeded = FileUtil.copy(_hadoopFS,
sourceFiles.next().getPath(), _hadoopFS, target, true, _hadoopConf);
- if (!succeeded) {
- return false;
+ if (!exists(srcUri)) {
+ LOGGER.warn("Source {} does not exist", srcUri);
+ return false;
+ }
+ if (srcUri.equals(dstUri)) {
+ LOGGER.info("Source {} and destination {} are the same.", srcUri,
dstUri);
+ return true;
+ }
+ if (!dstUri.getRawPath().startsWith(srcUri.getRawPath()) &&
exists(dstUri)) {
+ delete(dstUri, true);
+ }
+ if (isDirectory(srcUri)) {
+ mkdir(dstUri);
+
+ List<String> exclusionList = null;
+ // Cater for destination being directory within the source directory
+ if (dstUri.getRawPath().startsWith(srcUri.getRawPath())) {
+ FileStatus[] srcFiles = listStatus(new Path(srcUri), false);
+ exclusionList = new ArrayList<>(srcFiles.length);
+ for (FileStatus srcFile : srcFiles) {
+ Path dstPath = new Path(dstUri.getRawPath(),
srcFile.getPath().getName());
+ exclusionList.add(dstPath.toString());
}
}
+ doCopyDirectory(srcUri, dstUri, exclusionList);
+ } else {
+ doCopyFile(srcUri, dstUri);
}
return true;
}
+ /**
+ * Does the actual copy behavior on directory.
+ */
+ private void doCopyDirectory(URI srcUri, URI dstUri, List<String>
exclusionList) throws IOException {
+ FileStatus[] srcFiles = listStatus(new Path(srcUri), true);
+ for (FileStatus srcFile : srcFiles) {
+ Path srcPath = srcFile.getPath();
+ Path dstPath = new Path(dstUri.getPath(), srcFile.getPath().getName());
+ if (exclusionList == null ||
!exclusionList.contains(srcPath.toUri().getRawPath())) {
+ if (isDirectory(srcPath.toUri())) {
+ doCopyDirectory(srcPath.toUri(), dstPath.toUri(), exclusionList);
+ } else {
+ doCopyFile(srcPath.toUri(), dstPath.toUri());
+ }
+ }
+ }
+ }
+
+ /**
+ * Does the actual copy behavior on file.
+ */
+ private boolean doCopyFile(URI srcUri, URI dstUri) throws IOException {
+ Path source = new Path(srcUri);
+ Path target = new Path(dstUri);
+ URI parentUri = target.getParent().toUri();
+ if (!exists(parentUri)) {
+ mkdir(parentUri);
+ }
+ return FileUtil.copy(_hadoopFS, source, _hadoopFS, target, false,
_hadoopConf);
+ }
+
+ /**
+ * Check if
Review comment:
Incomplete
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]