OSDN Git Service

BugTrack-plugin/406
[fswiki/fswiki.git] / update.pl
1 #####################################################################
2 #
3 # ????????????????????X????
4 #
5 #####################################################################
6 use File::Path;
7 use File::Copy;
8
9 my $date = $ARGV[0];
10 my $dir  = $ARGV[1];
11
12 if($date eq "" || !($date =~ /^[1-2][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9]$/)){
13         &print_help();
14         exit;
15 }
16
17 $date =~ s/-//g;
18 $date = int($date);
19
20 if($dir ne ""){
21         if(-e $dir){
22                 print "$dir????????????B\n";
23                 rmtree($dir);
24         }
25         if(-e "$dir.zip"){
26                 print "$dir.zip??????B\n";
27                 unlink "$dir.zip";
28         }
29 }
30
31 $find_flag = 0;
32 &search_dir($date,".",$dir);
33
34 if($dir ne ""){
35         if($find_flag == 1){
36                 print "??t??????????\n";
37                 system("zip $dir.zip -r $dir");
38         }
39
40 }
41
42 #====================================================================
43 # ?????\8e¦
44 #====================================================================
45 sub print_help {
46         print "????????????????????A????????????\n";
47         print "\n";
48         print "perl update.pl YYYY-MM-DD [???f??????]\n";
49         print "  ?????????????Y???????????\8e¦???????B\n";
50 }
51
52 #====================================================================
53 # ?????????
54 #====================================================================
55 sub search_dir {
56         my $date = shift;
57         my $dir  = shift;
58         my $to   = shift;
59         my @list = ();
60         
61         opendir(DIR,$dir);
62         while(my $entry = readdir(DIR)){
63                 if(index($entry,".")!=0 && $entry ne "CVS"){
64                         if($dir eq "." && ($entry eq "log" || $entry eq "backup" || $entry eq "attach" || $entry eq "pdf")){
65                                 
66                         } elsif($dir eq "./data" && $entry ne "FrontPage" && $entry ne "Help"){
67                                 
68                                 
69                         } else {
70                                 push(@list,"$dir/$entry");
71                         }
72                 }
73         }
74         closedir(DIR);
75         
76         foreach my $entry (@list){
77                 if(-d $entry){
78                         &search_dir($date,$entry,$to);
79                 } else {
80                         # ??????????????
81                         my @status = stat($entry);
82                         my ($sec,$min,$hour,$mday,$mon,$year)=localtime($status[9]);
83                         my $date_str = sprintf("%04d%02d%02d",$year+1900,$mon+1,$mday);
84                         
85                         if(int($date_str) >= $date){
86                                 print $entry."\n";
87                                 # ?????????????????????????
88                                 if($to ne ""){
89                                         # ???????????????
90                                         my $path = $dir;
91                                         $path =~ s/^\.//;
92                                         my $copydir = "$to$path";
93                                         unless(-e $copydir){
94                                                 mkpath($copydir) or die "$copydir????\8e¸??????";
95                                         }
96                                         
97                                         my $name = $entry;
98                                         $name =~ s/^(.*?\/)*//g;
99                                         copy($entry,"$copydir/$name") or die "$copydir/$name?????\8e¸??????";
100                                         
101                                         $find_flag = 1;
102                                 }
103                         }
104                 }
105         }
106 }