display and/or create md5sum in user.md5 xattr
[cloudstore.git] / md5-attr.pl
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use autodie;
5 use File::Find;
6 use IPC::System::Simple qw(system capture);
7
8 my @dirs = @ARGV;
9 @dirs = ( '.' ) unless @dirs;
10 my @created;
11
12 sub md5sum {
13         my $path = shift;
14         my $md5;
15         eval { $md5 = capture( qw{attr -q -g md5}, $path ) };
16         if ( $md5 =~ /^[0-9a-fA-F]{32}$/ ) {
17                 print "$md5  $path\n";
18         } else {
19                 warn "# md5sum $path\n";
20                 my $line = capture( 'md5sum', $path );
21                 ($md5) = split(/\s+/, $line, 2);
22                 system( qw{attr -q -s md5 -V}, $md5, $path );
23                 warn "# $md5 $path\n";
24                 push @created, $path;
25                 print "$md5  $path\n";
26         }
27 }
28
29 find({
30         wanted => sub { md5sum $_ if -f $_ },
31         no_chdir => 1,
32 }, @dirs );
33
34 warn "# created md5sum for:\n", join("\n", @created), "\n";