Mercurial > projects > doodle
diff doodle/utils/prog/dupes.d @ 120:c275f26399c6
Tinkerings
author | David Bryant <bagnose@gmail.com> |
---|---|
date | Fri, 22 Apr 2011 00:06:07 +0930 |
parents | 8343c1dafac6 |
children | f1cf62339ed5 |
line wrap: on
line diff
--- a/doodle/utils/prog/dupes.d Thu Apr 21 18:12:13 2011 +0930 +++ b/doodle/utils/prog/dupes.d Fri Apr 22 00:06:07 2011 +0930 @@ -3,14 +3,14 @@ import std.exception; import std.file; import std.md5; +import std.getopt; +import std.conv; +import std.c.stdlib; -void find_duplicates(in string[] dirs) { - immutable ulong KILO = 1 << 10; - immutable ulong MEGA = 1 << 20; - - immutable ulong SIZE_THRESHOLD = 100 * KILO; - immutable ulong MD5_AMOUNT = 10 * KILO; - +void find_duplicates(in string[] dirs, + in ulong file_size, + in ulong digest_size, + bool verbose) { static ubyte[16] compute_md5(in string name, in ulong max_bytes) { ubyte[16] digest; @@ -51,7 +51,7 @@ try { if (!isSymLink(name) && isFile(name)) { ulong size = getSize(name); - if (size >= SIZE_THRESHOLD) { + if (size >= file_size) { file_array ~= FileInfo(name, size); } } @@ -103,7 +103,7 @@ const FileInfo file_info = file_array[index]; try { - ubyte[16] digest = compute_md5(file_info.name, MD5_AMOUNT); + ubyte[16] digest = compute_md5(file_info.name, digest_size); if (uint[] * duplicate_indices = (digest in digest_to_indices)) { // A true duplicate @@ -138,7 +138,39 @@ } int main(string[] args) { - find_duplicates(args[1..$]); + immutable ulong KILO = 1 << 10; + immutable ulong MEGA = 1 << 20; + immutable ulong GIGA = 1 << 30; + + /* + static ulong parse_size_string(in string[] s) { + if (s.length == 0) { + throw new ConvException + } + } + */ + + void help(in string) { + writefln("Help"); + exit(1); + } + + ulong file_size = 100 * KILO; + ulong digest_size = 10 * KILO; + bool verbose = false; + + try { + getopt(args, + "file-size|f", &file_size, + "digest-size|d", &digest_size, + "verbose|v", &verbose, + "help|h", &help); + } + catch (ConvException ex) { + + } + + find_duplicates(args[1..$], file_size, digest_size, verbose); return 0; }