]> git.sesse.net Git - pr0n/commitdiff
Auto-create images/NN and cache/NN directories on demand.
authorSteinar H. Gunderson <sesse@debian.org>
Sat, 9 Oct 2010 11:05:10 +0000 (13:05 +0200)
committerSteinar H. Gunderson <sesse@debian.org>
Sat, 9 Oct 2010 11:05:10 +0000 (13:05 +0200)
perl/Sesse/pr0n/Common.pm
perl/Sesse/pr0n/WebDAV.pm

index 6317ca4c09f66010a222518cd0a61751426cbe65..a9ee2119db8751d3c97770f5cb6f7aa68f9864e0 100644 (file)
@@ -211,7 +211,7 @@ sub get_base {
        my $r = shift;
        return $r->dir_config('ImageBase');
 }
        my $r = shift;
        return $r->dir_config('ImageBase');
 }
-
+                               
 sub get_disk_location {
        my ($r, $id) = @_;
         my $dir = POSIX::floor($id / 256);
 sub get_disk_location {
        my ($r, $id) = @_;
         my $dir = POSIX::floor($id / 256);
@@ -231,6 +231,23 @@ sub get_cache_location {
        }
 }
 
        }
 }
 
+sub ensure_disk_location_exists {
+       my ($r, $id) = @_;
+        my $dir = POSIX::floor($id / 256);
+
+       my $img_dir = get_base($r) . "/images/$dir/";
+       if (! -d $img_dir) {
+               $r->log->info("Need to create new image directory $img_dir");
+               mkdir($img_dir) or die "Couldn't create new image directory $img_dir";
+       }
+
+       my $cache_dir = get_base($r) . "/cache/$dir/";
+       if (! -d $cache_dir) {
+               $r->log->info("Need to create new cache directory $cache_dir");
+               mkdir($cache_dir) or die "Couldn't create new image directory $cache_dir";
+       }
+}
+
 sub get_mipmap_location {
        my ($r, $id, $width, $height) = @_;
         my $dir = POSIX::floor($id / 256);
 sub get_mipmap_location {
        my ($r, $id, $width, $height) = @_;
         my $dir = POSIX::floor($id / 256);
index 7298ffd105dc727c08fef07f1c6754f473eddd6a..73ca79cca6652a2619c308148da1b2c59b491197 100644 (file)
@@ -479,6 +479,7 @@ EOF
                                Sesse::pr0n::Common::purge_cache($r, "/$event/");
 
                                # Now save the file to disk
                                Sesse::pr0n::Common::purge_cache($r, "/$event/");
 
                                # Now save the file to disk
+                               Sesse::pr0n::Common::ensure_disk_location_exists($r, $newid);   
                                $fname = Sesse::pr0n::Common::get_disk_location($r, $newid);
                                open NEWFILE, ">$fname"
                                        or die "$fname: $!";
                                $fname = Sesse::pr0n::Common::get_disk_location($r, $newid);
                                open NEWFILE, ">$fname"
                                        or die "$fname: $!";