Lines 401-411
Link Here
|
401 |
next; |
401 |
next; |
402 |
} |
402 |
} |
403 |
|
403 |
|
404 |
# ensure dirs exist, upfront |
404 |
# ensure tmp dir exists, upfront |
405 |
unless (-d $UPDDir) { |
|
|
406 |
dbg("channel: creating $UPDDir"); |
407 |
mkpath([$UPDDir], 0, 0777) or die "fatal: can't create $UPDDir: $!\n"; |
408 |
} |
409 |
unless (-d $UPDTmp) { |
405 |
unless (-d $UPDTmp) { |
410 |
dbg("channel: creating $UPDTmp"); |
406 |
dbg("channel: creating $UPDTmp"); |
411 |
mkpath([$UPDTmp], 0, 0777) or die "fatal: can't create $UPDTmp: $!\n"; |
407 |
mkpath([$UPDTmp], 0, 0777) or die "fatal: can't create $UPDTmp: $!\n"; |
Lines 751-772
Link Here
|
751 |
} |
747 |
} |
752 |
closedir(DIR); |
748 |
closedir(DIR); |
753 |
if (!close(CF)) { |
749 |
if (!close(CF)) { |
754 |
warn "write to $CFFTmp failed! attempting to continue"; |
750 |
die "write to $CFFTmp failed! $!"; # write failed = fatal |
755 |
channel_failed("write to $CFFTmp failed"); |
|
|
756 |
next; |
757 |
} |
751 |
} |
758 |
|
752 |
|
|
|
753 |
# create a test file, in an attempt to mitigate dangers of incomplete |
754 |
# upgrades. If we fail to move this file the same way we expect to with the |
755 |
# "real" upgrade files, there's no point in continuing. (bug 4941) |
756 |
my $testfile = "$UPDTmp/.rename_test.tmp"; |
757 |
my $testtofile = "$UPDDir/.rename_test.tmp"; |
758 |
open(TST, ">".$testfile) or die "write to $testfile failed! $!"; |
759 |
print TST time; |
760 |
close TST or die "close of $testfile failed! $!"; |
761 |
|
759 |
dbg("channel: applying changes to $UPDDir..."); |
762 |
dbg("channel: applying changes to $UPDDir..."); |
760 |
|
763 |
|
761 |
# too late to stop now! At this stage, if there are errors, |
764 |
if (-d $UPDDir) { |
762 |
# we have to attempt to carry on regardless, since we've already |
765 |
if (!rename($testfile, $testtofile)) { |
763 |
# blown away the old ruleset. |
766 |
warn "rename $testfile $testtofile failed: $!"; |
|
|
767 |
unlink ($testfile, $testtofile); |
768 |
die "rename test failed (existing dir), aborting upgrade" |
769 |
} |
764 |
|
770 |
|
765 |
# clean out the "real" update dir, and copy from tmp areas |
771 |
unlink $testtofile; |
766 |
if (!clean_update_dir($UPDDir)) { |
772 |
|
767 |
warn("channel: attempt to rm contents failed, attempting to continue anyway"); |
773 |
# ok that worked, too late to stop now! At this stage, if there are |
|
|
774 |
# errors, we have to attempt to carry on regardless, since we've already |
775 |
# blown away the old ruleset. |
776 |
dbg("channel: point of no return for existing $UPDDir"); |
777 |
|
778 |
# clean out the "real" update dir |
779 |
if (!clean_update_dir($UPDDir)) { |
780 |
warn("channel: attempt to rm contents failed, attempting to continue anyway"); |
781 |
} |
782 |
|
783 |
} else { |
784 |
# create the dir, if it doesn't exist |
785 |
dbg("channel: creating $UPDDir"); |
786 |
if (!mkpath([$UPDDir], 0, 0777)) { |
787 |
rmdir $UPDDir; # be sure it can't be used (bug 4941) |
788 |
die "fatal: can't create $UPDDir: $!\n"; |
789 |
} |
790 |
|
791 |
if (!rename($testfile, $testtofile)) { |
792 |
warn "rename $testfile $testtofile failed: $!"; |
793 |
unlink ($testfile, $testtofile); |
794 |
rmdir $UPDDir; # be sure it can't be used (bug 4941) |
795 |
die "rename test failed (new dir), aborting upgrade" |
796 |
} |
797 |
|
798 |
unlink $testtofile; |
799 |
|
800 |
# ok, that test worked. it's now likely that the .cf's will |
801 |
# similarly be ok to rename, too. Too late to stop from here on |
802 |
dbg("channel: point of no return for new $UPDDir"); |
768 |
} |
803 |
} |
769 |
|
804 |
|
|
|
805 |
# move in the files |
770 |
foreach my $file (@files) { |
806 |
foreach my $file (@files) { |
771 |
rename("$UPDTmp/$file", "$UPDDir/$file") |
807 |
rename("$UPDTmp/$file", "$UPDDir/$file") |
772 |
or warn "rename $UPDTmp/$file $UPDDir/$file failed: $!"; |
808 |
or warn "rename $UPDTmp/$file $UPDDir/$file failed: $!"; |
Lines 1067-1072
Link Here
|
1067 |
|
1103 |
|
1068 |
sub clean_update_dir { |
1104 |
sub clean_update_dir { |
1069 |
my $dir = shift; |
1105 |
my $dir = shift; |
|
|
1106 |
|
1070 |
unless (opendir(DIR, $dir)) { |
1107 |
unless (opendir(DIR, $dir)) { |
1071 |
warn "error: can't readdir $dir: $!\n"; |
1108 |
warn "error: can't readdir $dir: $!\n"; |
1072 |
dbg("channel: attempt to readdir failed, channel failed"); |
1109 |
dbg("channel: attempt to readdir failed, channel failed"); |
Lines 1080-1085
Link Here
|
1080 |
$file = $1; |
1117 |
$file = $1; |
1081 |
if (!unlink "$dir/$file") { |
1118 |
if (!unlink "$dir/$file") { |
1082 |
warn "error: can't remove file $dir/$file: $!\n"; |
1119 |
warn "error: can't remove file $dir/$file: $!\n"; |
|
|
1120 |
closedir(DIR); |
1083 |
return 0; |
1121 |
return 0; |
1084 |
} |
1122 |
} |
1085 |
} |
1123 |
} |