From 7a5be72cbde6c15322c75f04229f10f59f32726b Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 15 Mar 2010 04:31:28 +0000 Subject: [PATCH] build warehouse directories on demand --- contrib/handle_flash/main.php | 1 + contrib/handle_ico/main.php | 1 + contrib/handle_mp3/main.php | 1 + contrib/handle_svg/main.php | 1 + core/imageboard.pack.php | 1 + ext/handle_pixel/main.php | 1 + install.php | 30 +++++++++++------------------- 7 files changed, 17 insertions(+), 19 deletions(-) diff --git a/contrib/handle_flash/main.php b/contrib/handle_flash/main.php index f63f988d..9bee0cfb 100644 --- a/contrib/handle_flash/main.php +++ b/contrib/handle_flash/main.php @@ -8,6 +8,7 @@ class FlashFileHandler extends DataHandlerExtension { protected function create_thumb($hash) { // FIXME: scale image, as not all boards use 192x192 + mkdir(dirname(warehouse_path("thumbs", $hash)), 0755, true); copy("ext/handle_flash/thumb.jpg", warehouse_path("thumbs", $hash)); } diff --git a/contrib/handle_ico/main.php b/contrib/handle_ico/main.php index 771dd506..8cb306c1 100644 --- a/contrib/handle_ico/main.php +++ b/contrib/handle_ico/main.php @@ -99,6 +99,7 @@ class IcoFileHandler extends SimpleExtension { $q = $config->get_int("thumb_quality"); $mem = $config->get_int("thumb_max_memory") / 1024 / 1024; // IM takes memory in MB + mkdir(dirname($outname), 0755, true); if($config->get_bool("ico_convert")) { // "-limit memory $mem" broken? exec("convert {$inname}[0] -geometry {$w}x{$h} -quality {$q} jpg:$outname"); diff --git a/contrib/handle_mp3/main.php b/contrib/handle_mp3/main.php index ba02b3c5..b6bd7b8d 100644 --- a/contrib/handle_mp3/main.php +++ b/contrib/handle_mp3/main.php @@ -8,6 +8,7 @@ class MP3FileHandler extends DataHandlerExtension { protected function create_thumb($hash) { // FIXME: scale image, as not all boards use 192x192 + mkdir(dirname(warehouse_path("thumbs", $hash)), 0755, true); copy("ext/handle_mp3/thumb.jpg", warehouse_path("thumbs", $hash)); } diff --git a/contrib/handle_svg/main.php b/contrib/handle_svg/main.php index e9e94c25..2be2c7b5 100644 --- a/contrib/handle_svg/main.php +++ b/contrib/handle_svg/main.php @@ -41,6 +41,7 @@ class SVGFileHandler implements Extension { // } // else { // FIXME: scale image, as not all boards use 192x192 + mkdir(dirname(warehouse_path("thumbs", $hash)), 0755, true); copy("ext/handle_svg/thumb.jpg", warehouse_path("thumbs", $hash)); // } } diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index cf986249..a9a0ec6e 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -949,6 +949,7 @@ class Tag { */ function move_upload_to_archive($event) { $target = warehouse_path("images", $event->hash); + mkdir(dirname($target), 0755, true); if(!@copy($event->tmpname, $target)) { throw new UploadException("Failed to copy file from uploads ({$event->tmpname}) to archive ($target)"); return false; diff --git a/ext/handle_pixel/main.php b/ext/handle_pixel/main.php index 53a18988..af02c220 100644 --- a/ext/handle_pixel/main.php +++ b/ext/handle_pixel/main.php @@ -48,6 +48,7 @@ class PixelFileHandler extends DataHandlerExtension { $ok = false; + mkdir(dirname($outname), 0755, true); switch($config->get_string("thumb_engine")) { default: case 'gd': diff --git a/install.php b/install.php index 4e77d8cb..e8e42732 100644 --- a/install.php +++ b/install.php @@ -149,9 +149,9 @@ function begin() { // {{{ EOD; } // }}} function install_process($database_dsn) { // {{{ + build_dirs(); create_tables($database_dsn); insert_defaults($database_dsn); - build_dirs(); write_config($database_dsn); header("Location: index.php"); @@ -266,34 +266,26 @@ function insert_defaults($dsn) { // {{{ } } // }}} function build_dirs() { // {{{ - if(!file_exists("images")) @mkdir("images"); // *try* and make default dirs. Ignore any errors -- - if(!file_exists("thumbs")) @mkdir("thumbs"); // if something is amiss, we'll tell the user later - if(!file_exists("data")) @mkdir("data"); + // *try* and make default dirs. Ignore any errors -- + // if something is amiss, we'll tell the user later + if(!file_exists("images")) @mkdir("images"); + if(!file_exists("thumbs")) @mkdir("thumbs"); + if(!file_exists("data") ) @mkdir("data"); + if(!is_writable("images")) @chmod("images", 0755); + if(!is_writable("thumbs")) @chmod("thumbs", 0755); + if(!is_writable("data") ) @chmod("data", 0755); if( - ((!file_exists("images") || !file_exists("thumbs") || !file_exists("data")) && !is_writable("./")) || - (!is_writable("images") || !is_writable("thumbs") || !is_writable("data")) + !file_exists("images") || !file_exists("thumbs") || !file_exists("data") || + !is_writable("images") || !is_writable("thumbs") || !is_writable("data") ) { print "Shimmie needs three folders in it's directory, 'images', 'thumbs', and 'data', and they need to be writable by the PHP user (if you see this error, if probably means the folders are owned by you, and they need to be writable by the web server). -

Once you have created these folders, hit 'refresh' to continue."; exit; } - else { - assert(file_exists("images") && is_writable("images")); - assert(file_exists("thumbs") && is_writable("thumbs")); - assert(file_exists("data") && is_writable("data")); - - if(!file_exists("images/ff")) { - for($i=0; $i<256; $i++) { - mkdir(sprintf("images/%02x", $i)); - mkdir(sprintf("thumbs/%02x", $i)); - } - } - } } // }}} function write_config($dsn) { // {{{ $file_content = "";