private void InnerCopy([NotNull] string sourceFileName, [NotNull] string destFileName, bool overwrite, bool isCopyAfterMoveFailed) { FileCopyResult copyResult = null; try { container.FileSystemLock.ExecuteInLock(() => { AbsolutePath sourcePath = owner.ToAbsolutePath(sourceFileName); AbsolutePath destinationPath = owner.ToAbsolutePath(destFileName); var handler = new FileCopyHandler(container); var arguments = new FileCopyArguments(sourcePath, destinationPath, overwrite, isCopyAfterMoveFailed); copyResult = handler.Handle(arguments); }); WaitOnIndicator(owner.CopyWaitIndicator); copyResult.SourceStream.CopyTo(copyResult.DestinationStream); } finally { copyResult?.DestinationStream.Dispose(); copyResult?.SourceStream.Dispose(); } container.FileSystemLock.ExecuteInLock(() => { copyResult.DestinationFile.LastWriteTimeUtc = copyResult.ExistingDestinationLastWriteTimeUtc ?? copyResult.SourceFile.LastWriteTimeUtc; }); }
public void Copy(string sourceFileName, string destFileName, bool overwrite = false) { Guard.NotNull(sourceFileName, nameof(sourceFileName)); Guard.NotNull(destFileName, nameof(destFileName)); AssertFileNameIsNotEmpty(sourceFileName); AssertFileNameIsNotEmpty(destFileName); FileEntry sourceFile; FileEntry destinationFile; Stream sourceStream = null; Stream destinationStream = null; try { lock (owner.TreeLock) { AbsolutePath sourcePath = owner.ToAbsolutePath(sourceFileName); AbsolutePath destinationPath = owner.ToAbsolutePath(destFileName); var handler = new FileCopyHandler(root); var arguments = new FileCopyArguments(sourcePath, destinationPath, overwrite); (sourceFile, sourceStream, destinationFile, destinationStream) = handler.Handle(arguments); } WaitOnIndicator(owner.CopyWaitIndicator); sourceStream.CopyTo(destinationStream); } finally { destinationStream?.Dispose(); sourceStream?.Dispose(); } lock (owner.TreeLock) { destinationFile.LastWriteTimeUtc = sourceFile.LastWriteTimeUtc; } }