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);
            }
        }
Beispiel #2
0
        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()));
        }
Beispiel #3
0
        public string GetFullPath(string path)
        {
            Guard.NotNull(path, nameof(path));

            AbsolutePath absolutePath = owner.ToAbsolutePath(path);

            return(absolutePath.GetText());
        }
Beispiel #4
0
        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());
        }
Beispiel #5
0
        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()));
        }
Beispiel #6
0
 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()}'.");
     }
 }
Beispiel #7
0
 private void AssertBasePathIsNotLongerThanSelf([NotNull] AbsolutePath basePath)
 {
     if (basePath.Components.Count > Components.Count)
     {
         throw ErrorFactory.Internal.UnknownError($"Cannot rebase path '{GetText()}' to '{basePath.GetText()}'.");
     }
 }