зеркало из https://github.com/mozilla/pjs.git
Use homegrown mozLock package instead of flock() as some platforms and/or filesystems do not implement flock (correctly)).
This commit is contained in:
Родитель
776bb72371
Коммит
b0e1bc4a07
|
@ -1,9 +1,9 @@
|
|||
#!/perl
|
||||
|
||||
use File::Path;
|
||||
use Fcntl qw(:DEFAULT :flock);
|
||||
use Getopt::Std;
|
||||
use IO::File;
|
||||
use mozLock;
|
||||
|
||||
getopts("l");
|
||||
|
||||
|
@ -33,37 +33,38 @@ else {
|
|||
}
|
||||
|
||||
my $lockfile = "$installedChromeFile.lck";
|
||||
my $lockhandle = new IO::File;
|
||||
|
||||
if (!$nofilelocks) {
|
||||
open($lockhandle,">$lockfile") ||
|
||||
die("WARNING: Could not create lockfile for $lockfile. Exiting.\n");
|
||||
flock($lockhandle, LOCK_EX);
|
||||
}
|
||||
my $err;
|
||||
|
||||
mozLock($lockfile) if (!$nofilelocks);
|
||||
$err = 0;
|
||||
if (open(FILE, "<$installedChromeFile")) {
|
||||
while (<FILE>) {
|
||||
chomp;
|
||||
if ($_ =~ $line) {
|
||||
# line already appears in installed-chrome.txt file
|
||||
# just update the mod date
|
||||
close(FILE) || die "error: can't close $installedChromeFile: $!";
|
||||
if (!$nofilelocks) {
|
||||
unlink($lockfile);
|
||||
flock($lockhandle, LOCK_UN);
|
||||
close(FILE) or $err = 1;
|
||||
if ($err) {
|
||||
mozUnlock($lockfile) if (!$nofilelocks);
|
||||
die "error: can't close $installedChromeFile: $!";
|
||||
}
|
||||
my $now = time;
|
||||
utime($now, $now, $installedChromeFile) || die "couldn't touch $installedChromeFile";
|
||||
utime($now, $now, $installedChromeFile) or $err = 1;
|
||||
mozUnlock($lockfile) if (!$nofilelocks);
|
||||
if ($err) {
|
||||
die "couldn't touch $installedChromeFile";
|
||||
}
|
||||
print "+++ updating chrome $installedChromeFile\n+++\t$line\n";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
close(FILE) || die "error: can't close $installedChromeFile: $!";
|
||||
}
|
||||
if (!$nofilelocks) {
|
||||
unlink($lockfile);
|
||||
flock($lockhandle, LOCK_UN);
|
||||
close(FILE) or $err = 1;
|
||||
if ($err) {
|
||||
mozUnlock($lockfile) if (!$nofilelocks);
|
||||
die "error: can't close $installedChromeFile: $!";
|
||||
}
|
||||
}
|
||||
mozUnlock($lockfile) if (!$nofilelocks);
|
||||
|
||||
my $dir = $installedChromeFile;
|
||||
if ("$dir" =~ /([\w\d.\-\\\/]+)[\\\/]([\w\d.\-]+)/) {
|
||||
|
@ -71,17 +72,18 @@ if ("$dir" =~ /([\w\d.\-\\\/]+)[\\\/]([\w\d.\-]+)/) {
|
|||
}
|
||||
mkpath($dir, 0, 0755);
|
||||
|
||||
if (!$nofilelocks) {
|
||||
open($lockhandle,">$lockfile") ||
|
||||
die("WARNING: Could not create lockfile for $lockfile. Exiting.\n");
|
||||
flock($lockhandle, LOCK_EX);
|
||||
mozLock($lockfile) if (!$nofilelocks);
|
||||
$err = 0;
|
||||
open(FILE, ">>$installedChromeFile") or $err = 1;
|
||||
if ($err) {
|
||||
mozUnlock($lockfile) if (!$nofilelocks);
|
||||
die "can't open $installedChromeFile: $!";
|
||||
}
|
||||
open(FILE, ">>$installedChromeFile") || die "can't open $installedChromeFile: $!";
|
||||
print FILE "$line\n";
|
||||
close(FILE) || die "error: can't close $installedChromeFile: $!";
|
||||
if (!$nofilelocks) {
|
||||
unlink($lockfile);
|
||||
flock($lockhandle, LOCK_UN);
|
||||
close(FILE) or $err = 1;
|
||||
mozUnlock($lockfile) if (!$nofilelocks);
|
||||
if ($err) {
|
||||
die "error: can't close $installedChromeFile: $!";
|
||||
}
|
||||
print "+++ adding chrome $installedChromeFile\n+++\t$line\n";
|
||||
|
||||
|
|
|
@ -11,8 +11,8 @@ use Time::localtime;
|
|||
use Cwd;
|
||||
use File::Copy;
|
||||
use File::Path;
|
||||
use Fcntl qw(:DEFAULT :flock);
|
||||
use IO::File;
|
||||
use mozLock;
|
||||
|
||||
my $objdir = getcwd;
|
||||
|
||||
|
@ -64,14 +64,11 @@ if ($verbose) {
|
|||
. "\n";
|
||||
}
|
||||
|
||||
sub zipErrorCheck($$$)
|
||||
sub zipErrorCheck($$)
|
||||
{
|
||||
my ($err,$lockfile,$lockhandle) = @_;
|
||||
my ($err,$lockfile) = @_;
|
||||
return if ($err == 0 || $err == 12);
|
||||
if (!$nofilelocks) {
|
||||
unlink($lockfile);
|
||||
flock($lockhandle, LOCK_UN);
|
||||
}
|
||||
mozUnlock($lockfile) if (!$nofilelocks);
|
||||
die ("Error invoking zip: $err");
|
||||
}
|
||||
|
||||
|
@ -90,12 +87,8 @@ sub JarIt
|
|||
#print "cd $destPath/$jarfile\n";
|
||||
|
||||
my $lockfile = "../$jarfile.lck";
|
||||
my $lockhandle = new IO::File;
|
||||
if (!$nofilelocks) {
|
||||
open($lockhandle,">$lockfile") ||
|
||||
die("WARNING: Could not create lockfile for $lockfile. Exiting.\n");
|
||||
flock($lockhandle, LOCK_EX);
|
||||
}
|
||||
|
||||
mozLock($lockfile) if (!$nofilelocks);
|
||||
|
||||
if (!($args eq "")) {
|
||||
my $cwd = getcwd;
|
||||
|
@ -115,13 +108,13 @@ sub JarIt
|
|||
#print "Length of subargs: " . length($subargs) . "\n";
|
||||
system("zip $zipmoveopt -u ../$jarfile.jar $subargs") == 0 or
|
||||
$err = $? >> 8;
|
||||
zipErrorCheck($err,$lockfile,$lockhandle);
|
||||
zipErrorCheck($err,$lockfile);
|
||||
}
|
||||
#print "Length of args: " . length($args) . "\n";
|
||||
#print "zip $zipmoveopt -u ../$jarfile.jar $args\n";
|
||||
system("zip $zipmoveopt -u ../$jarfile.jar $args") == 0 or
|
||||
$err = $? >> 8;
|
||||
zipErrorCheck($err,$lockfile,$lockhandle);
|
||||
zipErrorCheck($err,$lockfile);
|
||||
}
|
||||
|
||||
if (!($overrides eq "")) {
|
||||
|
@ -139,17 +132,14 @@ sub JarIt
|
|||
#print "Length of subargs: " . length($subargs) . "\n";
|
||||
system("zip $zipmoveopt ../$jarfile.jar $subargs") == 0 or
|
||||
$err = $? >> 8;
|
||||
zipErrorCheck($err,$lockfile,$lockhandle);
|
||||
zipErrorCheck($err,$lockfile);
|
||||
}
|
||||
#print "zip $zipmoveopt ../$jarfile.jar $overrides\n";
|
||||
system("zip $zipmoveopt ../$jarfile.jar $overrides\n") == 0 or
|
||||
$err = $? >> 8;
|
||||
zipErrorCheck($err,$lockfile,$lockhandle);
|
||||
}
|
||||
if (!$nofilelocks) {
|
||||
unlink("$lockfile");
|
||||
flock($lockhandle, LOCK_UN);
|
||||
zipErrorCheck($err,$lockfile);
|
||||
}
|
||||
mozUnlock($lockfile) if (!$nofilelocks);
|
||||
chdir($oldDir);
|
||||
#print "cd $oldDir\n";
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче