public void EmptyDatabasesReturnsEmpty() { var dba = new MemoryFileDatabase(); var dbb = new MemoryFileDatabase(); var sut = new FileDuplicateFinder(new StatDuplicateComparer()); var actual = sut.Find(dba, dbb); Assert.That(actual, Is.Empty); }
public void DifferentDatabasesReturnsEmpty() { var dba = new MemoryFileDatabase(); dba.UpdateDescriptor(new FileDescriptor("A.txt") {StatHash = new byte[] { 1 } }); dba.UpdateDescriptor(new FileDescriptor("B.txt") { StatHash = new byte[] { 2 } }); var dbb = new MemoryFileDatabase(); dbb.UpdateDescriptor(new FileDescriptor("C.txt") { StatHash = new byte[] { 3 } }); dbb.UpdateDescriptor(new FileDescriptor("D.txt") { StatHash = new byte[] { 4 } }); var sut = new FileDuplicateFinder(new StatDuplicateComparer()); var actual = sut.Find(dba, dbb); Assert.That(actual, Is.Empty); }
public void ReturnsAllDuplicatePairs() { var dba = new MemoryFileDatabase(); dba.UpdateDescriptor(new FileDescriptor("A.txt") {StatHash = new byte[] { 1 } }); dba.UpdateDescriptor(new FileDescriptor("B.txt") { StatHash = new byte[] { 2 } }); var dbb = new MemoryFileDatabase(); dbb.UpdateDescriptor(new FileDescriptor("C.txt") { StatHash = new byte[] { 1 } }); dbb.UpdateDescriptor(new FileDescriptor("D.txt") { StatHash = new byte[] { 4 } }); dbb.UpdateDescriptor(new FileDescriptor("E.txt") { StatHash = new byte[] { 2 } }); dbb.UpdateDescriptor(new FileDescriptor("F.txt") { StatHash = new byte[] { 2 } }); var sut = new FileDuplicateFinder(new StatDuplicateComparer()); var actual = sut.Find(dba, dbb).ToList(); Assert.That(actual, Has.Count.EqualTo(3)); Assert.That(actual[0].Descriptors.Select(x => x.Name), Is.EqualTo(new [] { "A.txt", "C.txt"})); Assert.That(actual[1].Descriptors.Select(x => x.Name), Is.EqualTo(new [] { "B.txt", "E.txt"})); Assert.That(actual[2].Descriptors.Select(x => x.Name), Is.EqualTo(new [] { "B.txt", "F.txt"})); }
static void Main(string[] args) { var options = new Options(); if (!Parser.Default.ParseArguments(args, options)) { Environment.Exit(1); } var baseFolder = options.ScanFolder; var database = new MemoryFileDatabase(); if (!string.IsNullOrEmpty(options.ScanFolder)) { FileDescriptor rootDescriptor = null; if (Directory.Exists(options.ScanFolder)) { rootDescriptor = StatScanFolder(database, baseFolder); } else if (File.Exists(options.ScanFolder)) { database = MemoryFileDatabase.Load(options.ScanFolder); rootDescriptor = database.RootDescriptor; } else { Console.WriteLine($"Could not open {options.ScanFolder}"); Console.WriteLine(options.GetUsage()); Environment.Exit(1); } if (options.ReadContent) UpdateContentSignatures(database, rootDescriptor); if (options.SaveDatabase) database.SaveDefault(); if (options.Verbose) { PrintDescriptorTree(rootDescriptor, descriptor => descriptor.StatHash); } var duplicateComparer = options.DuplicateMode == DuplicateMode.Stat ? (IDuplicateComparer) new StatDuplicateComparer() : new ContentDuplicateComparer(); if (options.ShowFileDuplicates) { Console.WriteLine("FILE DUPLICATES"); Console.WriteLine("---------------"); var duplicateFinder = new FileDuplicateFinder(duplicateComparer); var duplicates = duplicateFinder.Find(database, database); PrintDuplicates(duplicates); } if (options.ShowTopDuplicates) { Console.WriteLine("TOP DUPLICATES"); Console.WriteLine("--------------"); var duplicateFinder = new TopDescriptorDuplicateFinder(duplicateComparer); var duplicates = duplicateFinder.Find(database, database); PrintDuplicates(duplicates); } } }