Johannes Schauer <jo...@debian.org> writes: > Hi Daniel,
Hello. [...] > as I thought more about this problem I now found a better solution that makes > both of us happy. Consider this diff: > > - opendir(my $dh, $target) or die "Can't opendir($target): $!\n"; > - # Attempt reading the directory thrice. If the third time succeeds, then > it > - # has more entries than just "." and ".." and must thus not be empty. > - readdir $dh; > - readdir $dh; > - die "$target is not empty" if (readdir $dh); > + # check if the directory is empty or contains nothing more than an > + # empty lost+found directory. The latter exists on freshly created > + # ext3 and ext4 partitions. > + # rationale for requiring an empty directory: > https://bugs.debian.org/833525 > + opendir(my $dh, $target) or die "Can't opendir($target): $!"; > + while (my $entry = readdir $dh) { > + # skip the "." and ".." entries > + next if $entry eq "."; > + next if $entry eq ".."; > + # if the entry is a directory named "lost+found" then skip it > + # if it's empty > + if ($entry eq "lost+found" and -d "$target/$entry") { > + opendir(my $dh2, "$target/$entry"); > + # Attempt reading the directory thrice. If the third time > + # succeeds, then it has more entries than just "." and ".." > + # and must thus not be empty. > + readdir $dh2; > + readdir $dh2; > + # rationale for requiring an empty directory: > + # https://bugs.debian.org/833525 > + if (readdir $dh2) { > + die "$target contains a non-empty lost+found directory"; > + } > + closedir($dh2); > + } else { > + die "$target is not empty"; > + } > + } > + closedir($dh); > > The new version now check if either the target directory is empty, or it has > only an empty lost+found directory in it. It will abort in any other case. > This > means that: > > - we still get all the safety and make sure nothing of value will > accidentally > get deleted > > - you don't need to manually rmdir a fresh lost+found directory on a new > partition > > What do you think? It's perfect for me. I already took care of the rmdir in my LVM based provisioning script but I'm sure it will be less confusing for new users. Regards. -- Daniel Dehennin Récupérer ma clef GPG: gpg --recv-keys 0xCC1E9E5B7A6FE2DF Fingerprint: 3E69 014E 5C23 50E8 9ED6 2AAD CC1E 9E5B 7A6F E2DF