diff --git common/src/java/org/apache/hadoop/hive/common/FileUtils.java common/src/java/org/apache/hadoop/hive/common/FileUtils.java index 3ed2d08..2f02e19 100644 --- common/src/java/org/apache/hadoop/hive/common/FileUtils.java +++ common/src/java/org/apache/hadoop/hive/common/FileUtils.java @@ -627,34 +627,43 @@ public static boolean moveToTrash(FileSystem fs, Path f, Configuration conf) return result; } - public static boolean renameWithPerms(FileSystem fs, Path sourcePath, + public static boolean renameWithPerms(FileSystem srcFs, FileSystem destFs, Path srcPath, Path destPath, boolean inheritPerms, Configuration conf) throws IOException { - LOG.info("Renaming " + sourcePath + " to " + destPath); + LOG.info("Renaming " + srcPath + " to " + destPath); - // If destPath directory exists, rename call will move the sourcePath + // If destPath directory exists, rename call will move the srcPath // into destPath without failing. So check it before renaming. - if (fs.exists(destPath)) { + if (destFs.exists(destPath)) { throw new IOException("Cannot rename the source path. The destination " + "path already exists."); } - if (!inheritPerms) { - //just rename the directory - return fs.rename(sourcePath, destPath); - } else { - //rename the directory - if (fs.rename(sourcePath, destPath)) { - try { - HdfsUtils.setFullFileStatus(conf, new HdfsUtils.HadoopFileStatus(conf, fs, destPath.getParent()), fs, destPath, true); - } catch (Exception e) { - LOG.warn("Error setting permissions or group of " + destPath, e); + if (equalsFileSystem(srcFs, destFs)) { + if (!inheritPerms) { + //just rename the directory + return srcFs.rename(srcPath, destPath); + } else { + //rename the directory + if (srcFs.rename(srcPath, destPath)) { + try { + HdfsUtils.setFullFileStatus(conf, new HdfsUtils.HadoopFileStatus(conf, destFs, destPath.getParent()), destFs, destPath, true); + } catch (Exception e) { + LOG.warn("Error setting permissions or group of " + destPath, e); + } + + return true; } - return true; + return false; } - - return false; + } else { + HiveConf hc = new HiveConf(conf, conf.getClass()); + hc.setBoolVar(HiveConf.ConfVars.HIVE_WAREHOUSE_SUBDIR_INHERIT_PERMS, inheritPerms); + return copy(srcFs, srcPath, destFs, destPath, + true, // delete source + false, // overwrite destination + hc); } } diff --git metastore/src/java/org/apache/hadoop/hive/metastore/Warehouse.java metastore/src/java/org/apache/hadoop/hive/metastore/Warehouse.java index 6aca1b7..990dc7a 100755 --- metastore/src/java/org/apache/hadoop/hive/metastore/Warehouse.java +++ metastore/src/java/org/apache/hadoop/hive/metastore/Warehouse.java @@ -194,14 +194,15 @@ public boolean mkdirs(Path f, boolean inheritPermCandidate) throws MetaException return false; } - public boolean renameDir(Path sourcePath, Path destPath) throws MetaException { - return renameDir(sourcePath, destPath, false); + public boolean renameDir(Path srcPath, Path destPath) throws MetaException { + return renameDir(srcPath, destPath, false); } - public boolean renameDir(Path sourcePath, Path destPath, boolean inheritPerms) throws MetaException { + public boolean renameDir(Path srcPath, Path destPath, boolean inheritPerms) throws MetaException { try { - FileSystem fs = getFs(sourcePath); - return FileUtils.renameWithPerms(fs, sourcePath, destPath, inheritPerms, conf); + FileSystem srcFs = getFs(srcPath); + FileSystem destFs = getFs(destPath); + return FileUtils.renameWithPerms(srcFs, destFs, srcPath, destPath, inheritPerms, conf); } catch (Exception ex) { MetaStoreUtils.logAndThrowMetaException(ex); }