private FakeFileStream CreateStream([NotNull] AbsolutePath path, FileAccess access, bool isReaderOnly, bool notifyTracker) { lock (readerWriterLock) { if (activeWriter != null) { throw ErrorFactory.System.FileIsInUse(path.GetText()); } if (!isReaderOnly && activeReaders.Any()) { throw ErrorFactory.System.FileIsInUse(path.GetText()); } var stream = new FakeFileStream(this, access, notifyTracker); if (isReaderOnly) { activeReaders.Add(stream); } else { activeWriter = stream; } return(stream); } }
public IDirectoryInfo CreateSubdirectory(string path) { // TODO: Review what kinds of path are allowed here. AbsolutePath subPath = AbsolutePath.Append(path); return(Owner.Directory.CreateDirectory(subPath.GetText())); }
public string GetFullPath(string path) { Guard.NotNull(path, nameof(path)); AbsolutePath absolutePath = owner.ToAbsolutePath(path); return(absolutePath.GetText()); }
public string GetTempFileName() { string tempDirectory = GetTempPath(); AbsolutePath absoluteTempDirectory = owner.ToAbsolutePath(tempDirectory); var handler = new PathGetTempFileNameHandler(container, owner.RandomNumberGenerator); var arguments = new PathGetTempFileNameArguments(absoluteTempDirectory); AbsolutePath tempFilePath = handler.Handle(arguments); return(tempFilePath.GetText()); }
public IDirectoryInfo CreateSubdirectory(string path) { Guard.NotNull(path, nameof(path)); AssertPathIsNotEmpty(path); AssertPathIsRelative(path); AbsolutePath completePath = path.Trim().Length == 0 ? AbsolutePath : RelativePathConverter.Combine(AbsolutePath, path); if (!PathStartsWith(completePath, AbsolutePath)) { throw ErrorFactory.System.DirectoryIsNotASubdirectory(path, AbsolutePath.GetText()); } return(Owner.Directory.CreateDirectory(completePath.GetText())); }
private void AssertIsSameComponent([NotNull] string thisComponent, [NotNull] string baseComponent, [NotNull] AbsolutePath basePath) { if (!string.Equals(thisComponent, baseComponent, StringComparison.OrdinalIgnoreCase)) { throw ErrorFactory.Internal.UnknownError($"Cannot rebase path '{GetText()}' to '{basePath.GetText()}'."); } }
private void AssertBasePathIsNotLongerThanSelf([NotNull] AbsolutePath basePath) { if (basePath.Components.Count > Components.Count) { throw ErrorFactory.Internal.UnknownError($"Cannot rebase path '{GetText()}' to '{basePath.GetText()}'."); } }