示例#1
0
        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;
            });
        }
示例#2
0
        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;
            }
        }
示例#3
0
        /// <summary>
        /// Creates a linker.
        /// </summary>
        /// <param name="smallTables">Use small table definitions for MSI/MSM.</param>
        public Binder(bool smallTables)
        {
            this.tableDefinitions = Common.GetTableDefinitions(smallTables);

            this.extension = new BinderExtension();
            this.extensionMessages = new ExtensionMessages(this);
            this.fileCopyHandler = new FileCopyHandler(File.Copy);
            this.fileMoveHandler = new FileMoveHandler(File.Move);
        }