/// <exception cref="System.Exception"/> public virtual void CheckPathData(string dirString, PathData item) { Assert.Equal("checking fs", fs, item.fs); Assert.Equal("checking string", dirString, item.ToString()); Assert.Equal("checking path", fs.MakeQualified(new Path(item.ToString ())), item.path); Assert.True("checking exist", item.stat != null); Assert.True("checking isDir", item.stat.IsDirectory()); }
/// <exception cref="System.IO.IOException"/> protected internal override void ProcessPath(PathData item) { if (item.stat.IsDirectory()) { // TODO: handle this throw new PathIsDirectoryException(item.ToString()); } if (item.stat.GetLen() != 0) { throw new PathIOException(item.ToString(), "Not a zero-length file"); } Touchz(item); }
/// <exception cref="System.IO.IOException"/> protected internal override void ProcessNonexistentPath(PathData item) { // check if parent exists. this is complicated because getParent(a/b/c/) returns a/b/c, but // we want a/b if (!item.fs.Exists(new Path(item.path.ToString()).GetParent()) && !createParents) { throw new PathNotFoundException(item.ToString()); } if (!item.fs.Mkdirs(item.path)) { throw new PathIOException(item.ToString()); } }
/// <exception cref="System.IO.IOException"/> protected internal override void ProcessPath(PathData item) { if (item.stat.IsDirectory()) { if (!createParents) { throw new PathExistsException(item.ToString()); } } else { throw new PathIsNotDirectoryException(item.ToString()); } }
/// <exception cref="System.IO.IOException"/> protected internal override void ProcessPath(PathData item) { if (!item.stat.IsDirectory()) { throw new PathIsNotDirectoryException(item.ToString()); } }
/// <exception cref="System.IO.IOException"/> protected internal override void ProcessPath(PathData src, PathData target) { if (!src.fs.GetUri().Equals(target.fs.GetUri())) { throw new PathIOException(src.ToString(), "Does not match target filesystem"); } if (target.exists) { throw new PathExistsException(target.ToString()); } if (!target.fs.Rename(src.path, target.path)) { // we have no way to know the actual error... throw new PathIOException(src.ToString()); } }
/// <exception cref="System.IO.IOException"/> protected internal override void ProcessNonexistentPath(PathData item) { if (!item.ParentExists()) { throw new PathNotFoundException(item.ToString()); } Touchz(item); }
/// <exception cref="System.IO.IOException"/> protected internal override void ProcessPath(PathData src, PathData target) { // unlike copy, don't merge existing dirs during move if (target.exists && target.stat.IsDirectory()) { throw new PathExistsException(target.ToString()); } base.ProcessPath(src, target); }
/// <exception cref="System.IO.IOException"/> protected internal override void PostProcessPath(PathData src) { if (!src.fs.Delete(src.path, false)) { // we have no way to know the actual error... PathIOException e = new PathIOException(src.ToString()); e.SetOperation("remove"); throw e; } }
/// <exception cref="System.IO.IOException"/> protected internal override void ProcessPath(PathData item) { if (item.stat.IsDirectory() && !deleteDirs) { throw new PathIsDirectoryException(item.ToString()); } // TODO: if the user wants the trash to be used but there is any // problem (ie. creating the trash dir, moving the item to be deleted, // etc), then the path will just be deleted because moveToTrash returns // false and it falls thru to fs.delete. this doesn't seem right if (MoveToTrash(item)) { return; } if (!item.fs.Delete(item.path, deleteDirs)) { throw new PathIOException(item.ToString()); } @out.WriteLine("Deleted " + item); }
/// <exception cref="System.IO.IOException"/> internal virtual void Rename(PathData src, PathData target) { // the rename method with an option to delete the target is deprecated if (target.exists && !Delete(target.path, false)) { // too bad we don't know why it failed PathIOException e = new PathIOException(target.ToString()); e.SetOperation("delete"); throw e; } if (!Rename(src.path, target.path)) { // too bad we don't know why it failed PathIOException e = new PathIOException(src.ToString()); e.SetOperation("rename"); e.SetTargetPath(target.ToString()); throw e; } // cancel delete on exit if rename is successful CancelDeleteOnExit(src.path); }
/// <exception cref="System.IO.IOException"/> protected internal override void ProcessPath(PathData item) { if (!item.stat.IsDirectory()) { throw new PathIsNotDirectoryException(item.ToString()); } if (item.fs.ListStatus(item.path).Length == 0) { if (!item.fs.Delete(item.path, false)) { throw new PathIOException(item.ToString()); } } else { if (!ignoreNonEmpty) { throw new PathIsNotEmptyDirectoryException(item.ToString()); } } }
/// <exception cref="System.IO.IOException"/> protected internal override void RecursePath(PathData src) { PathData savedDst = dst; try { // modify dst as we descend to append the basename of the // current directory being processed dst = GetTargetPath(src); bool preserveRawXattrs = CheckPathsForReservedRaw(src.path, dst.path); if (dst.exists) { if (!dst.stat.IsDirectory()) { throw new PathIsNotDirectoryException(dst.ToString()); } } else { if (!dst.fs.Mkdirs(dst.path)) { // too bad we have no clue what failed PathIOException e = new PathIOException(dst.ToString()); e.SetOperation("mkdir"); throw e; } dst.RefreshStatus(); } // need to update stat to know it exists now base.RecursePath(src); if (dst.stat.IsDirectory()) { PreserveAttributes(src, dst, preserveRawXattrs); } } finally { dst = savedDst; } }
/// <exception cref="System.IO.IOException"/> protected internal override void ProcessPathArgument(PathData src) { 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; } } base.ProcessPathArgument(src); }
/// <summary>Called with a source and target destination pair</summary> /// <param name="src">for the operation</param> /// <param name="dst">for the operation</param> /// <exception cref="System.IO.IOException">if anything goes wrong</exception> protected internal virtual void ProcessPath(PathData src, PathData dst) { 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()); } } } }
/// <exception cref="System.IO.IOException"/> protected internal override void ProcessPath(PathData item) { if (item.stat.IsSymlink()) { throw new PathIOException(item.ToString(), "Symlinks unsupported"); } if (item.stat.IsFile()) { if (!item.fs.SetReplication(item.path, newRep)) { throw new IOException("Could not set replication for: " + item); } @out.WriteLine("Replication " + newRep + " set: " + item); if (waitOpt) { waitList.AddItem(item); } } }
/// <exception cref="System.IO.IOException"/> protected internal override void ProcessOptions(List <string> args) { try { CommandFormat cf = new CommandFormat(2, int.MaxValue, "nl"); cf.Parse(args); delimiter = cf.GetOpt("nl") ? "\n" : null; dst = new PathData(new URI(args.RemoveLast()), GetConf()); if (dst.exists && dst.stat.IsDirectory()) { throw new PathIsDirectoryException(dst.ToString()); } srcs = new List <PathData>(); } catch (URISyntaxException e) { throw new IOException("unexpected URISyntaxException", e); } }
/// <exception cref="System.IO.IOException"/> protected internal override void ProcessPath(PathData item) { if (item.stat.IsDirectory()) { throw new PathIsDirectoryException(item.ToString()); } long offset = DumpFromOffset(item, startingOffset); while (follow) { try { Thread.Sleep(followDelay); } catch (Exception) { break; } offset = DumpFromOffset(item, offset); } }
/// <summary>Copies the stream contents to a temporary file.</summary> /// <remarks> /// Copies the stream contents to a temporary file. If the copy is /// successful, the temporary file will be renamed to the real path, /// else the temporary file will be deleted. /// </remarks> /// <param name="in">the input stream for the copy</param> /// <param name="target">where to store the contents of the stream</param> /// <exception cref="System.IO.IOException">if copy fails</exception> protected internal virtual void CopyStreamToTarget(InputStream @in, PathData target ) { if (target.exists && (target.stat.IsDirectory() || !overwrite)) { throw new PathExistsException(target.ToString()); } CommandWithDestination.TargetFileSystem targetFs = new CommandWithDestination.TargetFileSystem (target.fs); try { PathData tempTarget = target.Suffix("._COPYING_"); targetFs.SetWriteChecksum(writeChecksum); targetFs.WriteStreamToFile(@in, tempTarget, lazyPersist); targetFs.Rename(tempTarget, target); } finally { targetFs.Close(); } }
/// <summary>Provides a hook for handling paths that don't exist.</summary> /// <remarks> /// Provides a hook for handling paths that don't exist. By default it /// will throw an exception. Primarily overriden by commands that create /// paths such as mkdir or touch. /// </remarks> /// <param name="item"> /// the /// <see cref="PathData"/> /// that doesn't exist /// </param> /// <exception cref="System.IO.FileNotFoundException">if arg is a path and it doesn't exist /// </exception> /// <exception cref="System.IO.IOException">if anything else goes wrong...</exception> protected internal virtual void ProcessNonexistentPath(PathData item) { throw new PathNotFoundException(item.ToString()); }