ramesh0201 commented on code in PR #3264:
URL: https://github.com/apache/hive/pull/3264#discussion_r868772399


##########
ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java:
##########
@@ -5008,10 +5009,27 @@ static private boolean needToCopy(final HiveConf conf, 
Path srcf, Path destf, Fi
         boolean isOwned = FileUtils.isOwnerOfFileHierarchy(srcFs, srcs, 
configuredOwner, false);
         if (configuredOwner.equals(runningUser)) {
           // Check if owner has write permission, else it will have to copy
-          if (!(isOwned &&
-              FileUtils.isActionPermittedForFileHierarchy(
-                  srcFs, srcs, configuredOwner, FsAction.WRITE, false))) {
-            return true;
+          UserGroupInformation ugi = Utils.getUGI();
+          String currentUser = ugi.getShortUserName();
+          FileSystem fsAsUser = null;
+          UserGroupInformation proxyUser = null;
+          try {
+            if (configuredOwner != null && 
!configuredOwner.equals(currentUser)) {
+              proxyUser = 
UserGroupInformation.createProxyUser(configuredOwner, 
UserGroupInformation.getLoginUser());
+              fsAsUser = FileUtils.getFsAsUser(srcFs, proxyUser);
+            }
+            if (!(isOwned && 
FileUtils.isActionPermittedForFileHierarchy(srcFs, srcs, configuredOwner, 
FsAction.WRITE,
+                false, fsAsUser))) {
+              if (proxyUser != null) {
+                FileSystem.closeAllForUGI(proxyUser);

Review Comment:
   Agree



##########
common/src/java/org/apache/hadoop/hive/common/FileUtils.java:
##########
@@ -493,12 +505,28 @@ private static void addChildren(FileSystem fsAsUser, Path 
path, List<FileStatus>
    */
   public static boolean isActionPermittedForFileHierarchy(FileSystem fs, 
FileStatus fileStatus,
                                                           String userName, 
FsAction action) throws Exception {
-    return isActionPermittedForFileHierarchy(fs,fileStatus,userName, action, 
true);
+    UserGroupInformation ugi = Utils.getUGI();
+    String currentUser = ugi.getShortUserName();
+    FileSystem fsAsUser = null;
+    UserGroupInformation proxyUser = null;
+    boolean isPermitted = false;
+    try {
+      if (userName != null && !userName.equals(currentUser)) {
+        proxyUser = UserGroupInformation.createProxyUser(userName, 
UserGroupInformation.getLoginUser());
+        fsAsUser = getFsAsUser(fs, proxyUser);
+      }

Review Comment:
   Addressed



-- 
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