/** * 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 { final boolean preserveRawXattrs = checkPathsForReservedRaw(src.path, target.path); src.fs.setVerifyChecksum(verifyChecksum); InputStream in = null; try { in = src.fs.open(src.path); copyStreamToTarget(in, target); preserveAttributes(src, target, preserveRawXattrs); } finally { IOUtils.closeStream(in); } }
/** * Called with a source and target destination pair * @param src for the operation * @param dst for the operation * @throws IOException if anything goes wrong */ 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()); } }
/** * The last arg is expected to be a local path, if only one argument is * given then the destination will be the current directory * @param args is the list of arguments */ protected void getLocalDestination(LinkedList<String> args) throws IOException { String pathString = (args.size() < 2) ? Path.CUR_DIR : args.removeLast(); try { dst = new PathData(new URI(pathString), getConf()); } catch (URISyntaxException e) { if (Path.WINDOWS) { // Unlike URI, PathData knows how to parse Windows drive-letter paths. dst = new PathData(pathString, getConf()); } else { throw new IOException("unexpected URISyntaxException", e); } } }
@Override protected void processPath(PathData src) throws IOException { processPath(src, getTargetPath(src)); }
dst = getTargetPath(src); final boolean preserveRawXattrs = checkPathsForReservedRaw(src.path, dst.path); if (dst.exists) { if (!dst.stat.isDirectory()) { preserveAttributes(src, dst, preserveRawXattrs);
@Override protected void processArguments(LinkedList<PathData> args) throws IOException { // NOTE: this logic should be better, mimics previous implementation if (args.size() == 1 && args.get(0).toString().equals("-")) { copyStreamToTarget(System.in, getTargetPath(args.get(0))); return; } super.processArguments(args); } }
protected PathData getTargetPath(PathData src) throws IOException { PathData target; // on the first loop, the dst may be directory or a file, so only create // a child path if dst is a dir; after recursion, it's always a dir if ((getDepth() > 0) || (dst.exists && dst.stat.isDirectory())) { target = dst.getPathDataForChild(src); } else if (dst.representsDirectory()) { // see if path looks like a dir target = dst.getPathDataForChild(src); } else { target = dst; } return target; }
/** * If true, the last modified time, last access time, * owner, group and permission information of the source * file will be preserved as far as target {@link FileSystem} * implementation allows. */ protected void setPreserve(boolean preserve) { if (preserve) { preserve(FileAttribute.TIMESTAMPS); preserve(FileAttribute.OWNERSHIP); preserve(FileAttribute.PERMISSION); } else { preserveStatus.clear(); } }
@Override protected void processPathArgument(PathData src) throws IOException { if (src.stat.isDirectory() && src.fs.equals(dst.fs)) { PathData target = getTargetPath(src); String srcPath = src.fs.makeQualified(src.path).toString(); String dstPath = dst.fs.makeQualified(target.path).toString(); if (dstPath.equals(srcPath)) { PathIOException e = new PathIOException(src.toString(), "are identical"); e.setTargetPath(dstPath.toString()); throw e; } // When a path is normalized, all trailing slashes are removed // except for the root if(!srcPath.endsWith(Path.SEPARATOR)) { srcPath += Path.SEPARATOR; } if(dstPath.startsWith(srcPath)) { PathIOException e = new PathIOException(src.toString(), "is a subdirectory of itself"); e.setTargetPath(target.toString()); throw e; } } super.processPathArgument(src); }
dst = getTargetPath(src); final boolean preserveRawXattrs = checkPathsForReservedRaw(src.path, dst.path); if (dst.exists) { if (!dst.stat.isDirectory()) { preserveAttributes(src, dst, preserveRawXattrs);
@Override protected void processPath(PathData src) throws IOException { processPath(src, getTargetPath(src)); }
@Override protected void processArguments(LinkedList<PathData> args) throws IOException { // NOTE: this logic should be better, mimics previous implementation if (args.size() == 1 && args.get(0).toString().equals("-")) { copyStreamToTarget(System.in, getTargetPath(args.get(0))); return; } super.processArguments(args); } }
protected PathData getTargetPath(PathData src) throws IOException { PathData target; // on the first loop, the dst may be directory or a file, so only create // a child path if dst is a dir; after recursion, it's always a dir if ((getDepth() > 0) || (dst.exists && dst.stat.isDirectory())) { target = dst.getPathDataForChild(src); } else if (dst.representsDirectory()) { // see if path looks like a dir target = dst.getPathDataForChild(src); } else { target = dst; } return target; }
/** * If true, the last modified time, last access time, * owner, group and permission information of the source * file will be preserved as far as target {@link FileSystem} * implementation allows. */ protected void setPreserve(boolean preserve) { if (preserve) { preserve(FileAttribute.TIMESTAMPS); preserve(FileAttribute.OWNERSHIP); preserve(FileAttribute.PERMISSION); } else { preserveStatus.clear(); } }
@Override protected void processPathArgument(PathData src) throws IOException { if (src.stat.isDirectory() && src.fs.equals(dst.fs)) { PathData target = getTargetPath(src); String srcPath = src.fs.makeQualified(src.path).toString(); String dstPath = dst.fs.makeQualified(target.path).toString(); if (dstPath.equals(srcPath)) { PathIOException e = new PathIOException(src.toString(), "are identical"); e.setTargetPath(dstPath.toString()); throw e; } if (dstPath.startsWith(srcPath+Path.SEPARATOR)) { PathIOException e = new PathIOException(src.toString(), "is a subdirectory of itself"); e.setTargetPath(target.toString()); throw e; } } super.processPathArgument(src); }
/** * 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 { final boolean preserveRawXattrs = checkPathsForReservedRaw(src.path, target.path); src.fs.setVerifyChecksum(verifyChecksum); InputStream in = null; try { in = src.fs.open(src.path); copyStreamToTarget(in, target); preserveAttributes(src, target, preserveRawXattrs); } finally { IOUtils.closeStream(in); } }
dst = getTargetPath(src); final boolean preserveRawXattrs = checkPathsForReservedRaw(src.path, dst.path); if (dst.exists) { if (!dst.stat.isDirectory()) { preserveAttributes(src, dst, preserveRawXattrs);
@Override protected void processPath(PathData src) throws IOException { processPath(src, getTargetPath(src)); }
/** * Called with a source and target destination pair * @param src for the operation * @param dst for the operation * @throws IOException if anything goes wrong */ 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()); } }
/** * The last arg is expected to be a remote path, if only one argument is * given then the destination will be the remote user's directory * @param args is the list of arguments * @throws PathIOException if path doesn't exist or matches too many times */ protected void getRemoteDestination(LinkedList<String> args) throws IOException { if (args.size() < 2) { dst = new PathData(Path.CUR_DIR, getConf()); } else { String pathString = args.removeLast(); // if the path is a glob, then it must match one and only one path PathData[] items = PathData.expandAsGlob(pathString, getConf()); switch (items.length) { case 0: throw new PathNotFoundException(pathString); case 1: dst = items[0]; break; default: throw new PathIOException(pathString, "Too many matches"); } } }