From 375c3284531f10a47299fcd4f185459d3be20cd1 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 21 Oct 2008 07:08:12 +0000 Subject: [PATCH] Fixed bug pointed out by lluis : sqlfs stores files with fs_id < 100 directly under /sqlfs in the files dir. They conflict with directories created for fs_id >= 1000. --> fs_id < 100 are now in a directory /sqlfs/00 You need to run the 1.5.016 update or you will not find the content of files with fs_id < 100 anymore! --- .../inc/class.sqlfs_stream_wrapper.inc.php | 17 +++++----- phpgwapi/setup/setup.inc.php | 2 +- phpgwapi/setup/tables_update.inc.php | 34 +++++++++++++++++++ 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/phpgwapi/inc/class.sqlfs_stream_wrapper.inc.php b/phpgwapi/inc/class.sqlfs_stream_wrapper.inc.php index e4bba9a2d6..962be87350 100644 --- a/phpgwapi/inc/class.sqlfs_stream_wrapper.inc.php +++ b/phpgwapi/inc/class.sqlfs_stream_wrapper.inc.php @@ -208,7 +208,7 @@ class sqlfs_stream_wrapper implements iface_stream_wrapper { $stmt->bindParam(':'.$name,$val); } - if (!$stmt->execute() || !($this->opened_fs_id = self::$pdo->lastInsertId('fs_id'))) + if (!$stmt->execute() || !($this->opened_fs_id = self::$pdo->lastInsertId('egw_sqlfs_fs_id_seq'))) { $this->opened_stream = $this->opened_path = $this->opened_mode = null; error_log(__METHOD__."($url,$mode,$options) execute() failed: ".self::$pdo->errorInfo()); @@ -1415,8 +1415,8 @@ class sqlfs_stream_wrapper implements iface_stream_wrapper * Return the path of the stored content of a file if $this->operation == self::STORE2FS * * To limit the number of files stored in one directory, we create a hash from the fs_id: - * 1 --> /1 - * 34 --> /34 + * 1 --> /00/1 + * 34 --> /00/34 * 123 --> /01/123 * 4567 --> /45/4567 * 99999 --> /09/99/99999 @@ -1430,7 +1430,7 @@ class sqlfs_stream_wrapper implements iface_stream_wrapper { throw new egw_exception_wrong_parameter(__METHOD__."(id=$id) id has to be an integer!"); } - if (!isset($GLOBALS['egw_info']['server']['files_dir']) || $GLOBALS['egw_info']['server']['files_dir']) + if (!isset($GLOBALS['egw_info']['server']['files_dir'])) { if (is_object($GLOBALS['egw_setup']->db)) // if we run under setup, query the db for the files dir { @@ -1439,16 +1439,17 @@ class sqlfs_stream_wrapper implements iface_stream_wrapper 'config_app' => 'phpgwapi', ),__LINE__,__FILE__)->fetchSingle(); } - if (!$GLOBALS['egw_info']['server']['files_dir']) - { - throw new egw_exception_assertion_failed("\$GLOBALS['egw_info']['server']['files_dir'] not set!"); - } + } + if (!$GLOBALS['egw_info']['server']['files_dir']) + { + throw new egw_exception_assertion_failed("\$GLOBALS['egw_info']['server']['files_dir'] not set!"); } $hash = array(); for ($n = $id; $n = (int) ($n / self::HASH_MAX); ) { $hash[] = sprintf('%02d',$n % self::HASH_MAX); } + if (!$hash) $hash[] = '00'; // we need at least one directory, to not conflict with the dir-names array_unshift($hash,$id); $path = '/sqlfs/'.implode('/',array_reverse($hash)); diff --git a/phpgwapi/setup/setup.inc.php b/phpgwapi/setup/setup.inc.php index 861c56bf99..fce0007acf 100755 --- a/phpgwapi/setup/setup.inc.php +++ b/phpgwapi/setup/setup.inc.php @@ -12,7 +12,7 @@ /* Basic information about this app */ $setup_info['phpgwapi']['name'] = 'phpgwapi'; $setup_info['phpgwapi']['title'] = 'eGroupWare API'; -$setup_info['phpgwapi']['version'] = '1.5.015'; +$setup_info['phpgwapi']['version'] = '1.5.016'; $setup_info['phpgwapi']['versions']['current_header'] = '1.29'; $setup_info['phpgwapi']['enable'] = 3; $setup_info['phpgwapi']['app_order'] = 1; diff --git a/phpgwapi/setup/tables_update.inc.php b/phpgwapi/setup/tables_update.inc.php index ef1be484d8..86bf36ed90 100644 --- a/phpgwapi/setup/tables_update.inc.php +++ b/phpgwapi/setup/tables_update.inc.php @@ -544,3 +544,37 @@ function phpgwapi_upgrade1_5_014() return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.5.015'; } +/** + * Move files created directly in the root of sqlfs (fs_id < 100) into a /00 directory, + * as they would conflict with dirnames in that directory. + * + * This update does nothing, if the files are already in the correct directory + */ +function phpgwapi_upgrade1_5_015() +{ + sqlfs_stream_wrapper::_fs_path(1); // loads egw_info/server/files_dir (!) + $sqlfs_dir = $GLOBALS['egw_info']['server']['files_dir'].'/sqlfs'; + + if (file_exists($sqlfs_dir) && ($d = opendir($sqlfs_dir))) + { + while(($f = readdir($d))) + { + if (is_file($old_name = $sqlfs_dir.'/'.$f)) + { + if (!$zero_dir) + { + if ($GLOBALS['DEBUG'] && isset($_SERVER['HTTP_HOST'])) echo "
\n";
+ 					mkdir($zero_dir = $sqlfs_dir.'/00',0777);
+					echo "created dir for files with fs_id < 100: $zero_dir\n";
+				}
+				$new_name = $zero_dir.'/'.$f;
+				if ($GLOBALS['DEBUG']) echo "moving file $old_name --> $new_name\n";
+				rename($old_name,$new_name);
+			}
+		}
+		closedir($d);
+		if ($GLOBALS['DEBUG'] && isset($_SERVER['HTTP_HOST']) && $zero_dir) echo "
\n"; + } + + return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.5.016'; +}