/[pub]/suikawiki/script/bin/difffl.pl
Suika

Contents of /suikawiki/script/bin/difffl.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations) (download)
Sat Mar 13 03:07:46 2004 UTC (20 years, 2 months ago) by wakaba
Branch: MAIN
CVS Tags: suikawiki3-redirect, release-3-0-0, HEAD
Branch point for: paragraph-200404, helowiki, helowiki-2005
File MIME type: text/plain
New

1 #!/usr/bin/perl
2 use strict;
3 use File::Find;
4 use Getopt::Long;
5 use Pod::Usage;
6 our $VERSION = do{my @r=(q$Revision: 1.2 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
7
8 my $dir = q(.);
9 my $filter = q/\.txt$/;
10 my $listfile;
11 my $oldlistfile;
12 my $newlistfile;
13
14 GetOptions (
15 q(target-dir=s) => \$dir,
16 q(target-filter=s) => \$filter,
17 q(list-file=s) => \$listfile,
18 q(removed-list-file=s) => \$oldlistfile,
19 q(added-list-file=s) => \$newlistfile,
20 q(h|help|?) => sub {
21 pod2usage (-exitstatus => 0, -verbose => 2);
22 },
23 ) or pod2usage (-exitstatus => 2, -verbose => 1);
24 pod2usage (-exitstatus => 2, -verbose => 1)
25 unless $listfile and $oldlistfile and $newlistfile;
26
27 my %newlist;
28 find (sub {
29 if (/$filter/o) {
30 $newlist{$File::Find::name} = 1;
31 }
32 }, $dir);
33 my %list = %newlist;
34
35 my %oldlist;
36 if (open my $oldlist, '<', $listfile) {
37 while (<$oldlist>) {
38 tr/\x0A\x0D//d;
39 $oldlist{$_} = 1;
40 }
41 } else {
42 warn "$0: $listfile: $!";
43 }
44
45 delete $newlist{$_} for keys %oldlist;
46 delete $oldlist{$_} for keys %list;
47
48 {
49 open my $list, '>', $listfile or die "$0: $listfile: $!";
50 print $list $_, "\n" for sort keys %list;
51 }
52
53 {
54 open my $newlist, '>', $newlistfile or die "$0: $newlistfile: $!";
55 print $newlist $_, "\n" for sort keys %newlist;
56 }
57 {
58 open my $oldlist, '>', $oldlistfile or die "$0: $oldlistfile: $!";
59 print $oldlist $_, "\n" for sort keys %oldlist;
60 }
61
62 =head1 NAME
63
64 difffl.pl - Find difference between previous snapshot of and current file list
65
66 =head1 SYNOPSIS
67
68 perl difffl.pl --list-file=file --added-list-file=file --removed-list-file=file [OPTIONS]
69
70 =head1 DESCRIPTION
71
72 Find difference between previous snapshot of file list and current file
73 list of certain directory (and its sub-directories). Lists for removed files
74 (ie. files found in previous list but does not in current list) and
75 added files (ie. files not in previous list but in current list) are
76 outputed as separate files and file list snapshot file is updated.
77
78 =head1 OPTIONS
79
80 =over 4
81
82 =item --added-list-file=file (REQUIRED)
83
84 Path to added-file-list file.
85
86 =item --help
87
88 Show help message.
89
90 =item --list-file=file (REQUIRED)
91
92 Path to file-list file. This file should contain previous snapshot
93 of file-list for target directory and is updated to latest file-list.
94
95 =item --removed-list-file=file (REQUIRED)
96
97 Path to removed-file-list file.
98
99 =item --target-dir=directory (Default: C<.>)
100
101 Path to directory from which files are to be listed.
102
103 =item --target-filter=regex (Default: C<\.txt$>)
104
105 Regular expression in Perl format, that filters files found in target
106 directory by their full path name.
107
108 =back
109
110 =head1 LICENSE
111
112 Copyright 2004 Wakaba <w@suika.fam.cx>. All rights reserved.
113
114 This program is free software; you can redistribute it and/or
115 modify it under the same terms as Perl itself.
116
117 =cut
118
119 1; # $Date: 2004/03/11 08:06:26 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24