示例#1
0
 public override Stream Create(FilePath file, bool openAsReadWrite = false, bool createParents = true)
 {
     if (file.RawPathSegments.Length < 2)
     {
         throw new InvalidOperationException("The root and mount point levels " +
             "may not have files or directories created within them.");
     }
     FilePath sub;
     FileSystem fs = TransformPathToMountedPath(file, out sub);
     return fs.Create(sub, openAsReadWrite, createParents);
 }
示例#2
0
        public override Stream Create(FilePath file, bool openAsReadWrite = false, bool createParents = true)
        {
            String rawPath = PathToStringPath(file);
            if (File.Exists(rawPath)) throw new IOException(String.Format("File '{0}' already exists.", file));

            String parentPath = Path.GetDirectoryName(rawPath);
            if (createParents == true && Directory.Exists(parentPath) == false)
            {
                Directory.CreateDirectory(parentPath);
            }

            if (openAsReadWrite)
            {
                return File.Open(PathToRealPath(file), FileMode.Create, FileAccess.Write);
            }
            else
            {
                return File.Open(PathToRealPath(file), FileMode.Create, FileAccess.ReadWrite);
            }
        }
示例#3
0
 /// <summary>
 /// Creates the listed file and returns a handle to a stream.
 /// </summary>
 /// <remarks>
 /// This method is largely superfluous and provided mostly for completeness.
 /// Its only distinguishing feature over just Open()'ing a file that does not
 /// yet exist is that it will, if createParents is true, also create parent
 /// directories. Will throw an exception if the file already exists.
 /// </remarks>
 /// <param name="file">The file to open as a stream.</param>
 /// <param name="openAsReadWrite">
 /// If true, opens using FileAccessMode.ReadWrite rather than 
 /// FileAccessMode.Write.
 /// </param>
 /// <param name="createParents">
 /// Creates any nonexistent parent directories to this path. If this is
 /// set to false, then a nonexistent parent directory will throw an
 /// exception. Failure to create any necessary parent directories will
 /// also throw an exception.
 /// </param>
 /// <returns>A Stream object corresponding to this file.</returns>
 public abstract Stream Create(FilePath file, Boolean openAsReadWrite = false, Boolean createParents = true);
示例#4
0
 /// <summary>
 /// Opens a file according to the FileAccessMode provided and creates
 /// a stream object for manipulating it.
 /// </summary>
 /// <remarks>
 /// Open() will create a file if it does not exist and the method is
 /// passed a writable FileAccessMode. If passed FileAccessMode.Read,
 /// however, a non-existent file will trigger an exception.
 /// </remarks>
 /// <param name="file">The file to open as a stream.</param>
 /// <param name="accessMode">
 /// The access mode with which to open this file.
 /// </param>
 /// <returns>A stream corresponding to this file.</returns>
 public abstract Stream Open(FilePath file, FileAccessMode accessMode);
示例#5
0
 /// <summary>
 /// Determines whether or not a path exists within the file system.
 /// </summary>
 /// <param name="path">The path to check.</param>
 /// <returns>True if the path exists; false otherwise.</returns>
 public abstract Boolean Exists(FilePath path);
示例#6
0
 private FilePath TranslatePathFromBaseSystem(FilePath path)
 {
     Int32 length = path.RawPathSegments.Length - BaseFileSystemPath.RawPathSegments.Length;
     String[] newSegments = new String[length];
     Array.Copy(path.RawPathSegments, BaseFileSystemPath.RawPathSegments.Length, newSegments, 0, length);
     return new FilePath(newSegments);
 }
示例#7
0
        public override bool Exists(FilePath path)
        {
            if (path.RawPathSegments.Length == 0) return false;

            return File.Exists(PathToRealPath(path));
        }
示例#8
0
 public override void Delete(FilePath path)
 {
     throw new UnauthorizedAccessException("Cannot modify files or directories through a ReadOnlyFileSystem.");
 }
示例#9
0
 public override Stream Open(FilePath file, FileAccessMode accessMode)
 {
     if (file.RawPathSegments.Length < 2)
     {
         throw new InvalidOperationException("The root and mount points cannot " +
             "be opened.");
     }
     FilePath sub;
     FileSystem fs = TransformPathToMountedPath(file, out sub);
     return fs.Open(sub, accessMode);
 }
示例#10
0
        public override bool Exists(FilePath path)
        {
            if (path.RawPathSegments.Length < 2)
            {
                return false; // no files at the root level
            }

            if (Mounts.ContainsKey(path.RawPathSegments[0]) == false) return false;

            FilePath sub;
            FileSystem fs = TransformPathToMountedPath(path, out sub);
            return fs.Exists(sub);
        }
示例#11
0
 public override bool Exists(FilePath path)
 {
     return this.BaseFileSystem.Exists(TranslatePathToBaseSystem(path));
 }
示例#12
0
 public override void Delete(FilePath path)
 {
     this.BaseFileSystem.Delete(TranslatePathToBaseSystem(path));
 }
示例#13
0
 public override Stream Create(FilePath file, bool openAsReadWrite = false, bool createParents = true)
 {
     return this.BaseFileSystem.Create(TranslatePathToBaseSystem(file), openAsReadWrite, createParents);
 }
示例#14
0
 private FilePath TranslatePathToBaseSystem(FilePath path)
 {
     return this.BaseFileSystemPath.AppendFile(path.RawPathSegments);
 }
示例#15
0
        public override Stream Open(FilePath file, FileAccessMode accessMode)
        {
            if (accessMode == FileAccessMode.Read)
            {
                return this.BaseFileSystem.Open(file, accessMode);
            }

            throw new UnauthorizedAccessException("Cannot modify files or directories through a ReadOnlyFileSystem.");
        }
示例#16
0
 public override Stream Create(FilePath file, bool openAsReadWrite = false, bool createParents = true)
 {
     throw new UnauthorizedAccessException("Cannot modify files or directories through a ReadOnlyFileSystem.");
 }
示例#17
0
        protected FileSystem TransformPathToMountedPath(FilePath path, out FilePath newPath)
        {
            if (path.RawPathSegments.Length < 1)
            {
                throw new Exception("Input path too short for transform; missed a check somewhere!");
            }
            String key = path.RawPathSegments[0];

            FileSystem fs;
            if (Mounts.TryGetValue(key, out fs) == false)
            {
                throw new DirectoryNotFoundException("Mount point '" + key + "' not found.");
            }

            String[] newSegments = new String[path.RawPathSegments.Length - 1];
            Array.Copy(path.RawPathSegments, 1, newSegments, 0, newSegments.Length);

            newPath = new FilePath(newSegments);
            return fs;
        }
示例#18
0
 public override bool Exists(FilePath path)
 {
     return this.BaseFileSystem.Exists(path);
 }
示例#19
0
 public override void Delete(FilePath path)
 {
     if (path.RawPathSegments.Length < 2)
     {
         throw new InvalidOperationException("The root and mount points cannot " +
             "be deleted. Use Unmount() instead.");
     }
     FilePath sub;
     FileSystem fs = TransformPathToMountedPath(path, out sub);
     fs.Delete(sub);
 }
示例#20
0
 public override Stream Open(FilePath file, FileAccessMode accessMode)
 {
     switch (accessMode)
     {
         case FileAccessMode.Read:
             return File.Open(PathToRealPath(file), FileMode.Open, FileAccess.Read);
         case FileAccessMode.Write:
             return File.Open(PathToRealPath(file), FileMode.OpenOrCreate, FileAccess.Write);
         case FileAccessMode.ReadWrite:
             return File.Open(PathToRealPath(file), FileMode.OpenOrCreate, FileAccess.ReadWrite);
         default:
             throw new ArgumentException("Impossible value for accessMode.");
     }
 }
示例#21
0
 /// <summary>
 /// Deletes the given file.
 /// </summary>
 /// <remarks>
 /// If the file does not exist, this is a no-op. No exception will be thrown.
 /// </remarks>
 /// <param name="path">The path to delete.</param>
 public abstract void Delete(FilePath path);
示例#22
0
 public override void Delete(FilePath path)
 {
     File.Delete(PathToRealPath(path));
 }
示例#23
0
 public override Stream Open(FilePath file, FileAccessMode accessMode)
 {
     return this.BaseFileSystem.Open(TranslatePathToBaseSystem(file), accessMode);
 }