forked from josch/mmdebstrap
allow empty lost+found directory in target directory
This commit is contained in:
parent
1730a17286
commit
16d2a4a8d9
1 changed files with 28 additions and 7 deletions
35
mmdebstrap
35
mmdebstrap
|
@ -1616,14 +1616,35 @@ sub main() {
|
||||||
if (!-d $options->{root}) {
|
if (!-d $options->{root}) {
|
||||||
die "$options->{root} exists and is not a directory";
|
die "$options->{root} exists and is not a directory";
|
||||||
}
|
}
|
||||||
opendir(my $dh, $options->{root}) or die "Can't opendir($options->{root}): $!";
|
# check if the directory is empty or contains nothing more than an
|
||||||
# Attempt reading the directory thrice. If the third time succeeds,
|
# empty lost+found directory. The latter exists on freshly created
|
||||||
# then it has more entries than just "." and ".." and must thus not
|
# ext3 and ext4 partitions.
|
||||||
# be empty.
|
|
||||||
readdir $dh;
|
|
||||||
readdir $dh;
|
|
||||||
# rationale for requiring an empty directory: https://bugs.debian.org/833525
|
# rationale for requiring an empty directory: https://bugs.debian.org/833525
|
||||||
die "$options->{root} is not empty" if (readdir $dh);
|
opendir(my $dh, $options->{root}) or die "Can't opendir($options->{root}): $!";
|
||||||
|
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 "$options->{root}/$entry") {
|
||||||
|
opendir(my $dh2, "$options->{root}/$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 "$options->{root} contains a non-empty lost+found directory";
|
||||||
|
}
|
||||||
|
closedir($dh2);
|
||||||
|
} else {
|
||||||
|
die "$options->{root} is not empty";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir($dh);
|
||||||
} else {
|
} else {
|
||||||
make_path($options->{root}) or die "cannot create root: $!";
|
make_path($options->{root}) or die "cannot create root: $!";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue