Example #1
0
        /// <summary>
        ///
        /// </summary>
        public void Table_Dispose()
        {
            lock (lock_fs)
            {
                if (_fsData != null)
                {
                    _fsData.Dispose();
                    _fsData = null;
                }

                if (_fsRollback != null)
                {
                    _fsRollback.Dispose();
                    _fsRollback = null;
                }

                if (_fsRollbackHelper != null)
                {
                    _fsRollbackHelper.Dispose();
                    _fsRollbackHelper = null;
                }

                _seqBuf.Dispose();
                _rollbackCache.Clear();
            }
        }
Example #2
0
        public void Dispose()
        {
            lock (lock_ibp_fs)
            {
                if (fs != null)
                {
                    FSR.NET_Flush(fs);


                    fs.Dispose();
                    fs = null;
                }
            }
        }
Example #3
0
        public override FileCopyResult Handle(FileCopyArguments arguments)
        {
            Guard.NotNull(arguments, nameof(arguments));

            FileEntry sourceFile = ResolveSourceFile(arguments.SourcePath);

            AssertHasExclusiveAccess(sourceFile);

            FileEntry destinationFile = ResolveDestinationFile(arguments.DestinationPath, arguments.Overwrite, sourceFile);

            IFileStream sourceStream      = null;
            IFileStream destinationStream = null;

            try
            {
                sourceStream      = sourceFile.Open(FileMode.Open, FileAccess.ReadWrite, arguments.SourcePath);
                destinationStream = destinationFile.Open(FileMode.Truncate, FileAccess.Write, arguments.DestinationPath);

                return(new FileCopyResult(sourceFile, sourceStream.AsStream(), destinationFile, destinationStream.AsStream()));
            }
            catch (Exception)
            {
                destinationStream?.Dispose();
                sourceStream?.Dispose();

                throw;
            }
        }
Example #4
0
        /// <summary>
        /// Closes the file.
        /// </summary>
        public void close()
        {
            stream.Dispose();

            if (file_exists)
            {
                var changed = true;

                try {
                    using (var old_file = MemoryMappedFile.OpenExisting(filename))
                        using (var new_file = MemoryMappedFile.OpenExisting(temp_filename)) {
                            var len = old_file.CreateViewStream().Length;
                            var st1 = old_file.CreateViewStream();
                            var st2 = new_file.CreateViewStream();
                            if (len == st2.Length)
                            {
                                byte[] data1 = new byte[len];
                                byte[] data2 = new byte[len];
                                st1.Read(data1, 0, (int)len);
                                st2.Read(data1, 0, (int)len);

                                if (data1 == data2)
                                {
                                    changed = false;
                                }
                            }
                        }
                } catch (Exception) {
                    // assume changed if mmap comparison doesn't work
                }

                if (changed)
                {
                    if (File.Exists(filename))
                    {
                        File.Delete(filename);
                    }
                    File.Move(temp_filename, filename);
                }
                else
                {
                    File.Delete(temp_filename);
                    if (source_filename != null)
                    {
                        var atime = File.GetLastAccessTime(source_filename);
                        var mtime = File.GetLastWriteTime(source_filename);

                        var t_atime = File.GetLastAccessTime(filename);
                        var t_mtime = File.GetLastWriteTime(filename);

                        if (mtime >= t_mtime)
                        {
                            File.SetLastAccessTime(filename, atime.AddSeconds(1));
                            File.SetLastWriteTime(filename, mtime.AddSeconds(1));
                        }
                    }
                }
            }
        }
Example #5
0
        /// <summary>
        /// Dispose
        /// </summary>
        public void Dispose()
        {
            lock (lock_fs)
            {
                if (_fsData != null)
                {
                    _fsData.Dispose();
                    _fsData = null;
                }

                if (_fsRollback != null)
                {
                    _fsRollback.Dispose();
                    _fsRollback = null;
                }

                if (_fsRollbackHelper != null)
                {
                    _fsRollbackHelper.Dispose();
                    _fsRollbackHelper = null;
                }
            }
        }
Example #6
0
        private void When_writing_to_closed_stream_it_must_fail()
        {
            // Arrange
            const string path = @"C:\file.txt";

            IFileSystem fileSystem = new FakeFileSystemBuilder()
                                     .IncludingEmptyFile(path)
                                     .Build();

            using (IFileStream stream = fileSystem.File.Open(path, FileMode.Open, FileAccess.ReadWrite))
            {
                stream.Dispose();

                // Act
                // ReSharper disable once AccessToDisposedClosure
                Action action = () => stream.Write(new byte[] { 0xFF }, 0, 1);

                // Assert
                action.ShouldThrow <ObjectDisposedException>().WithMessage("Cannot access a closed file.");
            }
        }
        public override FileCopyResult Handle(FileCopyArguments arguments)
        {
            Guard.NotNull(arguments, nameof(arguments));

            pendingContentChanges.Clear();
            pendingContentChanges.Add(FileAccessKinds.Write);

            FileEntry sourceFile = ResolveSourceFile(arguments.SourcePath, arguments.IsCopyAfterMoveFailed);

            FileResolveResult destinationResolveResult            = ResolveDestinationFile(arguments);
            DateTime?         existingDestinationLastWriteTimeUtc = destinationResolveResult.ExistingFileOrNull?.LastWriteTimeUtc;
            FileEntry         destinationFile = PrepareDestinationFile(destinationResolveResult, sourceFile, arguments);

            foreach (FileAccessKinds change in pendingContentChanges)
            {
                Container.ChangeTracker.NotifyContentsAccessed(destinationFile.PathFormatter, change);
            }

            IFileStream sourceStream      = null;
            IFileStream destinationStream = null;

            try
            {
                sourceStream      = sourceFile.Open(FileMode.Open, FileAccess.ReadWrite, arguments.SourcePath, false, false, false);
                destinationStream = destinationFile.Open(FileMode.Open, FileAccess.Write, arguments.DestinationPath, false, false,
                                                         false);

                return(new FileCopyResult(sourceFile, sourceStream.AsStream(), destinationFile, destinationStream.AsStream(),
                                          existingDestinationLastWriteTimeUtc));
            }
            catch (Exception)
            {
                destinationStream?.Dispose();
                sourceStream?.Dispose();

                throw;
            }
        }
Example #8
0
 public void Dispose()
 {
     _stream?.Dispose();
     _stream = null;
 }