public void EmptyDatabasesReturnsEmpty()
        {
            var dba = new MemoryFileDatabase();
            var dbb = new MemoryFileDatabase();
            var sut = new TopDescriptorDuplicateFinder(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 TopDescriptorDuplicateFinder(new StatDuplicateComparer());

            var actual = sut.Find(dba, dbb);
            Assert.That(actual, Is.Empty);
        }
Пример #3
0
        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);
                }
            }
        }
        public void FolderDuplicateReturnedForSelfFinding()
        {
            var builder = new FileDescriptorBuilder("A", 1,
                new FileDescriptorBuilder("B1", 2),
                new FileDescriptorBuilder("C1", 3,
                    new FileDescriptorBuilder("D1", 4,
                        new FileDescriptorBuilder("E1", 5))),
                new FileDescriptorBuilder("X", 10,
                new FileDescriptorBuilder("B2", 11),
                new FileDescriptorBuilder("C2", 3,
                    new FileDescriptorBuilder("D2", 4,
                        new FileDescriptorBuilder("E2", 5)))));
            var db = new MemoryFileDatabase(builder.Build());
            var sut = new TopDescriptorDuplicateFinder(new StatDuplicateComparer());

            var actual = sut.Find(db, db).ToList();
            Assert.That(actual, Has.Count.EqualTo(1));
            Assert.That(actual.Single().Descriptors.Select(x => x.Name), Is.EquivalentTo(new [] {"C1", "C2"}));
        }