diff --git common/src/java/org/apache/hadoop/hive/common/FileUtils.java common/src/java/org/apache/hadoop/hive/common/FileUtils.java index 3ed2d08..a799b30 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 FileUtils.copy(srcFs, srcPath, destFs, destPath, + true, // delete source + false, // overwrite destination + hc); } } @@ -851,11 +860,11 @@ public static boolean deleteTmpFile(File tempFile) { } return false; } - - + + /** * Return whenever all paths in the collection are schemaless - * + * * @param paths * @return */ @@ -870,16 +879,16 @@ public static boolean pathsContainNoScheme(Collection paths) { /** * Returns the deepest candidate path for the given path. - * + * * prioritizes on paths including schema / then includes matches without schema - * + * * @param path * @param candidates the candidate paths * @return */ public static Path getParentRegardlessOfScheme(Path path, Collection candidates) { Path schemalessPath = Path.getPathWithoutSchemeAndAuthority(path); - + for(;path!=null && schemalessPath!=null; path=path.getParent(),schemalessPath=schemalessPath.getParent()){ if(candidates.contains(path)) return path; @@ -892,13 +901,13 @@ public static Path getParentRegardlessOfScheme(Path path, Collection candi /** * Checks whenever path is inside the given subtree - * + * * return true iff * * path = subtree * * subtreeContains(path,d) for any descendant of the subtree node * @param path the path in question * @param subtree - * + * * @return */ public static boolean isPathWithinSubtree(Path path, Path subtree) { 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); }