mason/.perl-lib/TrivGal.pm: Append `/' to folder names.
[tgal] / mason / .perl-lib / TrivGal.pm
index bbef2ed..600e9f5 100644 (file)
@@ -69,7 +69,10 @@ export qw{split_path};
 sub split_path ($) {
   my ($path) = @_;
 
-  my ($dir, $base, $ext) = $path =~ m#^(?:(.*)/)?(?:([^/]*)\.)?([^./]*)$#;
+  my ($dir, $base, $ext) =
+    $path =~ m#^ (?: (.*) /)?
+                (?: ([^/]*) \.)?
+                ([^./]*) $#x;
   if (defined $base) { $ext = ".$ext"; }
   else { $base = $ext; $ext = ""; }
   return ($dir, $base, $ext);
@@ -249,7 +252,7 @@ package TrivGal::Image {
 
     $scaled->image_set_format($ty->imlibfmt);
     $scaled->set_quality(90);
-    my $new = "$TMP/t${$}$ext";
+    my $new = "$TMP/t$$-$ext";
     make_path $TMP;
     $scaled->save($new);
     make_path $dir;
@@ -282,6 +285,7 @@ sub listdir ($) {
   my (@d, @f);
   my $ix = undef;
 
+  $path =~ s#/$##;
   if (-f "$path/.tgal.index") {
     open my $f, "<", "$path/.tgal.index";
     my $item = undef;
@@ -294,9 +298,15 @@ sub listdir ($) {
        $comment = defined $comment ? $comment . "\n" . $_ : $_;
       } else {
        if ($item && $comment) { $item->comment($comment); }
-       my ($indexp, $name, $c) = /(!\s+)?(\S+)\s*(\S|\S.*\S)?\s*$/;
+       my ($indexp, $name, $c) =
+         /^ (! \s+)?                   # index flag
+            (\S+) \s*                  # filename
+            (\S | \S.*\S )?            # start of the comment
+            \s*
+            $/x;
        $name = urldecode $name;
        my $list;
+       $item = TrivGal::Item->new($name);
        if ($name =~ m#/$#) {
          $list = \@d;
          die "can't index a folder" if $indexp;
@@ -309,7 +319,6 @@ sub listdir ($) {
            $ix = $item;
          }
        }
-       $item = TrivGal::Item->new($name);
        $comment = $c;
        push @$list, $item;
       }
@@ -330,7 +339,7 @@ sub listdir ($) {
       my $st = stat "$path/$e";
       my $list = undef;
       if ($dotp) { }
-      elsif (-d $st) { $list = \@d; }
+      elsif (-d $st) { $list = \@d; $e .= "/"; }
       elsif ($TYPE{lc $ext} && -f $st) { $list = \@f; }
       $list and push @$list, TrivGal::Item->new($e);
     }