public void Extension(NewFileSystemDelegate fsFactory) { DiscFileSystem fs = fsFactory(); Assert.AreEqual("dir", fs.GetDirectoryInfo("fred.dir").Extension); Assert.AreEqual("", fs.GetDirectoryInfo("fred").Extension); }
public void FullName(NewFileSystemDelegate fsFactory) { DiscFileSystem fs = fsFactory(); Assert.AreEqual(@"\", fs.Root.FullName); Assert.AreEqual(@"SOMEDIR\", fs.GetDirectoryInfo(@"SOMEDIR").FullName); Assert.AreEqual(@"SOMEDIR\CHILDDIR\", fs.GetDirectoryInfo(@"SOMEDIR\CHILDDIR").FullName); }
public void Parent(NewFileSystemDelegate fsFactory) { DiscFileSystem fs = fsFactory(); fs.CreateDirectory(@"SOMEDIR\ADIR"); using (Stream s = fs.OpenFile(@"SOMEDIR\ADIR\FILE.TXT", FileMode.Create)) { } DiscFileInfo fi = fs.GetFileInfo(@"SOMEDIR\ADIR\FILE.TXT"); Assert.AreEqual(fs.GetDirectoryInfo(@"SOMEDIR\ADIR"), fi.Parent); Assert.AreEqual(fs.GetDirectoryInfo(@"SOMEDIR\ADIR"), fi.Directory); }
public void CreateRecursive(NewFileSystemDelegate fsFactory) { DiscFileSystem fs = fsFactory(); DiscDirectoryInfo dirInfo = fs.GetDirectoryInfo(@"SOMEDIR\CHILDDIR"); dirInfo.Create(); Assert.AreEqual(1, fs.Root.GetDirectories().Length); Assert.AreEqual(1, fs.GetDirectoryInfo(@"SOMEDIR").GetDirectories().Length); Assert.AreEqual("CHILDDIR", fs.GetDirectoryInfo(@"SOMEDIR").GetDirectories()[0].Name); }
public void CreateInvalid_Characters(NewFileSystemDelegate fsFactory) { DiscFileSystem fs = fsFactory(); DiscDirectoryInfo dirInfo = fs.GetDirectoryInfo("SOME\0DIR"); dirInfo.Create(); }
public void CreateInvalid_Long(NewFileSystemDelegate fsFactory) { DiscFileSystem fs = fsFactory(); DiscDirectoryInfo dirInfo = fs.GetDirectoryInfo(new String('X', 256)); dirInfo.Create(); }
public void Create(NewFileSystemDelegate fsFactory) { DiscFileSystem fs = fsFactory(); DiscDirectoryInfo dirInfo = fs.GetDirectoryInfo("SOMEDIR"); dirInfo.Create(); Assert.AreEqual(1, fs.Root.GetDirectories().Length); }
public void Move(NewFileSystemDelegate fsFactory) { DiscFileSystem fs = fsFactory(); fs.CreateDirectory(@"SOMEDIR\CHILD\GCHILD"); fs.GetDirectoryInfo(@"SOMEDIR\CHILD").MoveTo("NEWDIR"); Assert.AreEqual(2, fs.Root.GetDirectories().Length); Assert.AreEqual(0, fs.Root.GetDirectories("SOMEDIR")[0].GetDirectories().Length); }
public void LastWriteTime(NewFileSystemDelegate fsFactory) { DiscFileSystem fs = fsFactory(); fs.CreateDirectory("DIR"); DiscDirectoryInfo di = fs.GetDirectoryInfo("DIR"); DateTime baseTime = DateTime.Now - TimeSpan.FromMinutes(10); di.LastWriteTime = baseTime; fs.CreateDirectory(@"DIR\CHILD"); Assert.Less(baseTime, di.LastWriteTime); }
public void Exists(NewFileSystemDelegate fsFactory) { DiscFileSystem fs = fsFactory(); DiscDirectoryInfo dirInfo = fs.GetDirectoryInfo(@"SOMEDIR\CHILDDIR"); dirInfo.Create(); Assert.IsTrue(fs.GetDirectoryInfo(@"\").Exists); Assert.IsTrue(fs.GetDirectoryInfo(@"SOMEDIR").Exists); Assert.IsTrue(fs.GetDirectoryInfo(@"SOMEDIR\CHILDDIR").Exists); Assert.IsTrue(fs.GetDirectoryInfo(@"SOMEDIR\CHILDDIR\").Exists); Assert.IsFalse(fs.GetDirectoryInfo(@"NONDIR").Exists); Assert.IsFalse(fs.GetDirectoryInfo(@"SOMEDIR\NONDIR").Exists); }
public void CreateDeleteLeakTest(NewFileSystemDelegate fsFactory) { DiscFileSystem fs = fsFactory(); for (int i = 0; i < 2000; ++i) { fs.CreateDirectory(@"Fred"); fs.Root.GetDirectories(@"Fred")[0].Delete(); } fs.CreateDirectory(@"SOMEDIR"); DiscDirectoryInfo dirInfo = fs.GetDirectoryInfo(@"SOMEDIR"); Assert.IsNotNull(dirInfo); for (int i = 0; i < 2000; ++i) { fs.CreateDirectory(@"SOMEDIR\Fred"); dirInfo.GetDirectories(@"Fred")[0].Delete(); } }
// private static WellKnownPartitionType GetPartitionType(PartitionInfo Partition) // { // switch (Partition.BiosType) // { // case BiosPartitionTypes.Fat16: // case BiosPartitionTypes.Fat32: // case BiosPartitionTypes.Fat32Lba: // return WellKnownPartitionType.WindowsFat; // case BiosPartitionTypes.Ntfs: // return WellKnownPartitionType.WindowsNtfs; // case BiosPartitionTypes.LinuxNative: // return WellKnownPartitionType.Linux; // case BiosPartitionTypes.LinuxSwap: // return WellKnownPartitionType.LinuxSwap; // case BiosPartitionTypes.LinuxLvm: // return WellKnownPartitionType.LinuxLvm; // default: // throw new ArgumentException( // String.Format("Unsupported partition type: '{0}'", BiosPartitionTypes.ToString(Partition.BiosType)), "Partition"); // } // } // // private static DiscFileSystem DetectFileSystem(PartitionInfo Partition) // { // using (var stream = Partition.Open()) // { // if (NtfsFileSystem.Detect(stream)) // return new NtfsFileSystem(Partition.Open()); // stream.Seek(0, SeekOrigin.Begin); // if (FatFileSystem.Detect(stream)) // return new FatFileSystem(Partition.Open()); // // /* Ext2/3/4 file system - when Ext becomes fully writable // // stream.Seek(0, SeekOrigin.Begin); // if (ExtFileSystem.Detect(stream)) // return new ExtFileSystem(Partition.Open()); // */ // // return null; // } // } private static void DiffPart(DiscFileSystem PartA, DiscFileSystem PartB, DiscFileSystem Output, ComparisonStyle Style = ComparisonStyle.DateTimeOnly, CopyQueue WriteQueue = null) { if (PartA == null) throw new ArgumentNullException("PartA"); if (PartB == null) throw new ArgumentNullException("PartB"); if (Output == null) throw new ArgumentNullException("Output"); if (PartA is NtfsFileSystem) { ((NtfsFileSystem) PartA).NtfsOptions.HideHiddenFiles = false; ((NtfsFileSystem) PartA).NtfsOptions.HideSystemFiles = false; } if (PartB is NtfsFileSystem) { ((NtfsFileSystem) PartB).NtfsOptions.HideHiddenFiles = false; ((NtfsFileSystem) PartB).NtfsOptions.HideSystemFiles = false; } if (Output is NtfsFileSystem) { ((NtfsFileSystem) Output).NtfsOptions.HideHiddenFiles = false; ((NtfsFileSystem) Output).NtfsOptions.HideSystemFiles = false; } if (WriteQueue == null) WriteQueue = new CopyQueue(); var RootA = PartA.Root; var RootB = PartB.Root; var OutRoot = Output.Root; var OutFileRoot = Output.GetDirectoryInfo(RootFiles); if (!OutFileRoot.Exists) OutFileRoot.Create(); CompareTree(RootA, RootB, OutFileRoot, WriteQueue, Style); WriteQueue.Go(); // Now handle registry files (if any) ParallelQuery<DiscFileInfo> Ofiles; lock(OutFileRoot.FileSystem) Ofiles = OutFileRoot.GetFiles("*.*", SearchOption.AllDirectories).AsParallel(); Ofiles = Ofiles.Where(dfi => SystemRegistryFiles.Contains(dfi.FullName, StringComparer.CurrentCultureIgnoreCase)); foreach (var file in Ofiles) { var A = PartA.GetFileInfo(file.FullName.Substring(RootFiles.Length + 1)); if (!A.Exists) { file.FileSystem.MoveFile(file.FullName, String.Concat(RootSystemRegistry, A.FullName)); continue; } //else MemoryStream SideA = new MemoryStream(); using (var tmp = A.OpenRead()) tmp.CopyTo(SideA); MemoryStream SideB = new MemoryStream(); using (var tmp = file.OpenRead()) tmp.CopyTo(SideB); var comp = new RegistryComparison(SideA, SideB, RegistryComparison.Side.B); comp.DoCompare(); var diff = new RegDiff(comp, RegistryComparison.Side.B); var outFile = Output.GetFileInfo(Path.Combine(RootSystemRegistry, file.FullName)); if (!outFile.Directory.Exists) { outFile.Directory.Create(); } using (var OUT = outFile.Open(outFile.Exists ? FileMode.Truncate : FileMode.CreateNew, FileAccess.ReadWrite)) diff.WriteToStream(OUT); file.Delete(); // remove this file from the set of file to copy and overwrite } lock (OutFileRoot.FileSystem) Ofiles = OutFileRoot.GetFiles("*.*", SearchOption.AllDirectories).AsParallel(); Ofiles = Ofiles.Where(dfi => UserRegisrtyFiles.IsMatch(dfi.FullName)); foreach (var file in Ofiles) { var match = UserRegisrtyFiles.Match(file.FullName); var A = PartA.GetFileInfo(file.FullName.Substring(RootFiles.Length + 1)); if (!A.Exists) { file.FileSystem.MoveFile(file.FullName, Path.Combine(RootUserRegistry, match.Groups["user"].Value, A.Name)); continue; } //else MemoryStream SideA = new MemoryStream(); using (var tmp = A.OpenRead()) tmp.CopyTo(SideA); MemoryStream SideB = new MemoryStream(); using (var tmp = file.OpenRead()) tmp.CopyTo(SideB); var comp = new RegistryComparison(SideA, SideB, RegistryComparison.Side.B); comp.DoCompare(); var diff = new RegDiff(comp, RegistryComparison.Side.B); var outFile = Output.GetFileInfo(Path.Combine(RootUserRegistry, match.Groups["user"].Value, file.FullName)); if (!outFile.Directory.Exists) { outFile.Directory.Create(); } using (var OUT = outFile.Open(outFile.Exists ? FileMode.Truncate : FileMode.CreateNew, FileAccess.ReadWrite)) diff.WriteToStream(OUT); file.Delete(); // remove this file from the set of file to copy and overwrite } }
public void Equals(NewFileSystemDelegate fsFactory) { DiscFileSystem fs = fsFactory(); Assert.AreEqual(fs.GetDirectoryInfo("foo"), fs.GetDirectoryInfo("foo")); }