ayushtkn commented on a change in pull request #2793:
URL: https://github.com/apache/hive/pull/2793#discussion_r753953113



##########
File path: common/src/java/org/apache/hadoop/hive/common/FileUtils.java
##########
@@ -661,11 +663,50 @@ static boolean copy(FileSystem srcFS, Path src,
       // is tried and it fails. We depend upon that behaviour in cases like 
replication,
       // wherein if distcp fails, there is good reason to not plod along with 
a trivial
       // implementation, and fail instead.
+      boolean shouldPreserveXAttrs = shouldPreserveXAttrs(conf, srcFS, dstFS);
+      Map<Path, Map<String, byte[]>> XAttrsToDestMapping = null;
+      if (shouldPreserveXAttrs) {
+        XAttrsToDestMapping = new HashMap<>();
+        fetchXAttrs(XAttrsToDestMapping, srcFS, srcFS.getFileStatus(src), dst);
+      }
       copied = FileUtil.copy(srcFS, src, dstFS, dst, deleteSource, overwrite, 
conf);
+      if (copied && shouldPreserveXAttrs) {
+        for (Map.Entry<Path, Map<String, byte[]>> xAttrs : 
XAttrsToDestMapping.entrySet()) {
+          for (Map.Entry<String, byte[]> val : xAttrs.getValue().entrySet()) {
+            dstFS.setXAttr(xAttrs.getKey(), val.getKey(), val.getValue());
+          }
+        }
+      }
     }
     return copied;
   }
 
+  public static void fetchXAttrs(Map<Path, Map<String, byte[]>> xAttrs, 
FileSystem srcFS, FileStatus srcStatus, Path dst) throws IOException {
+    Path src = srcStatus.getPath();
+    Path dstFile = new Path(dst, src.getName());

Review comment:
       Check the path resolution, It won't work in couple of cases like if src 
is a file & /dst doesn't exist.
   Can extract the logic for FileUtils.copy from hadoop & have a preserveXAttr 
flag additional




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



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

Reply via email to