diff --git a/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java b/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java index 3fa1233..ef5fac1 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java @@ -2697,7 +2697,7 @@ private static void copyFiles(final HiveConf conf, final FileSystem destFs, } if (inheritPerms) { - HdfsUtils.setFullFileStatus(conf, fullDestStatus, destFs, destPath, false); + HdfsUtils.setFullFileStatus(conf, fullDestStatus, srcFile, destFs, destPath, false); } if (null != newFiles) { newFiles.add(destPath); @@ -2860,6 +2860,18 @@ public static boolean moveFile(final HiveConf conf, Path srcf, final Path destf, if (destIsSubDir) { FileStatus[] srcs = destFs.listStatus(srcf, FileUtils.HIDDEN_FILES_PATH_FILTER); + if (inheritPerms) { + try { + HdfsUtils.setFullFileStatus(conf, destStatus, + destFs.getFileStatus(destf), + destFs, destf, false); + } catch (IOException e) { + String msg = "Error setting permission of file " + destf; + LOG.error(msg); + throw new HiveException(msg, e); + } + } + List> futures = new LinkedList<>(); final ExecutorService pool = Executors.newFixedThreadPool( conf.getIntVar(ConfVars.HIVE_MOVE_FILES_THREAD_COUNT), @@ -2874,7 +2886,7 @@ public Void call() throws Exception { try { if(destFs.rename(status.getPath(), destf)) { if (inheritPerms) { - HdfsUtils.setFullFileStatus(conf, desiredStatus, destFs, destPath, false); + HdfsUtils.setFullFileStatus(conf, desiredStatus, destFs.getFileStatus(destf), destFs, destPath, false); } } else { throw new IOException("rename for src path: " + status.getPath() + " to dest path:" diff --git a/shims/common/src/main/java/org/apache/hadoop/hive/io/HdfsUtils.java b/shims/common/src/main/java/org/apache/hadoop/hive/io/HdfsUtils.java index c2060fc..567cfcc 100644 --- a/shims/common/src/main/java/org/apache/hadoop/hive/io/HdfsUtils.java +++ b/shims/common/src/main/java/org/apache/hadoop/hive/io/HdfsUtils.java @@ -58,6 +58,11 @@ public static Path getFileIdPath( public static void setFullFileStatus(Configuration conf, HdfsUtils.HadoopFileStatus sourceStatus, FileSystem fs, Path target, boolean recursion) throws IOException { + setFullFileStatus(conf, sourceStatus, null, fs, target, recursion); + } + + public static void setFullFileStatus(Configuration conf, HdfsUtils.HadoopFileStatus sourceStatus, + FileStatus targetStatus, FileSystem fs, Path target, boolean recursion) throws IOException { FileStatus fStatus= sourceStatus.getFileStatus(); String group = fStatus.getGroup(); boolean aclEnabled = Objects.equal(conf.get("dfs.namenode.acls.enabled"), "true"); @@ -111,7 +116,10 @@ public static void setFullFileStatus(Configuration conf, HdfsUtils.HadoopFileSta } } else { if (group != null && !group.isEmpty()) { - fs.setOwner(target, null, group); + if (targetStatus == null || + !targetStatus.getGroup().equals(group)) { + fs.setOwner(target, null, group); + } } if (aclEnabled) { if (null != aclEntries) {