Skip to content

Commit

Permalink
Failed attempt to improve program(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
Barry Carter authored and Barry Carter committed Mar 7, 2012
1 parent 9f9f724 commit 1fbf8f0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
14 changes: 9 additions & 5 deletions bc-dupe-checker.pl
Expand Up @@ -3,12 +3,15 @@
# given a file with the (unsorted) output of sha1sum, list duplicate files
# fairly trivial to write

require "bclib.pl";
# "bc-dupe-checker.pl sha1file | xargs ls -l | sort -k5nr" helpful in
# finding large duplicates

chdir(tmpdir());
push(@INC, "/usr/local/lib");
require "bclib.pl";
$dir = tmpdir();

system("sort $ARGV[0] > sha1sorted.txt");
$sha1s = read_file("sha1sorted.txt");
system("sort $ARGV[0] > $dir/sha1sorted.txt");
$sha1s = read_file("$dir/sha1sorted.txt");

for $i (split(/\n/, $sha1s)) {
# confirm the line is really sha1 or md5 followed by filename
Expand All @@ -22,7 +25,8 @@

# are we seeing the same sha1 again?
if ($sha1 eq $cur) {
print "'$file'\n";
# print qq%"$file";: $cur\n%;
print qq%"$file"\n%;
next;
}

Expand Down
5 changes: 5 additions & 0 deletions bc-extract-attachments.pl
Expand Up @@ -4,6 +4,7 @@
# consistent "sha1" format. Recreates mailbox with pointers to
# attachment files

push(@INC,"/usr/local/lib");
require "bclib.pl";

# list of types we can handle (excl image/jpeg and octet-stream, which
Expand All @@ -23,6 +24,7 @@
handle_attachment($msg);
$msg=$_;
} else {
debug("READ: $_");
$msg = "$msg$_";
}
}
Expand All @@ -32,6 +34,7 @@

sub handle_attachment {
my($a)=@_;
debug("handle_attachment length:". length($a));
my($fname, $ctype, $bound);
# need a global to preserve uniqueness
$attachnum++;
Expand All @@ -45,6 +48,7 @@ sub handle_attachment {
}

my($head,$body)=($1,$2);
debug("HEAD: $head");

# if multipart, get content-type and boundary (if not, just get content-type)
if ($head=~/Content-[Tt]ype: (.*?); boundary="(.*?)"/m) {
Expand All @@ -57,6 +61,7 @@ sub handle_attachment {
}

my($ctype)=$1;
debug("CTYPE: $ctype");

# is this a multipart msg? if so, recurse
if ($ctype=~m!multipart/(.*?)!i) {
Expand Down

0 comments on commit 1fbf8f0

Please sign in to comment.