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); }
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); } }
/// <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);
/// <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);
/// <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);
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); }
public override bool Exists(FilePath path) { if (path.RawPathSegments.Length == 0) return false; return File.Exists(PathToRealPath(path)); }
public override void Delete(FilePath path) { throw new UnauthorizedAccessException("Cannot modify files or directories through a ReadOnlyFileSystem."); }
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); }
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); }
public override bool Exists(FilePath path) { return this.BaseFileSystem.Exists(TranslatePathToBaseSystem(path)); }
public override void Delete(FilePath path) { this.BaseFileSystem.Delete(TranslatePathToBaseSystem(path)); }
public override Stream Create(FilePath file, bool openAsReadWrite = false, bool createParents = true) { return this.BaseFileSystem.Create(TranslatePathToBaseSystem(file), openAsReadWrite, createParents); }
private FilePath TranslatePathToBaseSystem(FilePath path) { return this.BaseFileSystemPath.AppendFile(path.RawPathSegments); }
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."); }
public override Stream Create(FilePath file, bool openAsReadWrite = false, bool createParents = true) { throw new UnauthorizedAccessException("Cannot modify files or directories through a ReadOnlyFileSystem."); }
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; }
public override bool Exists(FilePath path) { return this.BaseFileSystem.Exists(path); }
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); }
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."); } }
/// <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);
public override void Delete(FilePath path) { File.Delete(PathToRealPath(path)); }
public override Stream Open(FilePath file, FileAccessMode accessMode) { return this.BaseFileSystem.Open(TranslatePathToBaseSystem(file), accessMode); }