internal override void Copy(AbstractFile destination) { Log.DebugFormat("Copy file {0} to {1}", Path, destination.Path); if (!(destination is AbstractRegularFile)) { throw new CopyTypeException("Destination type is not regular file."); } var destinationRegularFile = destination as AbstractRegularFile; if (destinationRegularFile.Exists) { destinationRegularFile.IsReadOnly = false; destinationRegularFile.Truncate(); } else { destinationRegularFile.Create(); } using (var sourceStream = OpenRead()) { using (var destinationStream = destinationRegularFile.OpenWrite()) { sourceStream.CopyTo(destinationStream); } } destinationRegularFile.SetAllAttributes(this); }
internal virtual void Copy(AbstractFile destination, bool ignoreErrors) { Log.DebugFormat("Copy directory {0} to {1}", Path, destination.Path); if (!(destination is AbstractDirectory)) { throw new CopyTypeException("Destination type is not directory."); } var destinationDirectory = destination as AbstractDirectory; if (!destination.Exists) { destination.Create(); } foreach (var directory in GetDirectories()) { try { var targetDirectory = destinationDirectory.GetSubDirectory(directory.Name); directory.Copy(targetDirectory); } catch (AccessDeniedException e) { Log.Warn(e.Message); if (!ignoreErrors) { throw e; } } } foreach (var file in GetRegularFiles()) { try { var targetFile = destinationDirectory.GetFile(file.Name); file.Copy(targetFile); } catch (AccessDeniedException e) { Log.Warn(e.Message); if (!ignoreErrors) { throw e; } } } destinationDirectory.SetAllAttributes(this); }
internal override void Copy(AbstractFile destination) { Copy(destination, true); }