fixed file handle conflict

This commit is contained in:
Christoph Klaffl 2025-08-12 14:19:47 +02:00
parent 940a84e21f
commit efd52f416d
No known key found for this signature in database
GPG Key ID: 8FC1D76EED4970D2
1 changed files with 7 additions and 8 deletions

15
sanoid
View File

@ -1084,11 +1084,9 @@ sub init {
@datasets = getchilddatasets($config{$section}{'path'}); @datasets = getchilddatasets($config{$section}{'path'});
DATASETS: foreach my $dataset(@datasets) { DATASETS: foreach my $dataset(@datasets) {
if (! @cachedatasets) { if (! @cachedatasets) {
push (@updatedatasets, $dataset); push (@updatedatasets, "$dataset\n");
} }
chomp $dataset;
if ($zfsRecursive) { if ($zfsRecursive) {
# don't try to take the snapshot ourself, recursive zfs snapshot will take care of that # don't try to take the snapshot ourself, recursive zfs snapshot will take care of that
$config{$dataset}{'autosnap'} = 0; $config{$dataset}{'autosnap'} = 0;
@ -1691,7 +1689,7 @@ sub getchilddatasets {
my $getchildrencmd = "$mysudocmd $zfs list -o name -t filesystem,volume -Hr $fs |"; my $getchildrencmd = "$mysudocmd $zfs list -o name -t filesystem,volume -Hr $fs |";
if ($args{'debug'}) { print "DEBUG: getting list of child datasets on $fs using $getchildrencmd...\n"; } if ($args{'debug'}) { print "DEBUG: getting list of child datasets on $fs using $getchildrencmd...\n"; }
open FH, $getchildrencmd; open FH, $getchildrencmd;
my @children = <FH>; chomp( my @children = <FH> );
close FH; close FH;
# parent dataset is the first element # parent dataset is the first element
@ -1781,25 +1779,26 @@ sub addcachedsnapshots {
copy($cache, "$cache.tmp") or die "Could not copy to $cache.tmp!\n"; copy($cache, "$cache.tmp") or die "Could not copy to $cache.tmp!\n";
open FH, ">> $cache.tmp" or die "Could not write to $cache.tmp!\n"; open my $fh, ">> $cache.tmp" or die "Could not write to $cache.tmp!\n";
while((my $snap, my $details) = each(%taken)) { while((my $snap, my $details) = each(%taken)) {
my @parts = split("@", $snap, 2); my @parts = split("@", $snap, 2);
my $suffix = $parts[1] . "\tcreation\t" . $details->{time} . "\t-"; my $suffix = $parts[1] . "\tcreation\t" . $details->{time} . "\t-";
my $dataset = $parts[0]; my $dataset = $parts[0];
print FH "${dataset}\@${suffix}\n"; print $fh "${dataset}\@${suffix}\n";
if ($details->{recursive}) { if ($details->{recursive}) {
my @datasets = getchilddatasets($dataset); my @datasets = getchilddatasets($dataset);
foreach my $dataset(@datasets) { foreach my $dataset(@datasets) {
print FH "${dataset}\@${suffix}\n"; print "${dataset}\@${suffix}\n";
print $fh "${dataset}\@${suffix}\n";
} }
} }
} }
close FH; close $fh;
# preserve mtime of cache for expire check # preserve mtime of cache for expire check
my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks) = stat($cache); my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks) = stat($cache);