add --skip check/empty

This commit is contained in:
Johannes 'josch' Schauer 2020-05-01 07:39:52 +02:00
parent 1b380e4513
commit 4ea784c1bc
Signed by untrusted user: josch
GPG key ID: F2CBA5C78FBD83E1

View file

@ -3911,38 +3911,43 @@ sub main() {
if (!-d $options->{root}) { if (!-d $options->{root}) {
error "$options->{root} exists and is not a directory"; error "$options->{root} exists and is not a directory";
} }
# check if the directory is empty or contains nothing more than an if (any { $_ eq 'check/empty' } @{ $options->{skip} }) {
# empty lost+found directory. The latter exists on freshly created info "skipping check/empty as requested";
# ext3 and ext4 partitions. } else {
# rationale for requiring an empty directory: # check if the directory is empty or contains nothing more than
# https://bugs.debian.org/833525 # an empty lost+found directory. The latter exists on freshly
opendir(my $dh, $options->{root}) # created ext3 and ext4 partitions.
or error "Can't opendir($options->{root}): $!"; # rationale for requiring an empty directory:
while (my $entry = readdir $dh) { # https://bugs.debian.org/833525
# skip the "." and ".." entries opendir(my $dh, $options->{root})
next if $entry eq "."; or error "Can't opendir($options->{root}): $!";
next if $entry eq ".."; while (my $entry = readdir $dh) {
# if the entry is a directory named "lost+found" then skip it # skip the "." and ".." entries
# if it's empty next if $entry eq ".";
if ($entry eq "lost+found" and -d "$options->{root}/$entry") { next if $entry eq "..";
opendir(my $dh2, "$options->{root}/$entry"); # if the entry is a directory named "lost+found" then skip
# Attempt reading the directory thrice. If the third time # it, if it's empty
# succeeds, then it has more entries than just "." and ".." if ($entry eq "lost+found"
# and must thus not be empty. and -d "$options->{root}/$entry") {
readdir $dh2; opendir(my $dh2, "$options->{root}/$entry");
readdir $dh2; # Attempt reading the directory thrice. If the third
# rationale for requiring an empty directory: # time succeeds, then it has more entries than just "."
# https://bugs.debian.org/833525 # and ".." and must thus not be empty.
if (readdir $dh2) { readdir $dh2;
error "$options->{root} contains a non-empty" readdir $dh2;
. " lost+found directory"; # rationale for requiring an empty directory:
# https://bugs.debian.org/833525
if (readdir $dh2) {
error "$options->{root} contains a non-empty"
. " lost+found directory";
}
closedir($dh2);
} else {
error "$options->{root} is not empty";
} }
closedir($dh2);
} else {
error "$options->{root} is not empty";
} }
closedir($dh);
} }
closedir($dh);
} else { } else {
my $num_created = make_path "$options->{root}", my $num_created = make_path "$options->{root}",
{ error => \my $err }; { error => \my $err };