From 1a7507c6bccc249b2d2dbd7ed5dff978ed885d53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uro=C5=A1=20Golja?= Date: Sat, 12 Nov 2016 12:25:41 +0100 Subject: [PATCH] This apparently works. The trick was to use the $symlink_dir path as the basepath (for the abs2rel function), and not $symlink. Kinda makes sense, really. --- symlink-images-by-aspect-ratio.pl | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/symlink-images-by-aspect-ratio.pl b/symlink-images-by-aspect-ratio.pl index 4bd097c..d83a46a 100755 --- a/symlink-images-by-aspect-ratio.pl +++ b/symlink-images-by-aspect-ratio.pl @@ -5,7 +5,6 @@ use strict; use File::Find::Wanted; use File::Basename; -use Cwd qw/getcwd abs_path/; use File::Spec; use File::Spec::Functions; use Image::EXIF; @@ -39,7 +38,7 @@ if (! @list) { exit 0 } -# get their information +# extract the EXIF data from the files and build a hash from all that stuff my $count = 0; # how many files? my $errors = 0; # how many errors? my $ars = {}; # a hashref that holds all the encountered aspect rations and their number of occurence @@ -115,15 +114,19 @@ foreach my $f (keys %$files) { # Construct the symlink path. TODO: use something smarter than just string # concatenation. - my $ar = $files->{$f}->{ar}; - my $symlink_name = basename($f); - my $symlink_dir = abs_path($conf->{dst_dir}) . "/" . $ar; - my $symlink_path = File::Spec->abs2rel($symlink_dir . "/" . $symlink_name); - - my $f_path = File::Spec->abs2rel(abs_path($f)); + print "\$f='$f' "; + my $ar = $files->{$f}->{ar}; print "\$ar='$ar' "; + my $symlink_dir = $conf->{dst_dir} . "/" . $ar; print "\$symlink_dir='$symlink_dir' "; + my $symlink = $symlink_dir . "/" . basename($f); print "\$symlink='$symlink' "; + my $symlink_dst = File::Spec->abs2rel( + File::Spec->rel2abs($f), + File::Spec->rel2abs($symlink_dir) + ); print "\$symlink_dst='$symlink_dst' "; + print "\n"; # symlink - print "symlink($f_path, $symlink_path);\n"; + print "symlink($symlink_dst, $symlink);\n"; + symlink($symlink_dst, $symlink); } # vim: set ts=4 sw=4 et cc=80: