예제 #1
0
        public void EnumerateMountsOverride()
        {
            var baseFs = new MemoryFileSystem();

            baseFs.CreateDirectory("/foo/bar");
            baseFs.WriteAllText("/base.txt", "test");
            baseFs.WriteAllText("/foo/base.txt", "test");
            baseFs.WriteAllText("/foo/bar/base.txt", "test");

            var mountedFs = new MemoryFileSystem();

            mountedFs.WriteAllText("/mounted.txt", "test");

            var deepMountedFs = new MemoryFileSystem();

            deepMountedFs.WriteAllText("/deep_mounted.txt", "test");

            var mountFs = new MountFileSystem(baseFs);

            mountFs.Mount("/foo", mountedFs);
            mountFs.Mount("/foo/bar", deepMountedFs);

            var expected = new List <UPath>
            {
                "/base.txt",
                "/foo",
                "/foo/bar",
                "/foo/mounted.txt",
                "/foo/bar/deep_mounted.txt"
            };

            var actual = mountFs.EnumeratePaths("/", "*", SearchOption.AllDirectories).ToList();

            Assert.Equal(expected, actual);
        }
예제 #2
0
        public void MoveDirectoryFail()
        {
            var mountfs = new MountFileSystem();

            mountfs.Mount("/dir1", new MemoryFileSystem());
            mountfs.Mount("/dir2", new MemoryFileSystem());

            Assert.Throws <UnauthorizedAccessException>(() => mountfs.MoveDirectory("/dir1", "/dir2/yyy"));
            Assert.Throws <UnauthorizedAccessException>(() => mountfs.MoveDirectory("/dir1/xxx", "/dir2"));
            Assert.Throws <NotSupportedException>(() => mountfs.MoveDirectory("/dir1/xxx", "/dir2/yyy"));
        }
예제 #3
0
        public void TestMount()
        {
            var fs    = new MountFileSystem();
            var memfs = new MemoryFileSystem();

            Assert.Throws <ArgumentNullException>(() => fs.Mount(null, memfs));
            Assert.Throws <ArgumentNullException>(() => fs.Mount("/test", null));
            Assert.Throws <ArgumentException>(() => fs.Mount("test", memfs));
            Assert.Throws <ArgumentException>(() => fs.Mount("/", memfs));

            Assert.False(fs.IsMounted("/test"));
            fs.Mount("/test", memfs);
            Assert.True(fs.IsMounted("/test"));
            Assert.Throws <ArgumentException>(() => fs.Mount("/test", memfs));
            Assert.Throws <ArgumentException>(() => fs.Mount("/test", fs));

            Assert.Throws <ArgumentNullException>(() => fs.Unmount(null));
            Assert.Throws <ArgumentException>(() => fs.Unmount("test"));
            Assert.Throws <ArgumentException>(() => fs.Unmount("/"));
            Assert.Throws <ArgumentException>(() => fs.Unmount("/test/a"));
            Assert.Throws <ArgumentException>(() => fs.Unmount("/test/a/b"));
            Assert.Throws <ArgumentException>(() => fs.Unmount("/test2"));

            fs.Mount("/test2", memfs);
            Assert.True(fs.IsMounted("/test"));
            Assert.True(fs.IsMounted("/test2"));

            Assert.Equal(new Dictionary <UPath, IFileSystem>()
            {
                { "/test", memfs },
                { "/test2", memfs },
            }, fs.GetMounts());

            fs.Unmount("/test");
            Assert.False(fs.IsMounted("/test"));
            Assert.True(fs.IsMounted("/test2"));

            fs.Unmount("/test2");

            Assert.Equal(0, fs.GetMounts().Count);

            var innerFs = GetCommonMemoryFileSystem();

            fs.Mount("/x/y", innerFs);
            fs.Mount("/x/y/b", innerFs);
            Assert.True(fs.FileExists("/x/y/A.txt"));
            Assert.True(fs.FileExists("/x/y/b/A.txt"));
        }
예제 #4
0
        public void EnumerateDoesntExist()
        {
            var mountFs = new MountFileSystem();

            mountFs.Mount("/x", new MemoryFileSystem());
            Assert.Throws <DirectoryNotFoundException>(() => mountFs.EnumeratePaths("/y", "*", SearchOption.AllDirectories, SearchTarget.Both).ToList());
        }
예제 #5
0
        public void MoveFileFail()
        {
            var mountfs = new MountFileSystem();
            var memfs1  = new MemoryFileSystem();

            memfs1.WriteAllText("/file.txt", "content1");

            var memfs2 = new MemoryFileSystem();

            memfs2.WriteAllText("/file2.txt", "content1");

            mountfs.Mount("/dir1", memfs1);
            mountfs.Mount("/dir2", memfs2);
            Assert.Throws <DirectoryNotFoundException>(() => mountfs.MoveFile("/dir1/file.txt", "/xxx/yyy.txt"));
            Assert.Throws <FileNotFoundException>(() => mountfs.MoveFile("/dir1/xxx", "/dir1/file1.txt"));
            Assert.Throws <FileNotFoundException>(() => mountfs.MoveFile("/xxx", "/dir1/file1.txt"));
        }
예제 #6
0
        public void ReplaceFileFail()
        {
            var mountfs = new MountFileSystem();
            var memfs1  = new MemoryFileSystem();

            memfs1.WriteAllText("/file.txt", "content1");

            var memfs2 = new MemoryFileSystem();

            memfs2.WriteAllText("/file2.txt", "content1");

            mountfs.Mount("/dir1", memfs1);
            mountfs.Mount("/dir2", memfs2);
            Assert.Throws <FileNotFoundException>(() => mountfs.ReplaceFile("/dir1/file.txt", "/dir1/to.txt", "/dir1/to.bak", true));
            Assert.Throws <FileNotFoundException>(() => mountfs.ReplaceFile("/dir1/to.txt", "/dir1/file.txt", "/dir1/to.bak", true));
            Assert.Throws <NotSupportedException>(() => mountfs.ReplaceFile("/dir1/file.txt", "/dir2/file2.txt", null, true));
        }
예제 #7
0
        public void CopyFileFail()
        {
            var mountfs = new MountFileSystem();

            mountfs.Mount("/dir1", new MemoryFileSystem());
            Assert.Throws <FileNotFoundException>(() => mountfs.CopyFile("/test", "/test2", true));
            Assert.Throws <DirectoryNotFoundException>(() => mountfs.CopyFile("/dir1/test.txt", "/test2", true));
        }
예제 #8
0
        public TestMountFileSystemCompatSub()
        {
            // Check that MountFileSystem is working with a mount with the compat test
            var mountfs = new MountFileSystem();
            mountfs.Mount("/customMount", new MemoryFileSystem());

            // Use a SubFileSystem to fake the mount to a root folder
            fs = new SubFileSystem(mountfs, "/customMount");
        }
예제 #9
0
        public void Read()
        {
            // check the inputPath
            if (!Directory.Exists(InputPath))
            {
                throw new DirectoryNotFoundException("The input path is not a valid directory");
            }

            // change the (probably) relative path to an absolute one
            InputPath = Path.GetFullPath(InputPath);

            // again.. change the (probably) relative path to an absolute one
            OutputPath = Path.GetFullPath(OutputPath);

            _logger.Info($"Source path: '{InputPath}'");
            _logger.Info($"Output path: '{OutputPath}'");

            // check the project configuration file
            foreach (var extension in new[] { "yaml", "yml" })
            {
                var path = Path.Join(InputPath, $"project.{extension}");

                if (File.Exists(path))
                {
                    ProjectConfigurationPath = path;
                    break;
                }
            }

            if (string.IsNullOrWhiteSpace(ProjectConfigurationPath))
            {
                throw new FileNotFoundException("The project configuration file does not exist");
            }

            _logger.Info($"Reading the project file '{ProjectConfigurationPath}'");

            var yamlDeserializer = new Deserializer();
            var configStream     = File.OpenText(ProjectConfigurationPath);

            ProjectData = yamlDeserializer.Deserialize <ProjectData>(configStream);

            _fileSystem = new MountFileSystem(new SubFileSystem(new PhysicalFileSystem(), OsPathToUPath(InputPath)));

            foreach (var i in ProjectData.Includes)
            {
                i.Path = Path.GetFullPath(i.Path, InputPath);

                if (!Directory.Exists(i.Path))
                {
                    throw new DirectoryNotFoundException($"The include directory does not exist: '{i.Path}'");
                }

                _fileSystem.Mount(i.Mount, new SubFileSystem(new PhysicalFileSystem(), OsPathToUPath(i.Path)));
            }

            _logger.Info(ProjectData);
        }
예제 #10
0
        public void DeleteDirectoryFail()
        {
            var mountfs = new MountFileSystem();

            mountfs.Mount("/dir1", new MemoryFileSystem());

            Assert.Throws <UnauthorizedAccessException>(() => mountfs.DeleteDirectory("/dir1", true));
            Assert.Throws <UnauthorizedAccessException>(() => mountfs.DeleteDirectory("/dir1", false));
            Assert.Throws <DirectoryNotFoundException>(() => mountfs.DeleteDirectory("/dir2", false));
        }
예제 #11
0
        protected MountFileSystem GetCommonMountFileSystemWithMounts()
        {
            // Check on MountFileSystem
            // with real mount
            var fs = new MemoryFileSystem();

            CreateFolderStructure(fs);
            fs.DeleteDirectory("/b", true);
            fs.DeleteDirectory("/C", true);

            var fs1 = new MemoryFileSystem();

            fs1.WriteAllText("/b.i", "content");

            var mountfs = new MountFileSystem(fs);

            mountfs.Mount("/b", fs1);
            mountfs.Mount("/C", new MemoryFileSystem());

            return(mountfs);
        }
예제 #12
0
        public void DirectoryExistsPartialMountName()
        {
            var fs      = new MemoryFileSystem();
            var mountFs = new MountFileSystem();

            mountFs.Mount("/x/y/z", fs);

            Assert.True(mountFs.DirectoryExists("/x"));
            Assert.True(mountFs.DirectoryExists("/x/y"));
            Assert.True(mountFs.DirectoryExists("/x/y/z"));
            Assert.False(mountFs.DirectoryExists("/z"));
        }
예제 #13
0
        public void CopyAndMoveFileCross()
        {
            var mountfs = new MountFileSystem();
            var memfs1  = new MemoryFileSystem();

            memfs1.WriteAllText("/file1.txt", "content1");
            var memfs2 = new MemoryFileSystem();

            mountfs.Mount("/dir1", memfs1);
            mountfs.Mount("/dir2", memfs2);

            mountfs.CopyFile("/dir1/file1.txt", "/dir2/file2.txt", true);

            Assert.True(memfs2.FileExists("/file2.txt"));
            Assert.Equal("content1", memfs2.ReadAllText("/file2.txt"));

            mountfs.MoveFile("/dir1/file1.txt", "/dir2/file1.txt");

            Assert.False(memfs1.FileExists("/file1.txt"));
            Assert.True(memfs2.FileExists("/file1.txt"));
            Assert.Equal("content1", memfs2.ReadAllText("/file1.txt"));
        }
예제 #14
0
        public void DirectoryEntryPartialMountName()
        {
            var fs = new MemoryFileSystem();

            fs.CreateDirectory("/w");

            var mountFs = new MountFileSystem();

            mountFs.Mount("/x/y/z", fs);

            Assert.NotNull(mountFs.GetDirectoryEntry("/x"));
            Assert.NotNull(mountFs.GetDirectoryEntry("/x/y"));
            Assert.NotNull(mountFs.GetDirectoryEntry("/x/y/z"));
            Assert.NotNull(mountFs.GetDirectoryEntry("/x/y/z/w"));
        }
예제 #15
0
        public void EnumerateDeepMountPartial()
        {
            var fs      = GetCommonMemoryFileSystem();
            var mountFs = new MountFileSystem();

            mountFs.Mount("/x/y/z", fs);
            Assert.True(mountFs.FileExists("/x/y/z/A.txt"));

            var expected = new List <UPath>
            {
                "/x/y",
                "/x/y/z",
                "/x/y/z/a",
                "/x/y/z/A.txt"
            };

            // only concerned with the first few because it should list the mount parts first
            var actual = mountFs.EnumeratePaths("/x", "*", SearchOption.AllDirectories).Take(4).ToList();

            Assert.Equal(expected, actual);
        }