Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 4f18ca958f
Fetching contributors…

Cannot retrieve contributors at this time

executable file 43 lines (34 sloc) 1.029 kb
#!/usr/bin/env perl
use strict;
use Digest::MD5 ();
use File::Spec::Functions;
use Getopt::Std;
use Act::Config;
use Act::User;
use Act::Util;
my %opts;
getopts('n', \%opts) or die "usage: $0 [-n]\n";
Act::Util::db_connect;
# loop on users with a photo
my $dir = catfile($Config->home, 'wwwdocs', $Config->general_dir_photos);
for my $user ( @{ Act::User->get_items() } ) {
next unless $user->photo_name;
printf "%-10s ", $user->photo_name;
my $pathname = catfile($dir, $user->photo_name);
open my $fh, $pathname or print "can't open $pathname: $!\n" and next;
my $digest = Digest::MD5->new->addfile($fh)->hexdigest;
(my $ext) = $user->photo_name =~ /(\..*)$/;
my $newfile = $digest . $ext;
my $newpath = catfile($dir, $newfile);
if ($newpath ne $pathname) {
# rename
print " => $newfile\n";
unless ($opts{n}) {
rename($pathname, $newpath);
$user->update(photo_name => $newfile);
}
}
else {
print "\n";
}
}
Jump to Line
Something went wrong with that request. Please try again.