3 #=======================================================================
5 # File ID: 071005ea-f6bc-11e4-a11c-000df06acc56
7 # Add byte count to output created by "git annex fsck".
10 # ©opyleft 2015– Øyvind A. Holm <sunny@sunbase.org>
11 # License: GNU General Public License version 2 or later, see end of
12 # file for legal stuff.
13 #=======================================================================
18 use Number
::Bytes
::Human
qw(format_bytes);
32 $progname =~ s/^.*\/(.*?)$/$1/;
33 our $VERSION = '0.2.0';
35 Getopt
::Long
::Configure
('bundling');
38 'help|h' => \
$Opt{'help'},
39 'quiet|q+' => \
$Opt{'quiet'},
40 'verbose|v+' => \
$Opt{'verbose'},
41 'version' => \
$Opt{'version'},
43 ) || die("$progname: Option error. Use -h for help.\n");
45 $Opt{'verbose'} -= $Opt{'quiet'};
46 $Opt{'help'} && usage
(0);
47 if ($Opt{'version'}) {
61 while (my $line = <>) {
63 if ($line =~ /Only (\d+) of (\d+) trustworthy copies exist of (.*)$/m) {
64 my ($actual, $wanted, $filename) = ($1, $2, $3);
65 my $bytes = file_size
($filename);
68 $fulltotal += $bytes * ($wanted - $actual);
69 $line .= sprintf(" (%s bytes)",
70 format_bytes
($bytes, bs
=> 1000),
74 if ($line !~ /^ Back it up with git-annex copy\.$/) {
79 printf("Total size of files that need more copies: %s\n",
80 format_bytes
($total, bs
=> 1000));
81 printf("Total space needed to get enough copies : %s\n",
82 format_bytes
($fulltotal, bs
=> 1000));
89 # Read file size from git-annex symlink {{{
93 my $symlink = readlink($filename);
94 if ($symlink =~ /^.*\/[A
-Z0
-9_
]+-s
(\d
+)-/) {
103 # Print program version {{{
104 print("$progname $VERSION\n");
110 # Send the help message to stdout {{{
113 if ($Opt{'verbose'}) {
119 Usage: git annex fsck 2>&1 | $progname [options]
121 Add byte count to output created by "git annex fsck".
128 Be more quiet. Can be repeated to increase silence.
130 Increase level of verbosity. Can be repeated.
132 Print version information.
140 # Print a status message to stderr based on verbosity level {{{
141 my ($verbose_level, $Txt) = @_;
143 if ($Opt{'verbose'} >= $verbose_level) {
144 print(STDERR
"$progname: $Txt\n");
152 # This program is free software; you can redistribute it and/or modify
153 # it under the terms of the GNU General Public License as published by
154 # the Free Software Foundation; either version 2 of the License, or (at
155 # your option) any later version.
157 # This program is distributed in the hope that it will be useful, but
158 # WITHOUT ANY WARRANTY; without even the implied warranty of
159 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
160 # See the GNU General Public License for more details.
162 # You should have received a copy of the GNU General Public License
163 # along with this program.
164 # If not, see L<http://www.gnu.org/licenses/>.
166 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :