diff --git common/src/java/org/apache/hadoop/hive/common/FileUtils.java common/src/java/org/apache/hadoop/hive/common/FileUtils.java index 4591678..997bc5e 100644 --- common/src/java/org/apache/hadoop/hive/common/FileUtils.java +++ common/src/java/org/apache/hadoop/hive/common/FileUtils.java @@ -576,4 +576,29 @@ public static boolean moveToTrash(FileSystem fs, Path f, Configuration conf) thr } return result; } + + public static boolean rename(FileSystem fs, Path sourcePath, + Path destPath, boolean inheritPerms, + Configuration conf) throws IOException { + LOG.info("Renaming " + sourcePath + " to " + destPath); + if (!inheritPerms) { + //just rename the directory + return fs.rename(sourcePath, destPath); + } else { + //rename the directory + if (fs.rename(sourcePath, destPath)) { + HadoopShims shims = ShimLoader.getHadoopShims(); + HdfsFileStatus fullFileStatus = shims.getFullFileStatus(conf, fs, destPath.getParent()); + try { + shims.setFullFileStatus(conf, fullFileStatus, fs, destPath); + } catch (Exception e) { + LOG.warn("Error setting permissions or group of " + destPath, e); + } + + return true; + } + + return false; + } + } } diff --git itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/FolderPermissionBase.java itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/FolderPermissionBase.java index 57fe4cf..154cec5 100644 --- itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/FolderPermissionBase.java +++ itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/FolderPermissionBase.java @@ -185,17 +185,20 @@ public void testAlterPartition() throws Exception { ret = driver.run("insert into table " + tableName + " partition(part1='1',part2='1',part3='1') select key,value from mysrc"); Assert.assertEquals(0,ret.getResponseCode()); + assertExistence(warehouseDir + "/" + tableName); + setPermission(warehouseDir + "/" + tableName, 1); + //alter partition ret = driver.run("alter table " + tableName + " partition (part1='1',part2='1',part3='1') rename to partition (part1='2',part2='2',part3='2')"); Assert.assertEquals(0,ret.getResponseCode()); - verifyPermission(warehouseDir + "/" + tableName + "/part1=2"); - verifyPermission(warehouseDir + "/" + tableName + "/part1=2/part2=2"); - verifyPermission(warehouseDir + "/" + tableName + "/part1=2/part2=2/part3=2"); + verifyPermission(warehouseDir + "/" + tableName + "/part1=2", 1); + verifyPermission(warehouseDir + "/" + tableName + "/part1=2/part2=2", 1); + verifyPermission(warehouseDir + "/" + tableName + "/part1=2/part2=2/part3=2", 1); Assert.assertTrue(listStatus(warehouseDir + "/" + tableName + "/part1=2/part2=2/part3=2").size() > 0); for (String child : listStatus(warehouseDir + "/" + tableName + "/part1=2/part2=2/part3=2")) { - verifyPermission(child); + verifyPermission(child, 1); } } diff --git metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java index 221b010..3126880 100644 --- metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java +++ metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java @@ -398,7 +398,7 @@ public Partition alterPartition(final RawStore msdb, Warehouse wh, final String if (!wh.mkdirs(destParentPath, true)) { throw new IOException("Unable to create path " + destParentPath); } - srcFs.rename(srcPath, destPath); + wh.renameDir(srcPath, destPath, true); LOG.info("rename done!"); } } catch (IOException e) { diff --git metastore/src/java/org/apache/hadoop/hive/metastore/Warehouse.java metastore/src/java/org/apache/hadoop/hive/metastore/Warehouse.java index c1790b4..a665995 100755 --- metastore/src/java/org/apache/hadoop/hive/metastore/Warehouse.java +++ metastore/src/java/org/apache/hadoop/hive/metastore/Warehouse.java @@ -44,7 +44,6 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.permission.FsAction; -import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.hive.common.FileUtils; import org.apache.hadoop.hive.common.HiveStatsUtils; import org.apache.hadoop.hive.common.JavaUtils; @@ -52,8 +51,6 @@ import org.apache.hadoop.hive.metastore.api.Database; import org.apache.hadoop.hive.metastore.api.FieldSchema; import org.apache.hadoop.hive.metastore.api.MetaException; -import org.apache.hadoop.hive.metastore.api.Partition; -import org.apache.hadoop.hive.metastore.api.SkewedInfo; import org.apache.hadoop.hive.metastore.api.StorageDescriptor; import org.apache.hadoop.hive.metastore.api.Table; import org.apache.hadoop.hive.shims.ShimLoader; @@ -198,10 +195,14 @@ public boolean mkdirs(Path f, boolean inheritPermCandidate) throws MetaException } public boolean renameDir(Path sourcePath, Path destPath) throws MetaException { + return renameDir(sourcePath, destPath, false); + } + + public boolean renameDir(Path sourcePath, Path destPath, boolean inheritPerms) throws MetaException { FileSystem fs = null; try { fs = getFs(sourcePath); - fs.rename(sourcePath, destPath); + FileUtils.rename(fs, sourcePath, destPath, inheritPerms, conf); return true; } catch (Exception ex) { MetaStoreUtils.logAndThrowMetaException(ex);