mirror of
https://github.com/oliverbooth/fdup.git
synced 2024-12-05 02:08:48 +00:00
feat: enable verbose output to list hash of every file
This commit is contained in:
parent
d2ca59e174
commit
435318cd20
@ -1,6 +1,4 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Diagnostics;
|
||||
using System.Security;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Spectre.Console;
|
||||
@ -110,7 +108,7 @@ internal sealed class ListCommand : AsyncCommand<ListSettings>
|
||||
{
|
||||
string relativeFilePath = Path.GetRelativePath(inputDirectory.FullName, file.FullName);
|
||||
AnsiConsole.MarkupLineInterpolated($"Checking hash for [cyan]{relativeFilePath}[/]");
|
||||
tasks.Add(Task.Run(() => ProcessFile(file)));
|
||||
tasks.Add(Task.Run(() => ProcessFile(file, settings)));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -120,7 +118,7 @@ internal sealed class ListCommand : AsyncCommand<ListSettings>
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessFile(FileInfo file)
|
||||
private void ProcessFile(FileInfo file, ListSettings settings)
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[64];
|
||||
try
|
||||
@ -129,7 +127,8 @@ internal sealed class ListCommand : AsyncCommand<ListSettings>
|
||||
using BufferedStream bufferedStream = new BufferedStream(stream, 1048576 /* 1MB */);
|
||||
SHA512.HashData(bufferedStream, buffer);
|
||||
string hash = ByteSpanToString(buffer);
|
||||
Trace.WriteLine($"{file.FullName}: {hash}");
|
||||
if (settings.Verbose)
|
||||
AnsiConsole.WriteLine($"{file.FullName} ->\n {hash}");
|
||||
|
||||
if (!_fileHashMap.TryGetValue(hash, out List<FileInfo>? cache))
|
||||
_fileHashMap[hash] = cache = new List<FileInfo>();
|
||||
|
@ -13,4 +13,9 @@ internal sealed class ListSettings : CommandSettings
|
||||
[Description("When this flag is set, the directory will be scanned recursively. This may take longer.")]
|
||||
[DefaultValue(false)]
|
||||
public bool Recursive { get; set; } = false;
|
||||
|
||||
[CommandOption("--verbose")]
|
||||
[Description("Enable verbose output.")]
|
||||
[DefaultValue(false)]
|
||||
public bool Verbose { get; set; } = false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user