protected override void Dispose(bool disposing) { if (disposing) { if (!isClosed) { isClosed = true; if (newLength != null && newLength.Value != owner.Size) { owner.Size = newLength.Value; accessKinds |= FileAccessKinds.Resize; } if (accessKinds != FileAccessKinds.None) { owner.HandleFileContentsAccessed(accessKinds, notifyTracker); } if (LazyHandle.IsValueCreated) { LazyHandle.Value.Dispose(); } owner.lockTracker.Release(this); owner.CloseStream(this); } } base.Dispose(disposing); }
public FileSetAttributesArguments([NotNull] AbsolutePath path, FileAttributes attributes, FileAccessKinds accessKinds = FileAccessKinds.Attributes) { Guard.NotNull(path, nameof(path)); Path = path; Attributes = attributes; AccessKinds = accessKinds; }
private void NotifyDirectoriesChanged(bool skipNotifyLastAccessOnLastDirectory, [NotNull][ItemNotNull] params DirectoryEntry[] directories) { List <DirectoryEntry> uniqueDirectories = directories.Distinct().ToList(); while (uniqueDirectories.Any()) { FileAccessKinds accessKinds = uniqueDirectories.Count == 1 && skipNotifyLastAccessOnLastDirectory ? FileAccessKinds.Write : FileAccessKinds.WriteRead; DirectoryEntry directory = uniqueDirectories.First(); Container.ChangeTracker.NotifyContentsAccessed(directory.PathFormatter, accessKinds); uniqueDirectories.Remove(directory); } }
private void HandleFileContentsAccessed(FileAccessKinds accessKinds, bool notifyTracker) { DateTime utcNow = Parent.SystemClock.UtcNow(); if (accessKinds != FileAccessKinds.None) { LastAccessTimeUtc = utcNow; } if (accessKinds.HasFlag(FileAccessKinds.Write) || accessKinds.HasFlag(FileAccessKinds.Resize)) { LastWriteTimeUtc = utcNow; } if (notifyTracker) { ChangeTracker.NotifyContentsAccessed(PathFormatter, accessKinds); } }
public override int Read(byte[] buffer, int offset, int count) { AssertNotClosed(); AssertIsReadable(); var segment = new ArraySegment <byte>(buffer, offset, count); if (segment.Count == 0 || Position >= Length) { return(0); } lock (owner.readerWriterLock) { UnsafeAssertRangeNotLocked(Position + offset, count); int sumBytesRead = 0; int blockIndex = (int)(Position / BlockSize); int offsetInCurrentBlock = (int)(Position % BlockSize); while (count > 0 && Position < Length) { int bytesToRead = Math.Min(BlockSize - offsetInCurrentBlock, count); bytesToRead = Math.Min(bytesToRead, (int)(Length - Position)); Buffer.BlockCopy(owner.blocks[blockIndex], offsetInCurrentBlock, buffer, offset, bytesToRead); offset += bytesToRead; count -= bytesToRead; Position += bytesToRead; sumBytesRead += bytesToRead; blockIndex++; offsetInCurrentBlock = 0; } accessKinds |= FileAccessKinds.Read; return(sumBytesRead); } }
public override void Write(byte[] buffer, int offset, int count) { AssertNotClosed(); AssertIsWritable(); var segment = new ArraySegment <byte>(buffer, offset, count); if (segment.Count == 0) { return; } EnsureCapacity(Position + count); int blockIndex = (int)(Position / BlockSize); int bytesFreeInCurrentBlock = BlockSize - (int)(Position % BlockSize); while (count > 0) { int bytesToWrite = Math.Min(bytesFreeInCurrentBlock, count); int offsetInBlock = BlockSize - bytesFreeInCurrentBlock; Buffer.BlockCopy(buffer, offset, owner.blocks[blockIndex], offsetInBlock, bytesToWrite); offset += bytesToWrite; count -= bytesToWrite; Position += bytesToWrite; blockIndex++; bytesFreeInCurrentBlock = BlockSize; } if (Position > Length) { newLength = Position; } accessKinds |= FileAccessKinds.WriteRead; }
partial void ProcessContentsAccessed([NotNull] IPathFormatter formatter, FileAccessKinds accessKinds);
public void NotifyContentsAccessed([NotNull] IPathFormatter formatter, FileAccessKinds accessKinds) { ProcessContentsAccessed(formatter, accessKinds); }
public void EnableAccessKinds(FileAccessKinds kinds) { accessKinds |= kinds; }