mirror of
https://codeberg.org/h3xx/simplify_static_dir
synced 2024-08-14 23:57:24 +00:00
4d4edd5e9d
Fixes accidental inclusion of test instrumentation into the all-in-one script.
46 lines
1 KiB
Perl
46 lines
1 KiB
Perl
package Directory::Simplify::Instruction::Hardlink;
|
|
# vi: et sts=4 sw=4 ts=4
|
|
use strict;
|
|
use warnings;
|
|
use overload '""' => 'as_string';
|
|
|
|
# :squash-remove-start:
|
|
require Directory::Simplify::Utils;
|
|
# :squash-remove-end:
|
|
|
|
sub new {
|
|
my $class = shift;
|
|
return bless {
|
|
freed => 0,
|
|
@_,
|
|
}, $class;
|
|
}
|
|
|
|
sub run {
|
|
my $self = shift;
|
|
# hard link the files
|
|
|
|
unless (unlink $self->{target}->{name}) {
|
|
die "Failed to remove file `$self->{target}->{name}': $!\n";
|
|
}
|
|
unless (link $self->{source}->{name}, $self->{target}->{name}) {
|
|
die "Failed to hard link `$self->{source}->{name}' => `$self->{target}->{name}': $!";
|
|
}
|
|
# bookkeeping
|
|
++$self->{source}->{nlink};
|
|
if (--$self->{target}->{nlink} == 0) {
|
|
$self->{freed} = $self->{target}->{size};
|
|
}
|
|
}
|
|
|
|
sub bytes_freed {
|
|
my $self = shift;
|
|
return $self->{freed};
|
|
}
|
|
|
|
sub as_string {
|
|
my $self = shift;
|
|
return sprintf 'ln -sf %s %s', Directory::Simplify::Utils::shell_quote($self->{source}->{name}, $self->{target}->{name});
|
|
}
|
|
|
|
1;
|