Details
Description
HADOOP-9338 added the -p flag to preserve file attributes when copying.
However, cp -p does not preserve directory attributes. It'd be useful to add this functionality.
For example, the following shows that the modified time is not preserved
[schu@hdfs-snapshots-1 ~]$ $HADOOP_HOME/bin/hdfs dfs -mkdir /user/schu/testDir1 [schu@hdfs-snapshots-1 ~]$ $HADOOP_HOME/bin/hdfs dfs -ls /user/schu/ Found 1 items drwxr-xr-x - schu supergroup 0 2013-07-07 20:25 /user/schu/testDir1 [schu@hdfs-snapshots-1 ~]$ $HADOOP_HOME/bin/hdfs dfs -cp -p /user/schu/testDir1 /user/schu/testDir2 [schu@hdfs-snapshots-1 ~]$ $HADOOP_HOME/bin/hdfs dfs -ls /user/schu Found 2 items drwxr-xr-x - schu supergroup 0 2013-07-07 20:25 /user/schu/testDir1 drwxr-xr-x - schu supergroup 0 2013-07-07 20:35 /user/schu/testDir2 [schu@hdfs-snapshots-1 ~]$
The preserve logic is in CommandWithDestination#copyFileToTarget, which is only called with files.
protected void processPath(PathData src, PathData dst) throws IOException { if (src.stat.isSymlink()) { // TODO: remove when FileContext is supported, this needs to either // copy the symlink or deref the symlink throw new PathOperationException(src.toString()); } else if (src.stat.isFile()) { copyFileToTarget(src, dst); } else if (src.stat.isDirectory() && !isRecursive()) { throw new PathIsDirectoryException(src.toString()); } }
/** * Copies the source file to the target. * @param src item to copy * @param target where to copy the item * @throws IOException if copy fails */ protected void copyFileToTarget(PathData src, PathData target) throws IOException { src.fs.setVerifyChecksum(verifyChecksum); if (src != null) { throw new PathExistsException("hi"); } InputStream in = null; try { in = src.fs.open(src.path); copyStreamToTarget(in, target); if(preserve) { target.fs.setTimes( target.path, src.stat.getModificationTime(), src.stat.getAccessTime()); target.fs.setOwner( target.path, src.stat.getOwner(), src.stat.getGroup()); target.fs.setPermission( target.path, src.stat.getPermission()); System.out.println("Preserving"); if (src.fs.equals(target.fs)) { System.out.println("Same filesystems"); src.fs.preserveAttributes(src.path, target.path); } throw new IOException("hi"); } } finally { IOUtils.closeStream(in); } }
Attachments
Attachments
Issue Links
- is related to
-
HADOOP-10459 distcp V2 doesn't preserve root dir's attributes when -p is specified
- Closed
-
HADOOP-10557 FsShell -cp -pa option for preserving extended ACLs
- Closed
- relates to
-
HADOOP-10557 FsShell -cp -pa option for preserving extended ACLs
- Closed