Skip to content
This repository has been archived by the owner on Jan 29, 2019. It is now read-only.

Allow hard/soft/ref - linking to the original image, instead of copy #76

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 50 additions & 3 deletions fgallery
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ my $workers = 0;
my $sRGB = 1;
my $indexUrl = undef;
my @capmethods = ("txt", "xmp", "exif");
my $copy_method = 'copy';
my @copy_method_ok = qw(copy hard sym ref);


# support functions
Expand Down Expand Up @@ -332,6 +334,16 @@ sub parse_cap
return @capmethods;
}

sub parse_copy_method
{
my $opt = shift;
my $value = shift || 'hard'; # default to hard link
if (!isin($value, @copy_method_ok)) {
fatal("invalid image copy method: $value");
}
return $value;
}

sub print_version
{
print("fgallery $VERSION\n");
Expand Down Expand Up @@ -361,6 +373,7 @@ sub print_help
--no-sRGB do not remap preview/thumbnail color profiles to sRGB
--quality Q preview image quality (0-100, currently: $imgq)
--index url specify the URL location for the index/back button
--link-orig change images copy method (hard,sym,ref or copy)
});
exit(shift);
}
Expand Down Expand Up @@ -388,7 +401,9 @@ my ($ret, @ARGS) = GetOptions(
'min-thumb=s' => sub { @minthumb = parse_wh(@_); },
'no-sRGB' => sub { $sRGB = 0; },
'quality=i' => sub { $imgq = parse_int($_[0], $_[1], 0, 100); },
'index=s' => sub { $indexUrl = $_[1]; });
'index=s' => sub { $indexUrl = $_[1]; },
'link-orig:s' => sub { $copy_method = parse_copy_method($_[0], $_[1]); },
);

if(@ARGV < 2 || @ARGV > 3 || !$ret) {
print_help(2);
Expand Down Expand Up @@ -629,6 +644,39 @@ foreach my $props(@aprops)
}
$amp /= @files;

sub copy_source_file
{
my $file = shift;
my $fout = shift;

my @options;
push @options, '-L';

my %option = (
hard => '--link',
sym => '--symbolic-link',
ref => '--reflink',
);
if (defined($option{$copy_method}))
{
push @options, $option{$copy_method};
}

# symlinks need the right dest path - simplest is to give them an abs path
if ($copy_method eq 'sym')
{
$file = rel2abs($file);
}

sys('cp', @options, $file, $fout);

# these copy methods end up with a new inode
if ($copy_method eq 'copy' || $copy_method eq 'ref')
{
chmod(0600, $fout);
}
}

# 2nd pass: produce output files
sub process_img
{
Expand All @@ -649,8 +697,7 @@ sub process_img
progress::status($fbase);

# copy source file
sys('cp', '-L', $file, $fout);
chmod(0600, $fout);
copy_source_file($file,$fout);

# apply lossless transforms
if(!$keeporig)
Expand Down
6 changes: 6 additions & 0 deletions fgallery.1
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ Set the JPEG quality of the preview images to
The default is 90.
.It Fl -index Ar URL
Specify the URL location for the index and back buttons.
.It Fl -link-orig[=TYPE]
Change the method used to copy the original images. If this option is
not given, the method defaults to "copy". If the type is not specified
it sets the method to "hard". Otherwise the type must be one of "copy",
"hard", "soft" or "ref" - for normal copy, hard-linking, soft-linking or
ref-linking respectively.
.El
.Sh SEE ALSO
.Xr ImageMagick 1 ,
Expand Down