From 4eea6ddb8476f227580c0aa4fc3043bbed2ca385 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Mon, 21 May 2012 18:02:12 +0200 Subject: [PATCH] display and/or create md5sum in user.md5 xattr --- md5-attr.pl | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 md5-attr.pl diff --git a/md5-attr.pl b/md5-attr.pl new file mode 100755 index 0000000..d60b58c --- /dev/null +++ b/md5-attr.pl @@ -0,0 +1,34 @@ +#!/usr/bin/perl +use warnings; +use strict; +use autodie; +use File::Find; +use IPC::System::Simple qw(system capture); + +my @dirs = @ARGV; +@dirs = ( '.' ) unless @dirs; +my @created; + +sub md5sum { + my $path = shift; + my $md5; + eval { $md5 = capture( qw{attr -q -g md5}, $path ) }; + if ( $md5 =~ /^[0-9a-fA-F]{32}$/ ) { + print "$md5 $path\n"; + } else { + warn "# md5sum $path\n"; + my $line = capture( 'md5sum', $path ); + ($md5) = split(/\s+/, $line, 2); + system( qw{attr -q -s md5 -V}, $md5, $path ); + warn "# $md5 $path\n"; + push @created, $path; + print "$md5 $path\n"; + } +} + +find({ + wanted => sub { md5sum $_ if -f $_ }, + no_chdir => 1, +}, @dirs ); + +warn "# created md5sum for:\n", join("\n", @created), "\n"; -- 2.20.1