Author: cnauroth
Date: Thu Jun 26 05:40:26 2014
New Revision: 1605673
URL: http://svn.apache.org/r1605673
Log:
HADOOP-9705. Merging change r1605672 from trunk to branch-2.
Modified:
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestCopyPreserveFlag.java
Modified:
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt
URL:
http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt?rev=1605673&r1=1605672&r2=1605673&view=diff
==============================================================================
---
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt
(original)
+++
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt
Thu Jun 26 05:40:26 2014
@@ -260,6 +260,9 @@ Release 2.5.0 - UNRELEASED
HADOOP-10746. TestSocketIOWithTimeout#testSocketIOWithTimeout fails on
Power PC. (Jinghui Wang via Arpit Agarwal)
+ HADOOP-9705. FsShell cp -p does not preserve directory attibutes.
+ (Akira AJISAKA via cnauroth)
+
BREAKDOWN OF HADOOP-10514 SUBTASKS AND RELATED JIRAS
HADOOP-10520. Extended attributes definition and FileSystem APIs for
Modified:
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java
URL:
http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java?rev=1605673&r1=1605672&r2=1605673&view=diff
==============================================================================
---
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java
(original)
+++
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java
Thu Jun 26 05:40:26 2014
@@ -267,6 +267,9 @@ abstract class CommandWithDestination ex
dst.refreshStatus(); // need to update stat to know it exists now
}
super.recursePath(src);
+ if (dst.stat.isDirectory()) {
+ preserveAttributes(src, dst);
+ }
} finally {
dst = savedDst;
}
@@ -298,44 +301,7 @@ abstract class CommandWithDestination ex
try {
in = src.fs.open(src.path);
copyStreamToTarget(in, target);
- if (shouldPreserve(FileAttribute.TIMESTAMPS)) {
- target.fs.setTimes(
- target.path,
- src.stat.getModificationTime(),
- src.stat.getAccessTime());
- }
- if (shouldPreserve(FileAttribute.OWNERSHIP)) {
- target.fs.setOwner(
- target.path,
- src.stat.getOwner(),
- src.stat.getGroup());
- }
- if (shouldPreserve(FileAttribute.PERMISSION) ||
- shouldPreserve(FileAttribute.ACL)) {
- target.fs.setPermission(
- target.path,
- src.stat.getPermission());
- }
- if (shouldPreserve(FileAttribute.ACL)) {
- FsPermission perm = src.stat.getPermission();
- if (perm.getAclBit()) {
- List<AclEntry> srcEntries =
- src.fs.getAclStatus(src.path).getEntries();
- List<AclEntry> srcFullEntries =
- AclUtil.getAclFromPermAndEntries(perm, srcEntries);
- target.fs.setAcl(target.path, srcFullEntries);
- }
- }
- if (shouldPreserve(FileAttribute.XATTR)) {
- Map<String, byte[]> srcXAttrs = src.fs.getXAttrs(src.path);
- if (srcXAttrs != null) {
- Iterator<Entry<String, byte[]>> iter =
srcXAttrs.entrySet().iterator();
- while (iter.hasNext()) {
- Entry<String, byte[]> entry = iter.next();
- target.fs.setXAttr(target.path, entry.getKey(), entry.getValue());
- }
- }
- }
+ preserveAttributes(src, target);
} finally {
IOUtils.closeStream(in);
}
@@ -365,6 +331,56 @@ abstract class CommandWithDestination ex
}
}
+ /**
+ * Preserve the attributes of the source to the target.
+ * The method calls {@link #shouldPreserve(FileAttribute)} to check what
+ * attribute to preserve.
+ * @param src source to preserve
+ * @param target where to preserve attributes
+ * @throws IOException if fails to preserve attributes
+ */
+ protected void preserveAttributes(PathData src, PathData target)
+ throws IOException {
+ if (shouldPreserve(FileAttribute.TIMESTAMPS)) {
+ target.fs.setTimes(
+ target.path,
+ src.stat.getModificationTime(),
+ src.stat.getAccessTime());
+ }
+ if (shouldPreserve(FileAttribute.OWNERSHIP)) {
+ target.fs.setOwner(
+ target.path,
+ src.stat.getOwner(),
+ src.stat.getGroup());
+ }
+ if (shouldPreserve(FileAttribute.PERMISSION) ||
+ shouldPreserve(FileAttribute.ACL)) {
+ target.fs.setPermission(
+ target.path,
+ src.stat.getPermission());
+ }
+ if (shouldPreserve(FileAttribute.ACL)) {
+ FsPermission perm = src.stat.getPermission();
+ if (perm.getAclBit()) {
+ List<AclEntry> srcEntries =
+ src.fs.getAclStatus(src.path).getEntries();
+ List<AclEntry> srcFullEntries =
+ AclUtil.getAclFromPermAndEntries(perm, srcEntries);
+ target.fs.setAcl(target.path, srcFullEntries);
+ }
+ }
+ if (shouldPreserve(FileAttribute.XATTR)) {
+ Map<String, byte[]> srcXAttrs = src.fs.getXAttrs(src.path);
+ if (srcXAttrs != null) {
+ Iterator<Entry<String, byte[]>> iter = srcXAttrs.entrySet().iterator();
+ while (iter.hasNext()) {
+ Entry<String, byte[]> entry = iter.next();
+ target.fs.setXAttr(target.path, entry.getKey(), entry.getValue());
+ }
+ }
+ }
+ }
+
// Helper filter filesystem that registers created files as temp files to
// be deleted on exit unless successfully renamed
private static class TargetFileSystem extends FilterFileSystem {
Modified:
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestCopyPreserveFlag.java
URL:
http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestCopyPreserveFlag.java?rev=1605673&r1=1605672&r2=1605673&view=diff
==============================================================================
---
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestCopyPreserveFlag.java
(original)
+++
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestCopyPreserveFlag.java
Thu Jun 26 05:40:26 2014
@@ -74,6 +74,8 @@ public class TestCopyPreserveFlag {
output.close();
fs.setTimes(FROM, MODIFICATION_TIME, 0);
fs.setPermission(FROM, PERMISSIONS);
+ fs.setTimes(new Path("d1"), MODIFICATION_TIME, 0);
+ fs.setPermission(new Path("d1"), PERMISSIONS);
}
@After
@@ -132,4 +134,22 @@ public class TestCopyPreserveFlag {
run(new Cp(), FROM.toString(), TO.toString());
assertAttributesChanged();
}
+
+ @Test(timeout = 10000)
+ public void testDirectoryCpWithP() throws Exception {
+ run(new Cp(), "-p", "d1", "d3");
+ assertEquals(fs.getFileStatus(new Path("d1")).getModificationTime(),
+ fs.getFileStatus(new Path("d3")).getModificationTime());
+ assertEquals(fs.getFileStatus(new Path("d1")).getPermission(),
+ fs.getFileStatus(new Path("d3")).getPermission());
+ }
+
+ @Test(timeout = 10000)
+ public void testDirectoryCpWithoutP() throws Exception {
+ run(new Cp(), "d1", "d4");
+ assertTrue(fs.getFileStatus(new Path("d1")).getModificationTime() !=
+ fs.getFileStatus(new Path("d4")).getModificationTime());
+ assertTrue(!fs.getFileStatus(new Path("d1")).getPermission()
+ .equals(fs.getFileStatus(new Path("d4")).getPermission()));
+ }
}