From: Steinar H. Gunderson Date: Sat, 9 Oct 2010 11:05:10 +0000 (+0200) Subject: Auto-create images/NN and cache/NN directories on demand. X-Git-Url: https://git.sesse.net/?p=pr0n;a=commitdiff_plain;h=9b45ad1ecd9f1eace384f825a7dc6b2b7920af65;ds=sidebyside Auto-create images/NN and cache/NN directories on demand. --- diff --git a/perl/Sesse/pr0n/Common.pm b/perl/Sesse/pr0n/Common.pm index 6317ca4..a9ee211 100644 --- a/perl/Sesse/pr0n/Common.pm +++ b/perl/Sesse/pr0n/Common.pm @@ -211,7 +211,7 @@ sub get_base { my $r = shift; return $r->dir_config('ImageBase'); } - + 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); diff --git a/perl/Sesse/pr0n/WebDAV.pm b/perl/Sesse/pr0n/WebDAV.pm index 7298ffd..73ca79c 100644 --- a/perl/Sesse/pr0n/WebDAV.pm +++ b/perl/Sesse/pr0n/WebDAV.pm @@ -479,6 +479,7 @@ EOF 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: $!";