diff options
author | Robin Appelman <icewind@owncloud.com> | 2012-01-16 06:06:11 +0400 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2012-01-16 06:06:11 +0400 |
commit | 96e2f15d8a6eee83e30bdf77ef3582f0c26b52e0 (patch) | |
tree | 9df43704cb7e580d328d6780561a0ec146003e7b /lib | |
parent | ccc43f0ea02a048583fff715f00cda0280124586 (diff) | |
parent | b0dbca0cc7f2d07dbf01c54861b932d8dc9fe2df (diff) |
merge master into filesystem
Diffstat (limited to 'lib')
-rw-r--r-- | lib/app.php | 1 | ||||
-rw-r--r-- | lib/base.php | 10 | ||||
-rw-r--r-- | lib/db.php | 17 | ||||
-rw-r--r-- | lib/files.php | 19 | ||||
-rw-r--r-- | lib/filestorage/local.php | 9 | ||||
-rw-r--r-- | lib/filesystem.php | 142 | ||||
-rw-r--r-- | lib/image.php | 3 | ||||
-rw-r--r-- | lib/mimetypes.fixlist.php | 14 | ||||
-rw-r--r-- | lib/setup.php | 35 | ||||
-rw-r--r-- | lib/util.php | 4 |
10 files changed, 216 insertions, 38 deletions
diff --git a/lib/app.php b/lib/app.php index 13c4cef32b4..de7d82ce959 100644 --- a/lib/app.php +++ b/lib/app.php @@ -385,6 +385,7 @@ class OC_App{ $currentVersion=$appInfo['version']; if (version_compare($currentVersion, $installedVersion, '>')) { OC_App::updateApp($app); + OC_Appconfig::setValue($app,'installed_version',$appInfo['version']); } } } diff --git a/lib/base.php b/lib/base.php index 9ac6b6751a2..ca07eef590c 100644 --- a/lib/base.php +++ b/lib/base.php @@ -156,7 +156,11 @@ class OC{ $installedVersion=OC_Config::getValue('version','0.0.0'); $currentVersion=implode('.',OC_Util::getVersion()); if (version_compare($currentVersion, $installedVersion, '>')) { - OC_DB::updateDbFromStructure('../db_structure.xml'); + $result=OC_DB::updateDbFromStructure(OC::$SERVERROOT.'/db_structure.xml'); + if(!$result){ + echo 'Error while upgrading the database'; + die(); + } OC_Config::setValue('version',implode('.',OC_Util::getVersion())); } @@ -178,7 +182,7 @@ class OC{ // Add the stuff we need always OC_Util::addScript( "jquery-1.6.4.min" ); - OC_Util::addScript( "jquery-ui-1.8.14.custom.min" ); + OC_Util::addScript( "jquery-ui-1.8.16.custom.min" ); OC_Util::addScript( "jquery-showpassword" ); OC_Util::addScript( "jquery.infieldlabel.min" ); OC_Util::addScript( "jquery-tipsy" ); @@ -187,7 +191,7 @@ class OC{ OC_Util::addScript('search','result'); OC_Util::addStyle( "styles" ); OC_Util::addStyle( "multiselect" ); - OC_Util::addStyle( "jquery-ui-1.8.14.custom" ); + OC_Util::addStyle( "jquery-ui-1.8.16.custom" ); OC_Util::addStyle( "jquery-tipsy" ); $errors=OC_Util::checkServer(); diff --git a/lib/db.php b/lib/db.php index b901cc8b513..4860651b323 100644 --- a/lib/db.php +++ b/lib/db.php @@ -144,7 +144,7 @@ class OC_DB { // Prepare options array $options = array( - 'portability' => MDB2_PORTABILITY_ALL, + 'portability' => MDB2_PORTABILITY_ALL & (!MDB2_PORTABILITY_FIX_CASE), 'log_line_break' => '<br>', 'idxname_format' => '%s', 'debug' => true, @@ -361,6 +361,11 @@ class OC_DB { $content = file_get_contents( $file ); $previousSchema = self::$schema->getDefinitionFromDatabase(); + if (PEAR::isError($previousSchema)) { + $error = $previousSchema->getMessage(); + OC_Log::write('core','Failed to get existing database structure for upgrading ('.$error.')',OC_Log::FATAL); + return false; + } // Make changes and save them to a temporary file $file2 = tempnam( get_temp_dir(), 'oc_db_scheme_' ); @@ -371,10 +376,14 @@ class OC_DB { } file_put_contents( $file2, $content ); $op = self::$schema->updateDatabase($file2, $previousSchema, array(), false); + + // Delete our temporary file + unlink( $file2 ); + if (PEAR::isError($op)) { - $error = $op->getMessage(); - OC_Log::write('core','Failed to update database structure ('.$error.')',OC_Log::FATAL); - return false; + $error = $op->getMessage(); + OC_Log::write('core','Failed to update database structure ('.$error.')',OC_Log::FATAL); + return false; } return true; } diff --git a/lib/files.php b/lib/files.php index 143aab5c72d..5686287ecc4 100644 --- a/lib/files.php +++ b/lib/files.php @@ -152,8 +152,8 @@ class OC_Files { */ public static function move($sourceDir,$source,$targetDir,$target){ if(OC_User::isLoggedIn()){ - $targetFile=$targetDir.'/'.$target; - $sourceFile=$sourceDir.'/'.$source; + $targetFile=self::normalizePath($targetDir.'/'.$target); + $sourceFile=self::normalizePath($sourceDir.'/'.$source); return OC_Filesystem::rename($sourceFile,$targetFile); } } @@ -274,4 +274,19 @@ class OC_Files { $content.= "Options -Indexes\n"; @file_put_contents(OC::$SERVERROOT.'/.htaccess', $content); //supress errors in case we don't have permissions for it } + + /** + * normalize a path, removing any double, add leading /, etc + * @param string $path + * @return string + */ + static public function normalizePath($path){ + $path='/'.$path; + $old=''; + while($old!=$path){//replace any multiplicity of slashes with a single one + $old=$path; + $path=str_replace('//','/',$path); + } + return $path; + } } diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php index 18bfd69d719..dcffce6e867 100644 --- a/lib/filestorage/local.php +++ b/lib/filestorage/local.php @@ -120,6 +120,13 @@ class OC_Filestorage_Local extends OC_Filestorage{ public function getMimeType($fspath){ if($this->is_readable($fspath)){ $mimeType='application/octet-stream'; + if ($mimeType=='application/octet-stream') { + self::$mimetypes = include('mimetypes.fixlist.php'); + $extention=strtolower(strrchr(basename($fspath), ".")); + $extention=substr($extention,1);//remove leading . + $mimeType=(isset(self::$mimetypes[$extention]))?self::$mimetypes[$extention]:'application/octet-stream'; + + } if (@is_dir($this->datadir.$fspath)) { // directories are easy return "httpd/unix-directory"; @@ -146,7 +153,7 @@ class OC_Filestorage_Local extends OC_Filestorage{ } if ($mimeType=='application/octet-stream') { // Fallback solution: (try to guess the type by the file extension - if(!self::$mimetypes){ + if(!self::$mimetypes || self::$mimetypes != include('mimetypes.list.php')){ self::$mimetypes=include('mimetypes.list.php'); } $extention=strtolower(strrchr(basename($fspath), ".")); diff --git a/lib/filesystem.php b/lib/filesystem.php index 8765775dc29..6568a07a59c 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -47,6 +47,93 @@ class OC_Filesystem{ static private $storages=array(); static private $mounts=array(); static private $fakeRoot=''; + static private $storageTypes=array(); + + /** + * classname which used for hooks handling + * used as signalclass in OC_Hooks::emit() + */ + const CLASSNAME = 'OC_Filesystem'; + + /** + * signalname emited before file renaming + * @param oldpath + * @param newpath + */ + const signal_rename = 'rename'; + + /** + * signal emited after file renaming + * @param oldpath + * @param newpath + */ + const signal_post_rename = 'post_rename'; + + /** + * signal emited before file/dir creation + * @param path + * @param run changing this flag to false in hook handler will cancel event + */ + const signal_create = 'create'; + + /** + * signal emited after file/dir creation + * @param path + * @param run changing this flag to false in hook handler will cancel event + */ + const signal_post_create = 'post_create'; + + /** + * signal emits before file/dir copy + * @param oldpath + * @param newpath + * @param run changing this flag to false in hook handler will cancel event + */ + const signal_copy = 'copy'; + + /** + * signal emits after file/dir copy + * @param oldpath + * @param newpath + */ + const signal_post_copy = 'post_copy'; + + /** + * signal emits before file/dir save + * @param path + * @param run changing this flag to false in hook handler will cancel event + */ + const signal_write = 'write'; + + /** + * signal emits after file/dir save + * @param path + */ + const signal_post_write = 'post_write'; + + /** + * signal emits when reading file/dir + * @param path + */ + const signal_read = 'read'; + + /** + * signal emits when removing file/dir + * @param path + */ + const signal_delete = 'delete'; + + /** + * parameters definitions for signals + */ + const signal_param_path = 'path'; + const signal_param_oldpath = 'oldpath'; + const signal_param_newpath = 'newpath'; + + /** + * run - changing this flag to false in hook handler will cancel event + */ + const signal_param_run = 'run'; /** * tear down the filesystem, removing all storage providers @@ -260,7 +347,7 @@ class OC_Filesystem{ static public function rename($path1,$path2){ if(OC_FileProxy::runPreProxies('rename',$path1,$path2) and self::is_writeable($path1) and self::isValidPath($path2)){ $run=true; - OC_Hook::emit( 'OC_Filesystem', 'rename', array( 'oldpath' => $path1 ,'newpath'=>$path2, 'run' => &$run)); + OC_Hook::emit( self::CLASSNAME, self::signal_rename, array( self::signal_param_oldpath => $path1 , self::signal_param_newpath=>$path2, self::signal_param_run => &$run)); if($run){ $mp1=self::getMountPoint($path1); $mp2=self::getMountPoint($path2); @@ -273,7 +360,7 @@ class OC_Filesystem{ $result=$storage2->fromTmpFile($tmpFile,self::getInternalPath($path2)); $storage1->unlink(self::getInternalPath($path1)); } - OC_Hook::emit( 'OC_Filesystem', 'post_rename', array( 'oldpath' => $path1, 'newpath'=>$path2)); + OC_Hook::emit( self::CLASSNAME, self::signal_post_rename, array( self::signal_param_oldpath => $path1, self::signal_param_newpath=>$path2)); return $result; } } @@ -281,13 +368,13 @@ class OC_Filesystem{ static public function copy($path1,$path2){ if(OC_FileProxy::runPreProxies('copy',$path1,$path2) and self::is_readable($path1) and self::isValidPath($path2)){ $run=true; - OC_Hook::emit( 'OC_Filesystem', 'copy', array( 'oldpath' => $path1 ,'newpath'=>$path2, 'run' => &$run)); + OC_Hook::emit( self::CLASSNAME, self::signal_copy, array( self::signal_param_oldpath => $path1 , self::signal_param_newpath=>$path2, self::signal_param_run => &$run)); $exists=self::file_exists($path2); if($run and !$exists){ - OC_Hook::emit( 'OC_Filesystem', 'create', array( 'path' => $path2, 'run' => &$run)); + OC_Hook::emit( self::CLASSNAME, self::signal_create, array( self::signal_param_path => $path2, self::signal_param_run => &$run)); } if($run){ - OC_Hook::emit( 'OC_Filesystem', 'write', array( 'path' => $path2, 'run' => &$run)); + OC_Hook::emit( self::CLASSNAME, self::signal_write, array( self::signal_param_path => $path2, self::signal_param_run => &$run)); } if($run){ $mp1=self::getMountPoint($path1); @@ -300,11 +387,11 @@ class OC_Filesystem{ $tmpFile=$storage1->toTmpFile(self::getInternalPath($path1)); $result=$storage2->fromTmpFile($tmpFile,self::getInternalPath($path2)); } - OC_Hook::emit( 'OC_Filesystem', 'post_copy', array( 'oldpath' => $path1 ,'newpath'=>$path2)); + OC_Hook::emit( self::CLASSNAME, self::signal_post_copy, array( self::signal_param_oldpath => $path1 , self::signal_param_newpath=>$path2)); if(!$exists){ - OC_Hook::emit( 'OC_Filesystem', 'post_create', array( 'path' => $path2)); + OC_Hook::emit( self::CLASSNAME, self::signal_post_create, array( self::signal_param_path => $path2)); } - OC_Hook::emit( 'OC_Filesystem', 'post_write', array( 'path' => $path2)); + OC_Hook::emit( self::CLASSNAME, self::signal_post_write, array( self::signal_param_path => $path2)); return $result; } } @@ -335,7 +422,7 @@ class OC_Filesystem{ } static public function toTmpFile($path){ if(OC_FileProxy::runPreProxies('toTmpFile',$path) and self::isValidPath($path) and $storage=self::getStorage($path)){ - OC_Hook::emit( 'OC_Filesystem', 'read', array( 'path' => $path)); + OC_Hook::emit( self::CLASSNAME, self::signal_read, array( self::signal_param_path => $path)); return $storage->toTmpFile(self::getInternalPath($path)); } } @@ -344,21 +431,44 @@ class OC_Filesystem{ $run=true; $exists=self::file_exists($path); if(!$exists){ - OC_Hook::emit( 'OC_Filesystem', 'create', array( 'path' => $path, 'run' => &$run)); + OC_Hook::emit( self::CLASSNAME, self::signal_create, array( self::signal_param_path => $path, self::signal_param_run => &$run)); } if($run){ - OC_Hook::emit( 'OC_Filesystem', 'write', array( 'path' => $path, 'run' => &$run)); + OC_Hook::emit( self::CLASSNAME, self::signal_write, array( self::signal_param_path => $path, self::signal_param_run => &$run)); } if($run){ $result=$storage->fromTmpFile($tmpFile,self::getInternalPath($path)); if(!$exists){ - OC_Hook::emit( 'OC_Filesystem', 'post_create', array( 'path' => $path)); + OC_Hook::emit( self::CLASSNAME, self::signal_post_create, array( self::signal_param_path => $path)); + } + OC_Hook::emit( self::CLASSNAME, self::signal_post_write, array( self::signal_param_path => $path)); + return $result; + } + } + } +<<<<<<< HEAD +======= + static public function fromUploadedFile($tmpFile,$path){ + if(OC_FileProxy::runPreProxies('fromUploadedFile',$tmpFile,$path) and self::isValidPath($path) and $storage=self::getStorage($path)){ + $run=true; + $exists=self::file_exists($path); + if(!$exists){ + OC_Hook::emit( self::CLASSNAME, self::signal_create, array( self::signal_param_path => $path, self::signal_param_run => &$run)); + } + if($run){ + OC_Hook::emit( self::CLASSNAME, self::signal_write, array( self::signal_param_path => $path, self::signal_param_run => &$run)); + } + if($run){ + $result=$storage->fromUploadedFile($tmpFile,self::getInternalPath($path)); + if(!$exists){ + OC_Hook::emit( self::CLASSNAME, self::signal_post_create, array( self::signal_param_path => $path)); } - OC_Hook::emit( 'OC_Filesystem', 'post_write', array( 'path' => $path)); + OC_Hook::emit( self::CLASSNAME, self::signal_post_write, array( self::signal_param_path => $path)); return $result; } } } +>>>>>>> master static public function getMimeType($path){ return self::basicOperation('getMimeType',$path); } @@ -402,9 +512,9 @@ class OC_Filesystem{ $run=true; foreach($hooks as $hook){ if($hook!='read'){ - OC_Hook::emit( 'OC_Filesystem', $hook, array( 'path' => $path, 'run' => &$run)); + OC_Hook::emit( self::CLASSNAME, $hook, array( self::signal_param_path => $path, self::signal_param_run => &$run)); }else{ - OC_Hook::emit( 'OC_Filesystem', $hook, array( 'path' => $path)); + OC_Hook::emit( self::CLASSNAME, $hook, array( self::signal_param_path => $path)); } } if($run){ @@ -416,7 +526,7 @@ class OC_Filesystem{ $result=OC_FileProxy::runPostProxies($operation,$path,$result); foreach($hooks as $hook){ if($hook!='read'){ - OC_Hook::emit( 'OC_Filesystem', 'post_'.$hook, array( 'path' => $path)); + OC_Hook::emit( self::CLASSNAME, 'post_'.$hook, array( self::signal_param_path => $path)); } } return $result; diff --git a/lib/image.php b/lib/image.php index 45b6ad3918d..70ad3f5969e 100644 --- a/lib/image.php +++ b/lib/image.php @@ -196,10 +196,11 @@ class OC_Image { if (!$res) { OC_Log::write('core','OC_Image::_string. Error writing image',OC_Log::ERROR); } - return chunk_split(base64_encode(ob_get_clean())); + return base64_encode(ob_get_clean()); } /** + * (I'm open for suggestions on better method name ;) * @brief Fixes orientation based on EXIF data. * @returns bool. */ diff --git a/lib/mimetypes.fixlist.php b/lib/mimetypes.fixlist.php new file mode 100644 index 00000000000..1c6acbc4438 --- /dev/null +++ b/lib/mimetypes.fixlist.php @@ -0,0 +1,14 @@ +<?php +return array( + 'ics'=>'text/calendar', + 'ical'=>'text/calendar', + 'js'=>'application/javascript', + 'odt'=>'application/vnd.oasis.opendocument.text', + 'ods'=>'application/vnd.oasis.opendocument.spreadsheet', + 'odg'=>'application/vnd.oasis.opendocument.graphics', + 'odp'=>'application/vnd.oasis.opendocument.presentation', + 'pl'=>'text/x-script.perl', + 'py'=>'text/x-script.phyton', + 'vcf' => 'text/vcard', + 'vcard' => 'text/vcard' +); diff --git a/lib/setup.php b/lib/setup.php index 1b74e945196..eb32e84713f 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -84,7 +84,7 @@ class OC_Setup { $dbpass = $options['dbpass']; $dbname = $options['dbname']; $dbhost = $options['dbhost']; - $dbtableprefix = $options['dbtableprefix']; + $dbtableprefix = isset($options['dbtableprefix']) ? $options['dbtableprefix'] : 'oc_'; OC_Config::setValue('dbname', $dbname); OC_Config::setValue('dbhost', $dbhost); OC_Config::setValue('dbtableprefix', $dbtableprefix); @@ -189,16 +189,29 @@ class OC_Setup { self::pg_createDatabase($dbname, $dbuser, $connection); } - //fill the database if needed - $query = "select count(*) FROM pg_class WHERE relname='{$dbtableprefix}users' limit 1"; - $result = pg_query($connection, $query); - if($result){ - $row = pg_fetch_row($result); - } - if(!$result or $row[0]==0) { - OC_DB::createDbFromStructure('db_structure.xml'); - } + // the connection to dbname=postgres is not needed anymore pg_close($connection); + + // connect to the ownCloud database (dbname=$dbname) an check if it needs to be filled + $dbuser = OC_CONFIG::getValue('dbuser'); + $dbpass = OC_CONFIG::getValue('dbpassword'); + $connection_string = "host=$dbhost dbname=$dbname user=$dbuser password=$dbpass"; + $connection = @pg_connect($connection_string); + if(!$connection) { + $error[] = array( + 'error' => 'PostgreSQL username and/or password not valid', + 'hint' => 'You need to enter either an existing account or the administrator.' + ); + } else { + $query = "select count(*) FROM pg_class WHERE relname='{$dbtableprefix}users' limit 1"; + $result = pg_query($connection, $query); + if($result) { + $row = pg_fetch_row($result); + } + if(!$result or $row[0]==0) { + OC_DB::createDbFromStructure('db_structure.xml'); + } + } } } else { @@ -288,7 +301,7 @@ class OC_Setup { $content.= "php_value post_max_size 512M\n"; $content.= "SetEnv htaccessWorking true\n"; $content.= "</IfModule>\n"; - $content.= "<IfModule mod_rewrite.c>"; + $content.= "<IfModule mod_rewrite.c>\n"; $content.= "RewriteEngine on\n"; $content.= "RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization},last]\n"; $content.= "</IfModule>\n"; diff --git a/lib/util.php b/lib/util.php index a0c131201e4..2fb581aea25 100644 --- a/lib/util.php +++ b/lib/util.php @@ -226,6 +226,10 @@ class OC_Util { $errors[]=array('error'=>'PHP module ctype is not installed.<br/>','hint'=>'Please ask your server administrator to install the module.'); } + if(!is_writeable(OC::$SERVERROOT."/config/config.php")){ + $errors[]=array('error'=>"Can't write into config directory 'config'",'hint'=>"You can usually fix this by giving the webserver use write access to the config directory in owncloud"); + } + return $errors; } |