Permalink
Browse files

version 0.05 committed to git

  • Loading branch information...
0 parents commit 277a3f0692d42e47e96b898a3b6b10f877150c4d @cog committed Aug 17, 2010
Showing with 769 additions and 0 deletions.
  1. +21 −0 Changes
  2. +22 −0 MANIFEST
  3. +18 −0 Makefile.PL
  4. +157 −0 README
  5. +148 −0 fdu
  6. +292 −0 lib/Filesys/DiskUsage.pm
  7. +7 −0 t/00.load.t
  8. +37 −0 t/01.basic.t
  9. +9 −0 t/02.warnings.t
  10. +36 −0 t/71-version_numbers_are_the_same.t
  11. +6 −0 t/pod-coverage.t
  12. +6 −0 t/pod.t
  13. +1 −0 t/samples/1
  14. +1 −0 t/samples/2
  15. +1 −0 t/samples/3
  16. +1 −0 t/samples/4
  17. +1 −0 t/samples/5
  18. +1 −0 t/samples/6
  19. +1 −0 t/samples/7
  20. +1 −0 t/samples/8
  21. +1 −0 t/samples/a/9
  22. +1 −0 t/samples/a_b/9
@@ -0,0 +1,21 @@
+Revision history for Filesys::DiskUsage
+
+0.05
+ - fix for when a directory isn't openable (kudos to J.T. Conklin
+ for spotting the problem and providing a patch)
+ - added some tests
+
+0.04 Mon Nov 05 10:31:00 2005
+ - added sector-size and symlink-size patch, thanks to Darin McBride
+ - fixed a couple of things on fdu
+
+0.03 Mon Oct 24 17:21:00 2005
+ - added the fdu command
+ - directory excluding now works (thanks to Hussein Patni for pointing
+ this out)
+
+0.02 Wed Jan 19 10:53:00 2005
+ - fixed a bug regarding links, thanks to Steve Cleveland
+
+0.01 Mon Dec 27 16:42:00 2004
+ - first version
@@ -0,0 +1,22 @@
+Changes
+fdu
+lib/Filesys/DiskUsage.pm
+Makefile.PL
+MANIFEST This list of files
+META.yml
+README
+t/00.load.t
+t/01.basic.t
+t/pod-coverage.t
+t/pod.t
+t/samples/1
+t/samples/2
+t/samples/3
+t/samples/4
+t/samples/5
+t/samples/6
+t/samples/7
+t/samples/8
+t/samples/1
+t/samples/a/9
+t/samples/a_b/9
@@ -0,0 +1,18 @@
+use strict;
+use warnings;
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+ NAME => 'Filesys::DiskUsage',
+ AUTHOR => 'Jose Castro <cog@cpan.org>',
+ VERSION_FROM => 'lib/Filesys/DiskUsage.pm',
+ ABSTRACT_FROM => 'lib/Filesys/DiskUsage.pm',
+ PL_FILES => {},
+ 'EXE_FILES' => [],
+ PREREQ_PM => {
+ 'Test::More' => 0,
+ 'File::Basename' => 0,
+ },
+ dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
+ clean => { FILES => 'Filesys-DiskUsage-*' },
+);
@@ -0,0 +1,157 @@
+Filesys::DiskUsage version 0.04
+===============================
+
+=head1 NAME
+
+Filesys::DiskUsage - Estimate file space usage (similar to `du`)
+
+=head1 SYNOPSIS
+
+ use Filesys::DiskUsage qw/du/;
+
+ # basic
+ $total = du(qw/file1 file2 directory1/);
+
+or
+
+ # no recursion
+ $total = du( { recursive => 0 } , <*> );
+
+or
+
+ # max-depth is 1
+ $total = du( { 'max-depth' => 1 } , <*> );
+
+or
+
+ # get an array
+ @sizes = du( @files );
+
+or
+
+ # get a hash
+ %sizes = du( { 'make-hash' => 1 }, @files_and_directories );
+
+=head1 FUNCTIONS
+
+=head2 du
+
+Estimate file space usage.
+
+Get the size of files:
+
+ $total = du(qw/file1 file2/);
+
+Get the size of directories:
+
+ $total = du(qw/file1 directory1/);
+
+=head3 OPTIONS
+
+=over 6
+
+=item dereference
+
+Follow symbolic links. Default is 0. Overrides C<symlink-size>.
+
+Get the size of a directory, recursively, following symbolic links:
+
+ $total = du( { dereference => 1 } , $dir );
+
+=item exclude => PATTERN
+
+Exclude files that match PATTERN.
+
+Get the size of every file except for dot files:
+
+ $total = du( { exclude => qr/^\./ } , @files );
+
+=item human-readable
+
+Return sizes in human readable format (e.g., 1K 234M 2G)
+
+ $total = du ( { 'human-readable' => 1 } , @files );
+
+=item Human-readable
+
+Return sizes in human readable format, but use powers of 1000 instead
+of 1024.
+
+ $total = du ( { 'Human-readable' => 1 } , @files );
+
+=item make-hash
+
+Return the results in a hash.
+
+ %sizes = du( { 'make-hash' => 1 } , @files );
+
+=item max-depth
+
+Sets the max-depth for recursion. A negative number means there is no
+max-depth. Default is -1.
+
+Get the size of every file in the directory and immediate
+subdirectories:
+
+ $total = du( { 'max-depth' => 1 } , <*> );
+
+=item recursive
+
+Sets whether directories are to be explored or not. Set to 0 if you
+don't want recursion. Default is 1. Overrides C<max-depth>.
+
+Get the size of every file in the directory, but not directories:
+
+ $total = du( { recursive => 0 } , <*> );
+
+=item sector-size => NUMBER
+
+All file sizes are rounded up to a multiple of this number. Any file
+that is not an exact multiple of this size will be treated as the next
+multiple of this number as they would in a sector-based file system. Common
+values will be 512 or 1024. Default is 1 (no sectors).
+
+ $total = du( { sector-size => 1024 }, <*> );
+
+=item symlink-size => NUMBER
+
+Symlinks are assumed to be this size. Without this option, symlinks are
+ignored unless dereferenced. Setting this option to 0 will result in the
+files showing up in the hash, if C<make-hash> is set, with a size of 0.
+Setting this option to any other number will treat the size of the symlink
+as this number. This option is ignored if the C<dereference> option is
+set.
+
+ $total = du( { symlink-size => 1024, sector-size => 1024 }, <*> );
+
+=item truncate-readable => NUMBER
+
+Human readable formats decimal places are truncated by the value of
+this option. A negative number means the result won't be truncated at
+all. Default if 2.
+
+Get the size of a file in human readable format with three decimal
+places:
+
+ $size = du( { 'human-readable' => 1 , 'truncate-readable' => 3 } , $file);
+
+=back
+
+=head1 AUTHOR
+
+Jose Castro, C<< <cog@cpan.org> >>
+
+=head1 BUGS
+
+Please report any bugs or feature requests to
+C<bug-disk-usage@rt.cpan.org>, or through the web interface at
+L<http://rt.cpan.org>. I will be notified, and then you'll
+automatically be notified of progress on your bug as I make changes.
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2004 Jose Castro, All Rights Reserved.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
148 fdu
@@ -0,0 +1,148 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use 5.006;
+
+our $VERSION = '0.04';
+
+=head1 NAME
+
+fdu - Estimate file space usage (using Filesys::DiskUsage)
+
+=head1 SYNOPSIS
+
+ fdu [OPTION]... [FILE]...
+
+=head1 DESCRIPTION
+
+Summarize disk usage of each FILE, recursively for directories.
+
+=head1 OPTIONS
+
+=head2 -L
+
+Dereference all symbolic links.
+
+=head2 -X PATTERN
+
+Exclude files that match PATTERN.
+
+=head2 -h
+
+Print sizes in human readable format (e.g., 1K 234M 2G).
+
+=head2 -H
+
+Likewise, but use powers of 1000 not 1024.
+
+=head2 -s N
+
+Assume sector size of N.
+
+=head2 -l N
+
+Assume link size of N (ignored if -L).
+
+=head2 -s N
+
+Assume sector size of N.
+
+=head2 -l N
+
+Assume link size of N (ignored if -L).
+
+=head2 -m MAX-DEPTH
+
+Print the total for a directory (or file) only if it is N or fewer
+levels below the command line argument.
+
+=head2 -t N
+
+If printing sizes in human readable format, truncate all values by the
+Nth place.
+
+=cut
+
+use Getopt::Std qw(getopts);
+use lib 'blib/lib';
+use Filesys::DiskUsage qw/ du /;
+
+our %opts = get_options();
+
+#show_help() if $opts{ };
+show_version() if $opts{v};
+
+my %files = du( { 'make-hash' => 1, %opts }, @ARGV );
+my $human = $opts{'human-readable'} || $opts{'Human-readable'};
+
+my $total = 0;
+for (sort keys %files)
+{
+ print "$_ => $files{$_}\n";
+ $total += $files{$_} unless $human;
+}
+print "\nTotal: $total\n" unless $human;
+
+# subroutines
+
+sub get_options {
+ my %opts;
+ my %opts_to_du = (
+ L => 'dereference',
+ X => 'exclude',
+ h => 'human-readable',
+ H => 'Human-readable',
+ 'm' => 'max-depth',
+ 's' => 'sector-size',
+ l => 'symlink-size',
+ t => 'truncate-readable',
+ );
+
+ getopts('hHLm:t:vX:s:l:', \%opts );
+
+ for my $key ( keys %opts ) {
+ $opts{$key} = 1 unless defined $opts{$key}
+ }
+
+ map { $opts_to_du{$_} => $opts{$_} } keys %opts;
+}
+
+###
+
+sub show_help { # unfortunately, this is never used, for now
+ die "Usage: fdu file1 file2
+fdu: estimate file space usage (using Filesys::DiskUsage)
+
+Options:
+ - displays this messages and exit
+ -v show version and exit
+
+ -L dereference
+ -X PATTERN pattern to exclude
+ -h human-readable format
+ -H human-readable format with powers of 1000
+ -m MAXDEPTH max-depth
+ -s SIZE sector-size
+ -l SYMSIZE symlink-size
+ -t TRUNCATE truncate-readable
+"
+}
+
+###
+
+sub show_version {
+ die"fdu version $VERSION\n";
+}
+
+=head1 AUTHOR
+
+Jose Alves de Castro, E<lt>cog@cpan.orgE<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2004 by Jose Alves de Castro
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
Oops, something went wrong.

0 comments on commit 277a3f0

Please sign in to comment.