From 8fdf3069ba08c5ffc10aa1a71f27e39f82366c65 Mon Sep 17 00:00:00 2001 From: Dan Church Date: Thu, 20 Jul 2023 17:36:02 -0500 Subject: [PATCH] Fix issue where mixed readonly/read-write dirs didn't hard link --- CHANGELOG.md | 5 +++++ lib/Directory/Simplify/Instruction/Generator.pm | 12 +++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14592ef..ad8ebb4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/Directory/Simplify/Instruction/Generator.pm b/lib/Directory/Simplify/Instruction/Generator.pm index 85cd1ef..4369df3 100644 --- a/lib/Directory/Simplify/Instruction/Generator.pm +++ b/lib/Directory/Simplify/Instruction/Generator.pm @@ -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