Merge from mainline.
[official-gcc.git] / libjava / classpath / scripts / patches.pl
blob57f134d920166376730427443eae19d00fc6a08d
1 #!/usr/bin/perl -w
2 # Purpose is to move patches from upload directory to
3 # public patches directory. Any file not matching the correct
4 # pattern is deleted. Any patch file without a README and the
5 # file was last modified more than 120 minutes ago is deleted.
6 # Any README file without a patch file which was last modified
7 # more than 120 minutes ago is deleted.
9 # notes to self: as long as this runs as root do not worry
10 # about quota problems or disk space
12 use strict;
14 my ($upload_dir) = "/home/ftp/classpath/incoming";
15 my ($public_dir) = "/home/ftp/classpath/pub/patches";
16 my ($user) = "classpath";
17 my ($group) = "classpath";
18 my ($mode_dir) = "775";
19 my ($mode_file) = "664";
20 my (@patches) = ();
22 use vars qw($upload_dir $public_dir @patches $user $group
23 $mode_dir $mode_file);
25 # main
27 @patches = &getPatches();
28 &movePatches(@patches);
31 #---------------------------------------------------------------
32 # Purpose: To remove files not matching the correct pattern.
33 # To remove README files without patches (last modified greater
34 # than 2 hours). To remove patches without README files (last
35 # modified greater than 2 hours).
36 #---------------------------------------------------------------
37 sub getPatches
39 my (@patches) = ();
40 my (@entries) = ();
41 my (%maybe) = ();
42 my ($entry, $debug, $prefix, $junk, $file, $patch, $readme) = "";
43 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime,
44 $mtime, $ctime, $blksize, $blocks) = "";
46 $debug = 1;
48 opendir(INCOMING, "$upload_dir") || die "could not open $upload_dir\n";
49 @entries = grep( !/^\.\S+/, readdir(INCOMING)); # no .*
50 closedir(INCOMING);
51 foreach $entry (sort @entries)
53 if (($entry eq ".") || ($entry eq "..")) { next; }
54 if (-d "$upload_dir/$entry")
56 print "Directory: $upload_dir/$entry/\n";
58 elsif (-e "$upload_dir/$entry")
60 if ($entry eq ".message") { next; }
61 if ($entry eq "README") { next; }
62 if ($entry !~ /^\w+-\d\d\d\d\d\d-\d+\.patch\.(gz|README)$/)
64 print "REGEX FAILED: $entry\n";
65 unlink("$upload_dir/$entry");
67 else
69 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,
70 $ctime,$blksize,$blocks) = stat("$upload_dir/$entry");
71 if ($size > 512000)
73 print "LARGE PATCH: $entry\n";
74 unlink("$upload_dir/$entry");
76 else
78 ($prefix,$junk) = split(/(\.gz|\.README)/, $entry, 2);
79 $maybe{$prefix} += 1;
85 foreach $entry (keys(%maybe))
87 if ($maybe{$entry} == 2)
89 $patch = "$entry.gz";
90 $readme = "$entry.README";
92 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,
93 $ctime,$blksize,$blocks) = stat($patch);
94 if (time-$mtime > 900)
96 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,
97 $ctime,$blksize,$blocks) = stat($readme);
98 if (time-$mtime > 900)
100 $patches[$#patches+1] = $entry;
104 else
106 if (-e "$upload_dir/$entry.gz")
108 unlink("$upload_dir/$entry.gz");
109 print "STALE PATCH: $entry.gz\n";
111 elsif (-e "$upload_dir/$entry.README")
113 unlink("$upload_dir/$entry.README");
114 print "STALE README: $entry.README\n";
118 return (@patches);
121 #---------------------------------------------------------------
122 # Purpose: To move the patches to the proper directory and set
123 # the permissions correctly.
124 #---------------------------------------------------------------
125 sub movePatches
127 my (@patches) = @_;
128 my ($patch) = "";
129 my ($fail) = 0;
131 if (!(-d "$public_dir"))
133 system("mkdir -p $public_dir");
134 system("chown $user.$group $public_dir");
135 system("chmod $mode_dir $public_dir");
137 foreach $patch (@patches)
139 if (-e "$public_dir/$patch.gz")
141 print "Patch exists: $public_dir/$patch.gz\n";
142 $fail = 1;
144 if (-e "$public_dir/$patch.README")
146 print "README exists: $public_dir/$patch.README\n";
147 $fail = 1;
149 if ($fail == 0)
151 system("mv $upload_dir/$patch.gz $public_dir/$patch.gz");
152 system("mv $upload_dir/$patch.README $public_dir/$patch.README");
153 system("chown $user.$group $public_dir/*");
154 system("chmod $mode_file $public_dir/*");
155 open(MAIL, "|mail -s \"Classpath: $patch uploaded\" core\@classpath.org") || die "could not open mail\n";
156 print MAIL "GNU Classpath FTP Maintenance\n";
157 print MAIL "\n";
158 print MAIL "Added Files:\n";
159 print MAIL "ftp://ftp.classpath.org/pub/patches/$patch.gz\n";
160 print MAIL "ftp://ftp.classpath.org/pub/patches/$patch.README\n\n";
161 close(MAIL);