protected AggregateFileSystem GetCommonAggregateFileSystem(out MemoryFileSystem fs1, out MemoryFileSystem fs2, out MemoryFileSystem fs3)
        {
            // ----------------------------------------------
            // This creates the following AggregateFileSystem
            // ----------------------------------------------
            // /a                 -> fs2
            //     /a             -> fs1
            //        a.txt       -> fs1
            //     /b             -> fs1
            //        b.i         -> fs1
            //     /C             -> fs2
            //     /d             -> fs2
            //     a.txt          -> fs2
            //     A.txt          -> fs2
            //     b.txt          -> fs2
            //     c.txt1         -> fs2
            //     d.i            -> fs2
            //     f.i1           -> fs2
            //     E              -> fs2
            // /b                 -> fs1
            //    b.i             -> fs1
            // /C                 -> fs2
            // /d                 -> fs3
            // A.txt              -> fs3
            // b.txt              -> fs2
            // c.txt1             -> fs3
            // d.i                -> fs3
            // f.i1               -> fs3
            // E                  -> fs2

            fs1 = new MemoryFileSystem()
            {
                Name = "mem0"
            };
            CreateFolderStructure(fs1);
            fs2      = fs1.Clone();
            fs2.Name = "mem1";
            fs3      = fs2.Clone();
            fs3.Name = "mem2";

            // Delete part of fs2 so that it will fallback to fs1
            fs2.DeleteDirectory("/a/a", true);
            fs2.DeleteDirectory("/a/b", true);
            fs2.DeleteDirectory("/b", true);

            // Delete on fs3 to fallback to fs2 and fs1
            fs3.DeleteDirectory("/a", true);
            fs3.DeleteDirectory("/C", true);
            fs3.DeleteFile("/b.txt");
            fs3.DeleteFile("/E");

            var aggfs = new AggregateFileSystem(fs1);

            aggfs.AddFileSystem(fs2);
            aggfs.AddFileSystem(fs3);

            return(aggfs);
        }
Exemple #2
0
        public void 修改檔案日期()
        {
            var rootUPath = CreateRootPath();

            using var fileSystem = new MemoryFileSystem();

            var subName = "TestFolder";

            var subPath      = $"{rootUPath}/{subName}";
            var subPath1     = $"{subPath}/1";
            var subFile1     = $"{subPath}/1/1.txt";
            var subFile2     = $"{subPath}/1/2.txt";
            var subPath1_1   = $"{subPath}/1/1_1";
            var subFile1_1   = $"{subPath}/1/1_1/1_1.txt";
            var subPath1_1_1 = $"{subPath}/1/1_1/1_1_1";
            var subPath2     = $"{subPath}/2";
            var content      = "This is test string";
            var contentBytes = Encoding.UTF8.GetBytes(content);

            if (fileSystem.DirectoryExists(subPath1_1_1) == false)
            {
                fileSystem.CreateDirectory(subPath1_1_1);
            }

            if (fileSystem.DirectoryExists(subPath2) == false)
            {
                fileSystem.CreateDirectory(subPath2);
            }

            if (fileSystem.FileExists(subFile1) == false)
            {
                using var stream =
                          fileSystem.OpenFile(subFile1, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read);
                stream.Write(contentBytes, 0, contentBytes.Length);
            }

            if (fileSystem.FileExists(subFile1_1) == false)
            {
                using var stream =
                          fileSystem.OpenFile(subFile1_1, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read);
                stream.Write(contentBytes, 0, contentBytes.Length);
            }

            var fileEntry = fileSystem.GetFileEntry(subFile1);

            fileEntry.CreationTime   = new DateTime(1900, 1, 1);
            fileEntry.LastWriteTime  = new DateTime(1900, 1, 2);
            fileEntry.LastAccessTime = new DateTime(1900, 1, 3);

            Assert.AreEqual(true, fileSystem.DirectoryExists(subPath1));
            Assert.AreEqual(true, fileSystem.DirectoryExists(subPath1_1));
            Assert.AreEqual(true, fileSystem.DirectoryExists(subPath1_1_1));
            Assert.AreEqual(true, fileSystem.DirectoryExists(subPath2));

            fileSystem.DeleteDirectory(subPath, true);
        }
        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);
        }