Fix issue where mixed readonly/read-write dirs didn't hard link

This commit is contained in:
Dan Church 2023-07-20 17:36:02 -05:00
parent 76da187807
commit 8fdf3069ba
Signed by: h3xx
GPG key ID: EA2BF379CD2CDBD0
2 changed files with 14 additions and 3 deletions

View file

@ -14,6 +14,11 @@ All notable changes to this project will be documented in this file.
- Omit output of progress bar unless -v flag is present
- Add thousands separator commas to output
### Fixed
- Fixed issue where removable files wouldn't be linked with non-removable
files.
## [3.0.0]
### Changed

View file

@ -145,17 +145,23 @@ sub instructions {
my ($oldest_entry) = _oldest_mtime(@{$bucket});
# Limit link/unlink operations to files in non-readonly directories
my @non_readonly;
my (@non_readonly, @readonly);
foreach my $entry (@{$bucket}) {
unless (-w $entry->{dirname}) {
carp "Warning: $entry->{name} not able to be unlinked!";
push @readonly, $entry;
} else {
push @non_readonly, $entry;
}
push @non_readonly, $entry;
}
# Of the linkable files, find the file most embedded in the file system
my @to_link = _more_linked(@non_readonly);
my $most_linked_entry = shift @to_link;
@readonly = _more_linked(@readonly);
# Select a basis for linkage, either the most-linked readonly entry (if
# any) or the most linked of the read-write entries.
my $most_linked_entry = shift @readonly // shift @to_link;
foreach my $entry (@to_link) {
# XXX there shouldn't be a need to update entries' link counts,
# since this generates all the instructions at once