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,9 +3911,12 @@ 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 {
# 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: # rationale for requiring an empty directory:
# https://bugs.debian.org/833525 # https://bugs.debian.org/833525
opendir(my $dh, $options->{root}) opendir(my $dh, $options->{root})
@ -3922,13 +3925,14 @@ sub main() {
# skip the "." and ".." entries # skip the "." and ".." entries
next if $entry eq "."; next if $entry eq ".";
next if $entry eq ".."; next if $entry eq "..";
# if the entry is a directory named "lost+found" then skip it # if the entry is a directory named "lost+found" then skip
# if it's empty # it, if it's empty
if ($entry eq "lost+found" and -d "$options->{root}/$entry") { if ($entry eq "lost+found"
and -d "$options->{root}/$entry") {
opendir(my $dh2, "$options->{root}/$entry"); opendir(my $dh2, "$options->{root}/$entry");
# Attempt reading the directory thrice. If the third time # Attempt reading the directory thrice. If the third
# succeeds, then it has more entries than just "." and ".." # time succeeds, then it has more entries than just "."
# and must thus not be empty. # and ".." and must thus not be empty.
readdir $dh2; readdir $dh2;
readdir $dh2; readdir $dh2;
# rationale for requiring an empty directory: # rationale for requiring an empty directory:
@ -3943,6 +3947,7 @@ sub main() {
} }
} }
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 };