Ejemplo n.º 1
0
 public override void Create(DirectoryPath directory)
 {
     if (directory.RawPathSegments.Length < 2)
     {
         throw new InvalidOperationException("The root and mount point levels " +
             "may not have files or directories created within them.");
     }
     DirectoryPath sub;
     FileSystem fs = TransformPathToMountedPath(directory, out sub);
     fs.Create(sub);
 }
Ejemplo n.º 2
0
 public override void Delete(DirectoryPath path, bool deleteChildPaths = false)
 {
     if (path.RawPathSegments.Length < 2)
     {
         throw new InvalidOperationException("The root and mount points cannot " +
             "be deleted. Use Unmount() instead.");
     }
     DirectoryPath sub;
     FileSystem fs = TransformPathToMountedPath(path, out sub);
     fs.Delete(sub, deleteChildPaths);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="baseFileSystem">The file system to which this is an adjunct.</param>
        /// <param name="baseFileSystemPath">The file system path </param>
        public SubtreeFileSystem(FileSystem baseFileSystem, DirectoryPath baseFileSystemPath)
        {
            if (baseFileSystem.Exists(baseFileSystemPath) == false)
            {
                throw new IOException(String.Format("Cannot instantiate a SubtreeFileSystem upon a " +
                    "path that doesn't exist on its parent: '{0}'", baseFileSystemPath));
            }

            BaseFileSystem = baseFileSystem;
            BaseFileSystemPath = baseFileSystemPath;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets all paths that are direct children of this directory, filtered
        /// by the given string as a regular expression.
        /// </summary>
        /// <param name="directory">The directory in which to search.</param>
        /// <param name="regex">The regex to filter by.</param>
        /// <returns>
        /// A collection of all child paths that match the given regex.
        /// </returns>
        public ReadOnlyCollection<AbstractPath> GetChildPaths(DirectoryPath directory, String regex)
        {
            if (regex[0] != '^')
            {
                regex = "^" + regex;
            }

            if (regex[regex.Length - 1] != '$')
            {
                regex = regex + "$";
            }

            return this.GetChildPaths(directory, new Regex(regex));
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Gets all direct child paths of this directory.
 /// </summary>
 /// <param name="directory">The directory in which to search.</param>
 /// <returns>A collection of all children.</returns>
 public ReadOnlyCollection<AbstractPath> GetChildPaths(DirectoryPath directory)
 {
     return this.GetChildPaths(directory, FileSystem.AnyRegex);
 }
Ejemplo n.º 6
0
 public override ReadOnlyCollection<AbstractPath> GetChildPaths(DirectoryPath directory, Regex regex)
 {
     var entries = this.BaseFileSystem.GetChildPaths(TranslatePathToBaseSystem(directory), regex);
     List<AbstractPath> translatedList = new List<AbstractPath>(entries.Count);
     foreach (AbstractPath e in entries)
     {
         translatedList.Add(TranslatePathFromBaseSystem(e));
     }
     return new ReadOnlyCollection<AbstractPath>(translatedList);
 }
Ejemplo n.º 7
0
 public override void Create(DirectoryPath directory)
 {
     Directory.CreateDirectory(PathToRealPath(directory));
 }
Ejemplo n.º 8
0
        public override ReadOnlyCollection<FilePath> GetChildFiles(DirectoryPath directory, Regex regex)
        {
            String rawPath = PathToStringPath(directory);

            String[] entries = Directory.GetFiles(rawPath);
            List<FilePath> output = new List<FilePath>(entries.Length);
            foreach (String e in entries)
            {
                String filename = Path.GetFileName(e);

                if (regex.IsMatch(filename))
                {
                    output.Add(directory.AppendFile(filename));
                }
            }

            return new ReadOnlyCollection<FilePath>(output);
        }
Ejemplo n.º 9
0
 private DirectoryPath TranslatePathToBaseSystem(DirectoryPath path)
 {
     return this.BaseFileSystemPath.AppendDirectory(path.RawPathSegments);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Deletes the given directory.
 /// </summary>
 /// <remarks>
 /// If the directory does not exist, this is a no-op. No exception will
 /// be thrown.
 /// </remarks>
 /// <param name="path">The path to delete.</param>
 /// <param name="deleteChildPaths">
 /// If true, deletes all child items in the path (the moral equivalent
 /// of "rm -rf"). If false, will throw an exception if this has any children.
 /// </param>
 public abstract void Delete(DirectoryPath path, Boolean deleteChildPaths = false);
Ejemplo n.º 11
0
        protected FileSystem TransformPathToMountedPath(DirectoryPath path, out DirectoryPath 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 = null;
            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 DirectoryPath(newSegments);
            System.Diagnostics.Debug.Print(path.ToString());
            System.Diagnostics.Debug.Print(newPath.ToString());
            return fs;
        }
Ejemplo n.º 12
0
        public override ReadOnlyCollection<AbstractPath> GetChildPaths(DirectoryPath directory, Regex regex)
        {
            if (directory.RawPathSegments.Length == 0)
            {
                List<AbstractPath> a = new List<AbstractPath>(Mounts.Count);
                a.AddRange(MountPaths.Values);
                return new ReadOnlyCollection<AbstractPath>(a);
            }

            DirectoryPath sub;
            FileSystem fs = TransformPathToMountedPath(directory, out sub);
            ReadOnlyCollection<AbstractPath> paths = fs.GetChildPaths(sub, regex);
            List<AbstractPath> newPaths = new List<AbstractPath>(paths.Count);
            foreach (AbstractPath path in paths)
            {
                String[] newSegments = new String[path.RawPathSegments.Length + 1];
                newSegments[0] = directory.RawPathSegments[0];
                Array.Copy(path.RawPathSegments, 0, newSegments, 1, path.RawPathSegments.Length);

                if (path is DirectoryPath)
                    newPaths.Add(new DirectoryPath(newSegments));
                else
                    newPaths.Add(new FilePath(newSegments));
            }

            return new ReadOnlyCollection<AbstractPath>(newPaths);
        }
Ejemplo n.º 13
0
        public override ReadOnlyCollection<FilePath> GetChildFiles(DirectoryPath directory, Regex regex)
        {
            if (directory.RawPathSegments.Length == 0)
            {
                return _emptyFileCollection;
            }

            DirectoryPath sub;
            FileSystem fs = TransformPathToMountedPath(directory, out sub);
            ReadOnlyCollection<FilePath> paths = fs.GetChildFiles(sub, regex);
            List<FilePath> newPaths = new List<FilePath>(paths.Count);
            foreach (FilePath path in paths)
            {
                String[] newSegments = new String[path.RawPathSegments.Length + 1];
                newSegments[0] = directory.RawPathSegments[0];
                Array.Copy(path.RawPathSegments, 0, newSegments, 1, path.RawPathSegments.Length);
                newPaths.Add(new FilePath(newSegments));
            }

            return new ReadOnlyCollection<FilePath>(newPaths);
        }
Ejemplo n.º 14
0
        public override bool Exists(DirectoryPath path)
        {
            switch (path.RawPathSegments.Length)
            {
                case 0:
                    return true;
                case 1:
                    return Mounts.ContainsKey(path.RawPathSegments[0]);
                default:
                    if (Mounts.ContainsKey(path.RawPathSegments[0]) == false) return false;

                    DirectoryPath sub;
                    FileSystem fs = TransformPathToMountedPath(path, out sub);
                    return fs.Exists(sub);
            }
        }
Ejemplo n.º 15
0
 public override void Delete(DirectoryPath path, bool deleteChildPaths = false)
 {
     this.BaseFileSystem.Delete(TranslatePathToBaseSystem(path), deleteChildPaths);
 }
Ejemplo n.º 16
0
 public override void Create(DirectoryPath directory)
 {
     this.BaseFileSystem.Create(TranslatePathToBaseSystem(directory));
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Gets all paths that are direct children of this directory, filtered
 /// by the given regular expression.
 /// </summary>
 /// <remarks>
 /// The GetChildPaths(String) method internally falls back to this
 /// one, so if you're making the same check often it may prove worthwhile
 /// to save a regex object and call this variant instead. The variant
 /// of this method with no arguments, however, uses an internally stored
 /// regex of ".*" and so using this one instead won't really be faster.
 /// </remarks>
 /// <param name="directory">The directory in which to search.</param>
 /// <param name="regex">The regex to filter by.</param>
 /// <returns>
 /// A collection of all child paths that match the given regex.
 /// </returns>
 public abstract ReadOnlyCollection<AbstractPath> GetChildPaths(DirectoryPath directory, Regex regex);
Ejemplo n.º 18
0
 public override void Delete(DirectoryPath path, bool deleteChildPaths = false)
 {
     throw new UnauthorizedAccessException("Cannot modify files or directories through a ReadOnlyFileSystem.");
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Creates the given directory and all parent directories.
 /// </summary>
 /// <remarks>
 /// If the directory already exists, this is a no-op. No exception will
 /// be thrown.
 /// </remarks>
 /// <param name="directory">
 /// The directory to create.
 /// </param>
 public abstract void Create(DirectoryPath directory);
Ejemplo n.º 20
0
 public override ReadOnlyCollection<AbstractPath> GetChildPaths(DirectoryPath directory, Regex regex)
 {
     return this.BaseFileSystem.GetChildPaths(directory, regex);
 }
Ejemplo n.º 21
0
 public override void Create(DirectoryPath directory)
 {
     throw new UnauthorizedAccessException("Cannot modify files or directories through a ReadOnlyFileSystem.");
 }
Ejemplo n.º 22
0
 // there's probably a cleaner way to do this that's better for performance;
 // suggestions welcome!
 private DirectoryPath TranslatePathFromBaseSystem(DirectoryPath 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 DirectoryPath(newSegments);
 }
Ejemplo n.º 23
0
 public override bool Exists(DirectoryPath path)
 {
     return this.BaseFileSystem.Exists(path);
 }
Ejemplo n.º 24
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(DirectoryPath path);
Ejemplo n.º 25
0
        public override bool Exists(DirectoryPath path)
        {
            if (path.RawPathSegments.Length == 0) return true;

            return Directory.Exists(PathToRealPath(path));
        }
Ejemplo n.º 26
0
 /// <summary>
 /// Gets all files that are direct children of this directory.
 /// </summary>
 /// <param name="directory">The directory in which to search.</param>
 /// <returns>A collection of all child files.</returns>
 public ReadOnlyCollection<FilePath> GetChildFiles(DirectoryPath directory)
 {
     return this.GetChildFiles(directory, FileSystem.AnyRegex);
 }
Ejemplo n.º 27
0
        public override ReadOnlyCollection<AbstractPath> GetChildPaths(DirectoryPath directory, Regex regex)
        {
            String rawPath = PathToStringPath(directory);

            String[] entries = Directory.GetFiles(rawPath);
            List<AbstractPath> output = new List<AbstractPath>(entries.Length);
            foreach (String e in entries)
            {
                String filename = Path.GetFileName(e);

                if (regex.IsMatch(filename))
                {
                    if (File.Exists(e))
                    {
                        output.Add(directory.AppendFile(filename));
                    }
                    else if (Directory.Exists(e))
                    {
                        output.Add(directory.AppendDirectory(filename));
                    }
                    else
                    {
                        throw new IOException("Invalid state: file system entry neither File nor Directory?s");
                    }
                }
            }

            return new ReadOnlyCollection<AbstractPath>(output);
        }
Ejemplo n.º 28
0
 /// <summary>
 /// Gets all files that are direct children of this directory, filtered
 /// by the given regular expression.
 /// </summary>
 /// <remarks>
 /// The GetChildFiles(String) method internally falls back to this
 /// one, so if you're making the same check often it may prove worthwhile
 /// to save a regex object and call this variant instead. The variant
 /// of this method with no arguments, however, uses an internally stored
 /// regex of ".*" and so using this one instead won't really be faster.
 /// </remarks>
 /// <param name="directory">The directory in which to search.</param>
 /// <param name="regex">The regex to filter by.</param>
 /// <returns>
 /// A collection of all child files that match the given regex.
 /// </returns>
 public abstract ReadOnlyCollection<FilePath> GetChildFiles(DirectoryPath directory, Regex regex);
Ejemplo n.º 29
0
        public override void Delete(DirectoryPath path, bool deleteChildPaths = false)
        {
            String rawPath = PathToRealPath(path);

            if (Directory.Exists(rawPath))
            {
                Directory.Delete(rawPath, deleteChildPaths);
            }
        }
Ejemplo n.º 30
0
 public override bool Exists(DirectoryPath path)
 {
     return this.BaseFileSystem.Exists(TranslatePathToBaseSystem(path));
 }