From d049d9bd0c70c929c2116cf7d8d088dfa7f9ae62 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 29 Mar 2012 23:16:19 +0200 Subject: initial commit for OC_Exception --- lib/exception.php | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 lib/exception.php (limited to 'lib') diff --git a/lib/exception.php b/lib/exception.php new file mode 100644 index 00000000000..b4724e7c8c2 --- /dev/null +++ b/lib/exception.php @@ -0,0 +1,74 @@ +. + * + */ +class OC_Exception extends Exception{ + + function __construct($message = null, $code = 0, $file = null, $line = null){ + parent::__construct($message, $code); + if(!is_null($file)){ + $this->file = $file; + } + if(!is_null($line)){ + $this->line = $line; + } + $this->writelog(); + } + + private function writelog(){ + @OC_Log::write(OC_App::getCurrentApp(), $this->getMessage() . '-' . $this->getFile() . '-' . $this->getLine(), OC_Log::FATAL); + } + + private function generatesysinfo(){ + return array('phpversion' => PHP_VERSION, + 'os' => php_uname('s'), + 'osrelease' => php_uname('r'), + 'osarchitecture' => php_uname('m'), + 'phpserverinterface' => php_sapi_name(), + 'serverprotocol' => $_SERVER['SERVER_PROTOCOL'], + 'requestmethod' => $_SERVER['REQUEST_METHOD'], + 'https' => ($_SERVER['HTTPS']==''?'false':'true'), + 'database'=>(@OC_Config::getValue('dbtype')!=''?@OC_Config::getValue('dbtype'):'') + ); + } + + function __toString(){ + $tmpl = new OC_Template('core', 'exception', 'guest'); + $tmpl->assign('showsysinfo', true); + $tmpl->assign('message', $this->getMessage()); + $tmpl->assign('code', $this->getCode()); + $tmpl->assign('file', $this->getFile()); + $tmpl->assign('line', $this->getLine()); + $tmpl->assign('sysinfo', $this->generatesysinfo()); + $tmpl->printPage(); + } +} + +function oc_exceptionhandler($exception){ + throw new OC_Exception($exception->getMessage(), $exception->getCode(), $exception->getFile(), $exception->getLine()); + return true; +} + +function oc_errorhandler(){ + +} +set_exception_handler('oc_exceptionhandler'); +set_error_handler('oc_errorhandler'); +error_reporting(E_ERROR | E_WARNING | E_PARSE); \ No newline at end of file -- cgit v1.2.3 From 926e777061efcc29d293b4af305ca9d0d01f6e22 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 30 Mar 2012 23:37:47 +0200 Subject: filter notice and deprecated errors and write a proper error handler function --- lib/exception.php | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/exception.php b/lib/exception.php index b4724e7c8c2..db516fc12d2 100644 --- a/lib/exception.php +++ b/lib/exception.php @@ -62,12 +62,31 @@ class OC_Exception extends Exception{ } function oc_exceptionhandler($exception){ - throw new OC_Exception($exception->getMessage(), $exception->getCode(), $exception->getFile(), $exception->getLine()); + switch($exception->getCode()){ + case E_NOTICE: + case E_DEPRECATED: + case E_USER_NOTICE: + case E_USER_DEPRECATED: + break; + default: + throw new OC_Exception($exception->getMessage(), $exception->getCode(), $exception->getFile(), $exception->getLine()); + break; + } return true; } -function oc_errorhandler(){ - +function oc_errorhandler($errno , $errstr , $errfile , $errline){ + switch($errno){ + case E_NOTICE: + case E_DEPRECATED: + case E_USER_NOTICE: + case E_USER_DEPRECATED: + break; + default: + throw new OC_Exception($errstr, $errno, $errfile, $errline); + break; + } + return true; } set_exception_handler('oc_exceptionhandler'); set_error_handler('oc_errorhandler'); -- cgit v1.2.3 From 967c6d7d3cfeb2f504ddc4301b902b39377c45fb Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Fri, 13 Jul 2012 13:25:43 +0200 Subject: allow command line based installation/setup --- lib/setup.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/setup.php b/lib/setup.php index 2f73c486c9c..027c84db092 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -257,7 +257,7 @@ class OC_Setup { OC_Installer::installShippedApps(); //create htaccess files for apache hosts - if (strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')) { + if (isset($_SERVER['SERVER_SOFTWARE']) && strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')) { self::createHtaccess(); } -- cgit v1.2.3 From b45d3ced79b5a20034c85973760e2f120e1574e7 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 13 Jul 2012 22:44:35 +0200 Subject: fix remote and public.php --- apps/calendar/appinfo/version | 2 +- apps/contacts/appinfo/version | 2 +- apps/files/appinfo/version | 2 +- apps/files_sharing/appinfo/version | 2 +- apps/gallery/appinfo/version | 2 +- apps/media/appinfo/version | 2 +- lib/app.php | 2 +- public.php | 1 + remote.php | 10 ++++------ 9 files changed, 12 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/apps/calendar/appinfo/version b/apps/calendar/appinfo/version index 2eb3c4fe4ee..cb0c939a936 100644 --- a/apps/calendar/appinfo/version +++ b/apps/calendar/appinfo/version @@ -1 +1 @@ -0.5 +0.5.2 diff --git a/apps/contacts/appinfo/version b/apps/contacts/appinfo/version index 7dff5b89211..373f8c6f073 100644 --- a/apps/contacts/appinfo/version +++ b/apps/contacts/appinfo/version @@ -1 +1 @@ -0.2.1 \ No newline at end of file +0.2.3 \ No newline at end of file diff --git a/apps/files/appinfo/version b/apps/files/appinfo/version index 8cfbc905b39..9c1218c201f 100644 --- a/apps/files/appinfo/version +++ b/apps/files/appinfo/version @@ -1 +1 @@ -1.1.1 \ No newline at end of file +1.1.3 \ No newline at end of file diff --git a/apps/files_sharing/appinfo/version b/apps/files_sharing/appinfo/version index 7dff5b89211..f4778493c50 100644 --- a/apps/files_sharing/appinfo/version +++ b/apps/files_sharing/appinfo/version @@ -1 +1 @@ -0.2.1 \ No newline at end of file +0.2.2 \ No newline at end of file diff --git a/apps/gallery/appinfo/version b/apps/gallery/appinfo/version index 8f0916f768f..4b9fcbec101 100644 --- a/apps/gallery/appinfo/version +++ b/apps/gallery/appinfo/version @@ -1 +1 @@ -0.5.0 +0.5.1 diff --git a/apps/media/appinfo/version b/apps/media/appinfo/version index e6adf3fc7bb..44bb5d1f743 100644 --- a/apps/media/appinfo/version +++ b/apps/media/appinfo/version @@ -1 +1 @@ -0.4 \ No newline at end of file +0.4.1 \ No newline at end of file diff --git a/lib/app.php b/lib/app.php index 4c2c43ec26b..caf8bd82521 100755 --- a/lib/app.php +++ b/lib/app.php @@ -608,7 +608,7 @@ class OC_App{ //set remote/public handelers $appData=self::getAppInfo($appid); foreach($appData['remote'] as $name=>$path){ - OCP\CONFIG::setAppValue('core', 'remote_'.$name, $path); + OCP\CONFIG::setAppValue('core', 'remote_'.$name, $appid.'/'.$path); } foreach($appData['public'] as $name=>$path){ OCP\CONFIG::setAppValue('core', 'public_'.$name, $appid.'/'.$path); diff --git a/public.php b/public.php index 8846769f467..8383f36a246 100644 --- a/public.php +++ b/public.php @@ -10,6 +10,7 @@ if(is_null($file)){ $parts=explode('/',$file,2); $app=$parts[0]; + OC_Util::checkAppEnabled($app); OC_App::loadApp($app); diff --git a/remote.php b/remote.php index bdce867aaba..8c02c24e2a3 100644 --- a/remote.php +++ b/remote.php @@ -15,27 +15,25 @@ if (!$pos = strpos($path_info, '/', 1)) { $pos = strlen($path_info); } $service=substr($path_info, 1, $pos-1); + $file = OC_AppConfig::getValue('core', 'remote_' . $service); -$file = preg_replace('/apps\//','', $file); //Todo Remove after Multiappdir migration if(is_null($file)){ OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND); exit; } -$file = ltrim ($file, '/'); - $parts=explode('/', $file, 2); $app=$parts[0]; switch ($app) { + case 'core': + $file = OC::$SERVERROOT .'/'. $file; + break; default: OC_Util::checkAppEnabled($app); OC_App::loadApp($app); $file = OC_App::getAppPath($app) .'/'. $parts[1]; break; - case 'core': - $file = OC::$SERVERROOT .'/'. $file; - break; } $baseuri = OC::$WEBROOT . '/remote.php/'.$service.'/'; require_once($file); -- cgit v1.2.3 From b1a7826d56bbd779ef306cebd0d9f89faa878f14 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sun, 15 Jul 2012 15:17:27 -0400 Subject: Check if user is already logged in for DAV auth, instead of logging in and creating new sessions for every request --- lib/connector/sabre/auth.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/connector/sabre/auth.php b/lib/connector/sabre/auth.php index ee680391626..99f696e3a07 100644 --- a/lib/connector/sabre/auth.php +++ b/lib/connector/sabre/auth.php @@ -31,13 +31,18 @@ class OC_Connector_Sabre_Auth extends Sabre_DAV_Auth_Backend_AbstractBasic { * @return bool */ protected function validateUserPass($username, $password){ - OC_Util::setUpFS();//login hooks may need early access to the filesystem - if(OC_User::login($username,$password)){ - OC_Util::setUpFS($username); + if (OC_User::isLoggedIn()) { + OC_Util::setupFS($username); return true; - } - else{ - return false; + } else { + OC_Util::setUpFS();//login hooks may need early access to the filesystem + if(OC_User::login($username,$password)){ + OC_Util::setUpFS($username); + return true; + } + else{ + return false; + } } } } -- cgit v1.2.3 From 72ebc2a32a80bfcca6323e2313b1a08ad07f5c54 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sun, 15 Jul 2012 15:22:31 -0400 Subject: Delete old session files, suggested by Torben Nehmer, see bug oc-736 --- lib/user.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/user.php b/lib/user.php index f1903093d6d..230efe71394 100644 --- a/lib/user.php +++ b/lib/user.php @@ -200,7 +200,7 @@ class OC_User { if( $run ){ $uid=self::checkPassword( $uid, $password ); if($uid){ - session_regenerate_id(); + session_regenerate_id(true); self::setUserId($uid); OC_Hook::emit( "OC_User", "post_login", array( "uid" => $uid, 'password'=>$password )); return true; -- cgit v1.2.3 From ccb1c57745a4cab8cf475209fa17da0db390db01 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 16 Jul 2012 19:35:40 +0200 Subject: add warning in log if OC_L10N::tA was called --- lib/l10n.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib') diff --git a/lib/l10n.php b/lib/l10n.php index de8514573d3..e7f5ffea0e4 100644 --- a/lib/l10n.php +++ b/lib/l10n.php @@ -154,8 +154,15 @@ class OC_L10N{ * * Returns the translation. If no translation is found, $textArray will be * returned. + * + * + * @deprecated deprecated since ownCloud version 5.0 + * This method will probably be removed with ownCloud 6.0 + * + * */ public function tA($textArray){ + OC_Log::write('core', 'DEPRECATED: the method tA is deprecated and will be removed soon.',OC_Log::WARN); $result = array(); foreach($textArray as $key => $text){ $result[$key] = (string)$this->t($text); -- cgit v1.2.3 From f047fdbfaa653a3f745d3911df125b02ecb2556c Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 16 Jul 2012 19:55:53 +0200 Subject: revert to using fopen for webdav instead of readfile --- lib/connector/sabre/file.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/connector/sabre/file.php b/lib/connector/sabre/file.php index e4dc8c93445..4700dbf8b89 100644 --- a/lib/connector/sabre/file.php +++ b/lib/connector/sabre/file.php @@ -42,7 +42,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D */ public function get() { - return OC_Filesystem::readfile($this->path); + return OC_Filesystem::fopen($this->path,'rb'); } -- cgit v1.2.3 From 33b8de91eacc09a4c15d4d45df0006ff80a9fb09 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 19 Jul 2012 16:31:55 +0200 Subject: allow a more flexible way of using user backends --- lib/base.php | 2 +- lib/user.php | 38 +++++++++++++++++++++----------------- 2 files changed, 22 insertions(+), 18 deletions(-) (limited to 'lib') diff --git a/lib/base.php b/lib/base.php index fe69ad70c0f..631ed4fcce6 100644 --- a/lib/base.php +++ b/lib/base.php @@ -345,7 +345,7 @@ class OC{ $_SESSION['user_id'] = ''; } - OC_User::useBackend( OC_Config::getValue( "userbackend", "database" )); + OC_User::useBackend(new OC_User_Database()); OC_Group::useBackend(new OC_Group_Database()); // Load Apps diff --git a/lib/user.php b/lib/user.php index 230efe71394..356be4decf9 100644 --- a/lib/user.php +++ b/lib/user.php @@ -50,8 +50,8 @@ class OC_User { * * Makes a list of backends that can be used by other modules */ - public static function registerBackend( $name ){ - self::$_backends[] = $name; + public static function registerBackend( $backend ){ + self::$_backends[] = $backend; return true; } @@ -83,22 +83,26 @@ class OC_User { * Set the User Authentication Module */ public static function useBackend( $backend = 'database' ){ - // You'll never know what happens - if( null === $backend OR !is_string( $backend )){ - $backend = 'database'; - } + if($backend instanceof OC_User_Backend){ + self::$_usedBackends[get_class($backend)]=$backend; + }else{ + // You'll never know what happens + if( null === $backend OR !is_string( $backend )){ + $backend = 'database'; + } - // Load backend - switch( $backend ){ - case 'database': - case 'mysql': - case 'sqlite': - self::$_usedBackends[$backend] = new OC_User_Database(); - break; - default: - $className = 'OC_USER_' . strToUpper($backend); - self::$_usedBackends[$backend] = new $className(); - break; + // Load backend + switch( $backend ){ + case 'database': + case 'mysql': + case 'sqlite': + self::$_usedBackends[$backend] = new OC_User_Database(); + break; + default: + $className = 'OC_USER_' . strToUpper($backend); + self::$_usedBackends[$backend] = new $className(); + break; + } } true; -- cgit v1.2.3 From 98e769d2693d1798c25bba0b90c1e36995cce20a Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 20 Jul 2012 00:52:10 +0200 Subject: dont use the mtimes stored in zip archives since they dont update correctly --- lib/archive/zip.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/archive/zip.php b/lib/archive/zip.php index 6631a649b16..ff405ce098b 100644 --- a/lib/archive/zip.php +++ b/lib/archive/zip.php @@ -74,8 +74,7 @@ class OC_Archive_ZIP extends OC_Archive{ * @return int */ function mtime($path){ - $stat=$this->zip->statName($path); - return $stat['mtime']; + return filemtime($this->path); } /** * get the files in a folder -- cgit v1.2.3 From 445f52ef8ba9698d21cea262a8c227ddc6564945 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 20 Jul 2012 16:35:24 +0200 Subject: dont check for filecache updates when getting quota info over webdav --- lib/connector/sabre/directory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php index b75bb5c50f5..f3f6541a8d4 100644 --- a/lib/connector/sabre/directory.php +++ b/lib/connector/sabre/directory.php @@ -146,7 +146,7 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa * @return array */ public function getQuotaInfo() { - $rootInfo=OC_FileCache::get(''); + $rootInfo=OC_FileCache_Cached::get(''); return array( $rootInfo['size'], OC_Filesystem::free_space() -- cgit v1.2.3 From 57ed83f2665ef571f5de25a65764640a38c26acd Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 20 Jul 2012 16:54:29 +0200 Subject: fix eventsource fallback when more then one eventsource is active --- lib/eventsource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/eventsource.php b/lib/eventsource.php index cf10660b94c..2a8c6b92902 100644 --- a/lib/eventsource.php +++ b/lib/eventsource.php @@ -36,7 +36,7 @@ class OC_EventSource{ header('Cache-Control: no-cache'); $this->fallback=isset($_GET['fallback']) and $_GET['fallback']=='true'; if($this->fallback){ - $fallBackId=$_GET['fallback_id']; + $this->fallBackId=$_GET['fallback_id']; header("Content-Type: text/html"); echo str_repeat(''.PHP_EOL,10); //dummy data to keep IE happy }else{ -- cgit v1.2.3 From 0e111e1a17140a8a42a3dbf2ecce41e424b2afab Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 20 Jul 2012 16:56:07 +0200 Subject: fix increasing folder sizes in filecache for custom roots --- lib/filecache.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/filecache.php b/lib/filecache.php index d956f34dc48..4b1774925c3 100644 --- a/lib/filecache.php +++ b/lib/filecache.php @@ -126,7 +126,7 @@ class OC_FileCache{ $query=OC_DB::prepare($sql); $result=$query->execute($arguments); if(OC_DB::isError($result)){ - OC_Log::write('files','error while updating file('.$path.') in cache',OC_Log::ERROR); + OC_Log::write('files','error while updating file('.$id.') in cache',OC_Log::ERROR); } } @@ -303,7 +303,7 @@ class OC_FileCache{ */ public static function increaseSize($path,$sizeDiff, $root=false){ if($sizeDiff==0) return; - $id=self::getId($path,''); + $id=self::getId($path,$root); while($id!=-1){//walk up the filetree increasing the size of all parent folders $query=OC_DB::prepare('UPDATE *PREFIX*fscache SET size=size+? WHERE id=?'); $query->execute(array($sizeDiff,$id)); -- cgit v1.2.3 From 48306a3c4f708b80143757acbe9b270be476aab4 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 20 Jul 2012 17:51:50 +0200 Subject: fix unused variables --- lib/app.php | 1 - lib/db.php | 9 ++++----- lib/filestorage.php | 2 +- lib/filesystem.php | 17 ++++++++--------- lib/filesystemview.php | 2 +- lib/helper.php | 6 +++--- lib/image.php | 9 +++------ lib/migrate.php | 2 +- lib/ocs.php | 6 +----- lib/ocsclient.php | 2 +- lib/preferences.php | 8 ++++---- lib/setup.php | 1 - lib/streamwrappers.php | 5 ----- lib/template.php | 1 - lib/templatelayout.php | 2 +- lib/util.php | 2 -- 16 files changed, 28 insertions(+), 47 deletions(-) (limited to 'lib') diff --git a/lib/app.php b/lib/app.php index caf8bd82521..2b975de9ef0 100755 --- a/lib/app.php +++ b/lib/app.php @@ -27,7 +27,6 @@ * upgrading and removing apps. */ class OC_App{ - static private $init = false; static private $activeapp = ''; static private $navigation = array(); static private $settingsForms = array(); diff --git a/lib/db.php b/lib/db.php index 2a06d72ea32..6f083d17cfb 100644 --- a/lib/db.php +++ b/lib/db.php @@ -33,8 +33,6 @@ class OC_DB { static private $MDB2=false; static private $PDO=false; static private $schema=false; - static private $affected=0; - static private $result=false; static private $inTransaction=false; static private $prefix=null; static private $type=null; @@ -222,7 +220,7 @@ class OC_DB { echo( 'can not connect to database, using '.$type.'. ('.self::$MDB2->getUserInfo().')'); OC_Log::write('core',self::$MDB2->getUserInfo(),OC_Log::FATAL); OC_Log::write('core',self::$MDB2->getMessage(),OC_Log::FATAL); - die( $error ); + die(); } // We always, really always want associative arrays @@ -519,8 +517,9 @@ class OC_DB { // Delete our temporary file unlink( $file2 ); - foreach($definition['tables'] as $name=>$table){ - self::dropTable($name); + $tables=array_keys($definition['tables']); + foreach($tables as $table){ + self::dropTable($table); } } diff --git a/lib/filestorage.php b/lib/filestorage.php index 71ef4aed00b..e786127d525 100644 --- a/lib/filestorage.php +++ b/lib/filestorage.php @@ -24,7 +24,7 @@ * Provde a common interface to all different storage options */ abstract class OC_Filestorage{ - public function __construct($parameters){} + abstract public function __construct($parameters); abstract public function mkdir($path); abstract public function rmdir($path); abstract public function opendir($path); diff --git a/lib/filesystem.php b/lib/filesystem.php index 65318fa3ab6..5b31ed6c703 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -46,9 +46,10 @@ class OC_Filesystem{ static private $storages=array(); static private $mounts=array(); - static private $storageTypes=array(); public static $loaded=false; - private $fakeRoot=''; + /** + * @var OC_Filestorage $defaultInstance + */ static private $defaultInstance; @@ -155,7 +156,8 @@ class OC_Filesystem{ } $path=str_replace('//', '/',$path); $foundMountPoint=''; - foreach(OC_Filesystem::$mounts as $mountpoint=>$storage){ + $mountPoints=array_keys(OC_Filesystem::$mounts); + foreach($mountPoints as $mountpoint){ if($mountpoint==$path){ return $mountpoint; } @@ -260,10 +262,7 @@ class OC_Filesystem{ * tear down the filesystem, removing all storage providers */ static public function tearDown(){ - foreach(self::$storages as $mountpoint=>$storage){ - unset(self::$storages[$mountpoint]); - } - $fakeRoot=''; + self::$storages=array(); } /** @@ -287,7 +286,7 @@ class OC_Filesystem{ * @return bool */ static public function chroot($fakeRoot){ - return self::$defaultInstance->chroot($path); + return self::$defaultInstance->chroot($fakeRoot); } /** @@ -485,7 +484,7 @@ class OC_Filesystem{ * @return bool */ static public function hasUpdated($path,$time){ - return self::$defaultInstance->hasUpdated($path); + return self::$defaultInstance->hasUpdated($path,$time); } } diff --git a/lib/filesystemview.php b/lib/filesystemview.php index 448663bb081..a23d7bbe7fd 100644 --- a/lib/filesystemview.php +++ b/lib/filesystemview.php @@ -393,7 +393,7 @@ class OC_FilesystemView { return $this->basicOperation('getMimeType',$path); } public function hash($type,$path){ - return $this->basicOperation('hash',$path,array('read')); + return $this->basicOperation('hash',$path,array('read'),$type); } public function free_space($path='/'){ diff --git a/lib/helper.php b/lib/helper.php index 0d18098a4e7..c4f7e8b2e19 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -676,10 +676,10 @@ class OC_Helper { */ public static function mb_str_replace($search, $replace, $subject, $encoding = 'UTF-8', &$count = null) { $offset = -1; - $length = mb_strlen($search, 'UTF-8'); - while(($i = mb_strrpos($subject, $search, $offset, 'UTF-8'))) { + $length = mb_strlen($search, $encoding); + while(($i = mb_strrpos($subject, $search, $offset, $encoding))) { $subject = OC_Helper::mb_substr_replace($subject, $replace, $i, $length); - $offset = $i - mb_strlen($subject, 'UTF-8') - 1; + $offset = $i - mb_strlen($subject, $encoding) - 1; $count++; } return $subject; diff --git a/lib/image.php b/lib/image.php index 01e843d8316..c438b3d67f6 100644 --- a/lib/image.php +++ b/lib/image.php @@ -24,8 +24,8 @@ //From user comments at http://dk2.php.net/manual/en/function.exif-imagetype.php if ( ! function_exists( 'exif_imagetype' ) ) { function exif_imagetype ( $filename ) { - if ( ( list($width, $height, $type, $attr) = getimagesize( $filename ) ) !== false ) { - return $type; + if ( ( $info = getimagesize( $filename ) ) !== false ) { + return $info[2]; } return false; } @@ -364,7 +364,7 @@ class OC_Image { public function load($imageref) { if(is_resource($imageref)) { if(get_resource_type($imageref) == 'gd') { - $this->resource = $res; + $this->resource = $imageref; return $this->resource; } elseif(in_array(get_resource_type($imageref), array('file','stream'))) { return $this->loadFromFileHandle($imageref); @@ -650,9 +650,6 @@ class OC_Image { OC_Log::write('core',__METHOD__.'(): No image loaded', OC_Log::ERROR); return false; } - $width_orig=imageSX($this->resource); - $height_orig=imageSY($this->resource); - //OC_Log::write('core',__METHOD__.'(): Original size: '.$width_orig.'x'.$height_orig, OC_Log::DEBUG); $process = imagecreatetruecolor($w, $h); if ($process == false) { OC_Log::write('core',__METHOD__.'(): Error creating true color image',OC_Log::ERROR); diff --git a/lib/migrate.php b/lib/migrate.php index f788a637d3c..1b6367ed6ec 100644 --- a/lib/migrate.php +++ b/lib/migrate.php @@ -91,7 +91,7 @@ class OC_Migrate{ if( self::$exporttype == 'user' ){ // Check user exists if( !is_null($uid) ){ - $db = new OC_User_Database; + $db = new OC_User_Database; if( !$db->userExists( $uid ) ){ OC_Log::write('migration', 'User: '.$uid.' is not in the database and so cannot be exported.', OC_Log::ERROR); return json_encode( array( 'success' => false ) ); diff --git a/lib/ocs.php b/lib/ocs.php index 1be41202d78..77dd437d6c6 100644 --- a/lib/ocs.php +++ b/lib/ocs.php @@ -88,7 +88,6 @@ class OC_OCS { $method='get'; }elseif($_SERVER['REQUEST_METHOD'] == 'PUT') { $method='put'; - parse_str(file_get_contents("php://input"),$put_vars); }elseif($_SERVER['REQUEST_METHOD'] == 'POST') { $method='post'; }else{ @@ -356,9 +355,6 @@ class OC_OCS { * @return string xml/json */ private static function apiConfig($format) { - $user=OC_OCS::checkpassword(false); - $url=substr(OCP\Util::getServerHost().$_SERVER['SCRIPT_NAME'],0,-11).''; - $xml['version']='1.5'; $xml['website']='ownCloud'; $xml['host']=OCP\Util::getServerHost(); @@ -416,7 +412,7 @@ class OC_OCS { */ private static function activityPut($format,$message) { // not implemented in ownCloud - $user=OC_OCS::checkpassword(); + OC_OCS::checkpassword(); echo(OC_OCS::generatexml($format,'ok',100,'')); } diff --git a/lib/ocsclient.php b/lib/ocsclient.php index 951d761d7e6..ae35470cff6 100644 --- a/lib/ocsclient.php +++ b/lib/ocsclient.php @@ -71,7 +71,7 @@ class OC_OCSClient{ $tmp=$data->data; $cats=array(); - foreach($tmp->category as $key=>$value) { + foreach($tmp->category as $value) { $id= (int) $value->id; $name= (string) $value->name; diff --git a/lib/preferences.php b/lib/preferences.php index f72378ce94f..c91423e69bc 100644 --- a/lib/preferences.php +++ b/lib/preferences.php @@ -165,7 +165,7 @@ class OC_Preferences{ public static function deleteKey( $user, $app, $key ){ // No need for more comments $query = OC_DB::prepare( 'DELETE FROM *PREFIX*preferences WHERE userid = ? AND appid = ? AND configkey = ?' ); - $result = $query->execute( array( $user, $app, $key )); + $query->execute( array( $user, $app, $key )); return true; } @@ -181,7 +181,7 @@ class OC_Preferences{ public static function deleteApp( $user, $app ){ // No need for more comments $query = OC_DB::prepare( 'DELETE FROM *PREFIX*preferences WHERE userid = ? AND appid = ?' ); - $result = $query->execute( array( $user, $app )); + $query->execute( array( $user, $app )); return true; } @@ -196,7 +196,7 @@ class OC_Preferences{ public static function deleteUser( $user ){ // No need for more comments $query = OC_DB::prepare( 'DELETE FROM *PREFIX*preferences WHERE userid = ?' ); - $result = $query->execute( array( $user )); + $query->execute( array( $user )); return true; } @@ -211,7 +211,7 @@ class OC_Preferences{ public static function deleteAppFromAllUsers( $app ){ // No need for more comments $query = OC_DB::prepare( 'DELETE FROM *PREFIX*preferences WHERE appid = ?' ); - $result = $query->execute( array( $app )); + $query->execute( array( $app )); return true; } diff --git a/lib/setup.php b/lib/setup.php index 027c84db092..4d71bed86e2 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -102,7 +102,6 @@ class OC_Setup { } else { $oldUser=OC_Config::getValue('dbuser', false); - $oldPassword=OC_Config::getValue('dbpassword', false); $query="SELECT user FROM mysql.user WHERE user='$dbuser'"; //this should be enough to check for admin rights in mysql if(mysql_query($query, $connection)) { diff --git a/lib/streamwrappers.php b/lib/streamwrappers.php index f1e0fa0e1d9..f502c6170bd 100644 --- a/lib/streamwrappers.php +++ b/lib/streamwrappers.php @@ -1,6 +1,4 @@ name=substr($path,strlen('fakedir://')); $this->index=0; if(!isset(self::$dirs[$this->name])){ @@ -161,7 +157,6 @@ class OC_StaticStreamWrapper { public function stream_write($data) { if (!$this->writable) return 0; $size = strlen($data); - $len = strlen(self::$data[$this->path]); if ($this->stream_eof()) { self::$data[$this->path] .= $data; } else { diff --git a/lib/template.php b/lib/template.php index 3b48c27b9b4..5b6999af533 100644 --- a/lib/template.php +++ b/lib/template.php @@ -82,7 +82,6 @@ function relative_modified_date($timestamp) { $diffhours = round($diffminutes/60); $diffdays = round($diffhours/24); $diffmonths = round($diffdays/31); - $diffyears = round($diffdays/365); if($timediff < 60) { return $l->t('seconds ago'); } else if($timediff < 120) { return $l->t('1 minute ago'); } diff --git a/lib/templatelayout.php b/lib/templatelayout.php index d33a87e9e4c..588a7845997 100644 --- a/lib/templatelayout.php +++ b/lib/templatelayout.php @@ -123,7 +123,7 @@ class OC_TemplateLayout extends OC_Template { elseif(self::appendIfExist($files, $apps_dir['path'], $apps_dir['url'], "$style.css")) { $append =true; break; } } if(! $append) { - echo('css file not found: style:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); + echo('css file not found: style:'.$style.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); die(); } } diff --git a/lib/util.php b/lib/util.php index 2a7b8a922f9..f35e5a18e42 100755 --- a/lib/util.php +++ b/lib/util.php @@ -189,8 +189,6 @@ class OC_Util { if(!(is_callable('sqlite_open') or class_exists('SQLite3')) and !is_callable('mysql_connect') and !is_callable('pg_connect')){ $errors[]=array('error'=>'No database drivers (sqlite, mysql, or postgresql) installed.
','hint'=>'');//TODO: sane hint } - $CONFIG_DBTYPE = OC_Config::getValue( "dbtype", "sqlite" ); - $CONFIG_DBNAME = OC_Config::getValue( "dbname", "owncloud" ); //common hint for all file permissons error messages $permissionsHint="Permissions can usually be fixed by giving the webserver write access to the ownCloud directory"; -- cgit v1.2.3 From 39086ef63e451871dfd9778f64cdbc4df142bd19 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 20 Jul 2012 17:57:51 +0200 Subject: dont try to create mountpoints automatically --- lib/filesystem.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'lib') diff --git a/lib/filesystem.php b/lib/filesystem.php index 5b31ed6c703..148656be00f 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -319,9 +319,6 @@ class OC_Filesystem{ if(substr($mountpoint,-1)!=='/'){ $mountpoint=$mountpoint.'/'; } - if (self::getView() != null && $mountpoint != '/' && !self::is_dir(basename($mountpoint))) { - self::mkdir(basename($mountpoint)); - } self::$mounts[$mountpoint]=array('class'=>$class,'arguments'=>$arguments); } -- cgit v1.2.3 From 7152b8b4ee2f0d4de640868b614992e8aaf00803 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 20 Jul 2012 18:32:40 +0200 Subject: remove unused and depricated getFolderSize --- apps/files_sharing/sharedstorage.php | 31 +------------------------------ lib/filestorage/local.php | 12 +----------- 2 files changed, 2 insertions(+), 41 deletions(-) (limited to 'lib') diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 4138fc2b399..e1c6e8f2eba 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -190,7 +190,7 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common { public function filesize($path) { if ($path == "" || $path == "/" || $this->is_dir($path)) { - return $this->getFolderSize($path); + return 0; } else { $source = $this->getSource($path); if ($source) { @@ -200,35 +200,6 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common { } } - public function getFolderSize($path) { - return 0; //depricated - } - - private function calculateFolderSize($path) { - if ($this->is_file($path)) { - $path = dirname($path); - } - $size = 0; - if ($dh = $this->opendir($path)) { - while (($filename = readdir($dh)) !== false) { - if ($filename != "." && $filename != "..") { - $subFile = $path."/".$filename; - if ($this->is_file($subFile)) { - $size += $this->filesize($subFile); - } else { - $size += $this->getFolderSize($subFile); - } - } - } - if ($size > 0) { - $dbpath = rtrim($this->datadir.$path, "/"); -// $query = OCP\DB::prepare("INSERT INTO *PREFIX*foldersize VALUES(?,?)"); -// $result = $query->execute(array($dbpath, $size)); - } - } - return $size; - } - private function clearFolderSizeCache($path) { $path = rtrim($path, "/"); $path = preg_replace('{(/)\1+}', "/", $path); diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php index b2eba051515..0ed184c8025 100644 --- a/lib/filestorage/local.php +++ b/lib/filestorage/local.php @@ -4,7 +4,6 @@ */ class OC_Filestorage_Local extends OC_Filestorage_Common{ protected $datadir; - private static $mimetypes=null; public function __construct($arguments){ $this->datadir=$arguments['datadir']; if(substr($this->datadir,-1)!=='/'){ @@ -41,7 +40,7 @@ class OC_Filestorage_Local extends OC_Filestorage_Common{ } public function filesize($path){ if($this->is_dir($path)){ - return $this->getFolderSize($path); + return 0; }else{ return filesize($this->datadir.$path); } @@ -186,15 +185,6 @@ class OC_Filestorage_Local extends OC_Filestorage_Common{ return $files; } - /** - * @brief get the size of folder and it's content - * @param string $path file path - * @return int size of folder and it's content - */ - public function getFolderSize($path){ - return 0;//depricated, use OC_FileCach instead - } - /** * check if a file or folder has been updated since $time * @param int $time -- cgit v1.2.3 From c9be9ab251681d96cfb620ca26778ba0005023d3 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 20 Jul 2012 18:56:18 +0200 Subject: remove unused variables --- apps/files_encryption/lib/cryptstream.php | 3 --- apps/files_external/lib/smb.php | 2 -- apps/files_external/tests/ftp.php | 1 - apps/files_external/tests/google.php | 1 - apps/files_external/tests/smb.php | 1 - apps/files_external/tests/swift.php | 1 - apps/files_external/tests/webdav.php | 1 - apps/gallery/lib/album.php | 2 +- apps/gallery/lib/managers.php | 1 - apps/gallery/lib/tiles.php | 2 +- apps/media/lib_ampache.php | 1 - apps/media/lib_collection.php | 3 +-- apps/media/lib_media.php | 6 +++--- apps/remoteStorage/lib_remoteStorage.php | 13 ++++++------- lib/archive/zip.php | 1 - lib/filecache/update.php | 1 - lib/filestorage/common.php | 2 +- lib/group/database.php | 5 ++--- lib/group/dummy.php | 3 ++- lib/group/example.php | 18 +++++++++--------- lib/public/app.php | 22 ---------------------- lib/search/provider.php | 10 +++++++--- lib/user/database.php | 8 +++----- lib/user/example.php | 12 +++--------- tests/lib/user/database.php | 1 - 25 files changed, 39 insertions(+), 82 deletions(-) (limited to 'lib') diff --git a/apps/files_encryption/lib/cryptstream.php b/apps/files_encryption/lib/cryptstream.php index e0020537563..46471911d94 100644 --- a/apps/files_encryption/lib/cryptstream.php +++ b/apps/files_encryption/lib/cryptstream.php @@ -31,9 +31,7 @@ class OC_CryptStream{ public static $sourceStreams=array(); private $source; private $path; - private $readBuffer;//for streams that dont support seeking private $meta=array();//header/meta for source stream - private $count; private $writeCache; private $size; private static $rootView; @@ -100,7 +98,6 @@ class OC_CryptStream{ public function stream_write($data){ $length=strlen($data); - $written=0; $currentPos=ftell($this->source); if($this->writeCache){ $data=$this->writeCache.$data; diff --git a/apps/files_external/lib/smb.php b/apps/files_external/lib/smb.php index 5e34deb2337..8a5e993b1d0 100644 --- a/apps/files_external/lib/smb.php +++ b/apps/files_external/lib/smb.php @@ -15,8 +15,6 @@ class OC_FileStorage_SMB extends OC_FileStorage_StreamWrapper{ private $root; private $share; - private static $tempFiles=array(); - public function __construct($params){ $this->host=$params['host']; $this->user=$params['user']; diff --git a/apps/files_external/tests/ftp.php b/apps/files_external/tests/ftp.php index 68481b4e66b..97796bca128 100644 --- a/apps/files_external/tests/ftp.php +++ b/apps/files_external/tests/ftp.php @@ -13,7 +13,6 @@ if(!is_array($config) or !isset($config['ftp']) or !$config['ftp']['run']){ }else{ class Test_Filestorage_FTP extends Test_FileStorage { private $config; - private $id; public function setUp(){ $id=uniqid(); diff --git a/apps/files_external/tests/google.php b/apps/files_external/tests/google.php index 08116f0e748..806db5a6aaa 100644 --- a/apps/files_external/tests/google.php +++ b/apps/files_external/tests/google.php @@ -28,7 +28,6 @@ if(!is_array($config) or !isset($config['google']) or !$config['google']['run']) class Test_Filestorage_Google extends Test_FileStorage { private $config; - private $id; public function setUp(){ $id=uniqid(); diff --git a/apps/files_external/tests/smb.php b/apps/files_external/tests/smb.php index e1495b7480d..001ef842276 100644 --- a/apps/files_external/tests/smb.php +++ b/apps/files_external/tests/smb.php @@ -14,7 +14,6 @@ if(!is_array($config) or !isset($config['smb']) or !$config['smb']['run']){ }else{ class Test_Filestorage_SMB extends Test_FileStorage { private $config; - private $id; public function setUp(){ $id=uniqid(); diff --git a/apps/files_external/tests/swift.php b/apps/files_external/tests/swift.php index f0bde6ed605..1520c9473d3 100644 --- a/apps/files_external/tests/swift.php +++ b/apps/files_external/tests/swift.php @@ -13,7 +13,6 @@ if(!is_array($config) or !isset($config['swift']) or !$config['swift']['run']){ }else{ class Test_Filestorage_SWIFT extends Test_FileStorage { private $config; - private $id; public function setUp(){ $id=uniqid(); diff --git a/apps/files_external/tests/webdav.php b/apps/files_external/tests/webdav.php index 144659819b6..14abbef2cbf 100644 --- a/apps/files_external/tests/webdav.php +++ b/apps/files_external/tests/webdav.php @@ -13,7 +13,6 @@ if(!is_array($config) or !isset($config['webdav']) or !$config['webdav']['run']) }else{ class Test_Filestorage_DAV extends Test_FileStorage { private $config; - private $id; public function setUp(){ $id=uniqid(); diff --git a/apps/gallery/lib/album.php b/apps/gallery/lib/album.php index 39d6d3aded1..701949d4d80 100644 --- a/apps/gallery/lib/album.php +++ b/apps/gallery/lib/album.php @@ -58,7 +58,7 @@ class OC_Gallery_Album { return $stmt->execute($args); } - public static function removeByName($owner, $name) { self::remove($ownmer, $name); } + public static function removeByName($owner, $name) { self::remove($owner, $name); } public static function removeByPath($owner, $path) { self::remove($owner, null, $path); } public static function removeByParentPath($owner, $parent) { self::remove($owner, null, null, $parent); } diff --git a/apps/gallery/lib/managers.php b/apps/gallery/lib/managers.php index b6ade3d1b1e..575d962dbe3 100644 --- a/apps/gallery/lib/managers.php +++ b/apps/gallery/lib/managers.php @@ -29,7 +29,6 @@ class DatabaseManager { $stmt = \OCP\DB::prepare('INSERT INTO *PREFIX*pictures_images_cache (uid_owner, path, width, height) VALUES (?, ?, ?, ?)'); $stmt->execute(array(\OCP\USER::getUser(), $path, $width, $height)); $ret = array('path' => $path, 'width' => $width, 'height' => $height); - unset($image); $dir = dirname($path); $this->cache[$dir][$path] = $ret; return $ret; diff --git a/apps/gallery/lib/tiles.php b/apps/gallery/lib/tiles.php index 754734e609e..e36d26d3191 100644 --- a/apps/gallery/lib/tiles.php +++ b/apps/gallery/lib/tiles.php @@ -33,7 +33,7 @@ class TilesLine { } public function setAvailableSpace($space) { - $available_space = $space; + $this->available_space = $space; } public function getTilesCount() { diff --git a/apps/media/lib_ampache.php b/apps/media/lib_ampache.php index d35cca150b2..d5a093338cc 100644 --- a/apps/media/lib_ampache.php +++ b/apps/media/lib_ampache.php @@ -271,7 +271,6 @@ class OC_MEDIA_AMPACHE{ "); return; } - global $SITEROOT; $filter=$params['filter']; $albums=OC_MEDIA_COLLECTION::getAlbums($filter); $artist=OC_MEDIA_COLLECTION::getArtistName($filter); diff --git a/apps/media/lib_collection.php b/apps/media/lib_collection.php index e65930f551d..cacab8e959f 100644 --- a/apps/media/lib_collection.php +++ b/apps/media/lib_collection.php @@ -27,7 +27,6 @@ class OC_MEDIA_COLLECTION{ public static $uid; private static $artistIdCache=array(); private static $albumIdCache=array(); - private static $songIdCache=array(); private static $queries=array(); /** @@ -152,7 +151,7 @@ class OC_MEDIA_COLLECTION{ return $artistId; }else{ $query=OCP\DB::prepare("INSERT INTO `*PREFIX*media_artists` (`artist_name`) VALUES (?)"); - $result=$query->execute(array($name)); + $query->execute(array($name)); return self::getArtistId($name);; } } diff --git a/apps/media/lib_media.php b/apps/media/lib_media.php index 9e687a4af2c..54502f42575 100644 --- a/apps/media/lib_media.php +++ b/apps/media/lib_media.php @@ -27,12 +27,12 @@ class OC_MEDIA{ * @param array $params, parameters passed from OC_Hook */ public static function loginListener($params){ - if(isset($_POST['user']) and $_POST['password']){ - $name=$_POST['user']; + if(isset($params['uid']) and $params['password']){ + $name=$params['uid']; $query=OCP\DB::prepare("SELECT user_id from *PREFIX*media_users WHERE user_id LIKE ?"); $uid=$query->execute(array($name))->fetchAll(); if(count($uid)==0){ - $password=hash('sha256',$_POST['password']); + $password=hash('sha256',$params['password']); $query=OCP\DB::prepare("INSERT INTO *PREFIX*media_users (user_id, user_password_sha256) VALUES (?, ?);"); $query->execute(array($name,$password)); } diff --git a/apps/remoteStorage/lib_remoteStorage.php b/apps/remoteStorage/lib_remoteStorage.php index 42cd9c90f64..c1765640c5d 100644 --- a/apps/remoteStorage/lib_remoteStorage.php +++ b/apps/remoteStorage/lib_remoteStorage.php @@ -17,12 +17,11 @@ class OC_remoteStorage { $user=OCP\USER::getUser(); $query=OCP\DB::prepare("SELECT token FROM *PREFIX*authtoken WHERE user=? AND appUrl=? AND category=? LIMIT 1"); $result=$query->execute(array($user, $appUrl, $categories)); - $ret = array(); if($row=$result->fetchRow()) { - return base64_encode('remoteStorage:'.$row['token']); - } else { - return false; - } + return base64_encode('remoteStorage:'.$row['token']); + } else { + return false; + } } public static function getAllTokens() { @@ -42,13 +41,13 @@ class OC_remoteStorage { public static function deleteToken($token) { $user=OCP\USER::getUser(); $query=OCP\DB::prepare("DELETE FROM *PREFIX*authtoken WHERE token=? AND user=?"); - $result=$query->execute(array($token,$user)); + $query->execute(array($token,$user)); return 'unknown';//how can we see if any rows were affected? } private static function addToken($token, $appUrl, $categories){ $user=OCP\USER::getUser(); $query=OCP\DB::prepare("INSERT INTO *PREFIX*authtoken (`token`,`appUrl`,`user`,`category`) VALUES(?,?,?,?)"); - $result=$query->execute(array($token,$appUrl,$user,$categories)); + $query->execute(array($token,$appUrl,$user,$categories)); } public static function createCategories($appUrl, $categories) { $token=uniqid(); diff --git a/lib/archive/zip.php b/lib/archive/zip.php index ff405ce098b..b2d6674d639 100644 --- a/lib/archive/zip.php +++ b/lib/archive/zip.php @@ -11,7 +11,6 @@ class OC_Archive_ZIP extends OC_Archive{ * @var ZipArchive zip */ private $zip=null; - private $success=false; private $path; function __construct($source){ diff --git a/lib/filecache/update.php b/lib/filecache/update.php index dd77f491ca0..93b632acb4e 100644 --- a/lib/filecache/update.php +++ b/lib/filecache/update.php @@ -207,7 +207,6 @@ class OC_FileCache_Update{ $cached=OC_FileCache_Cached::get($oldPath,$root); $oldSize=$cached['size']; - $size=$view->filesize($newPath); OC_FileCache::increaseSize(dirname($oldPath),-$oldSize,$root); OC_FileCache::increaseSize(dirname($newPath),$oldSize,$root); OC_FileCache::move($oldPath,$newPath); diff --git a/lib/filestorage/common.php b/lib/filestorage/common.php index ba78fca80e5..fd389d3e2d7 100644 --- a/lib/filestorage/common.php +++ b/lib/filestorage/common.php @@ -220,7 +220,7 @@ abstract class OC_Filestorage_Common extends OC_Filestorage { } $tmpFile=OC_Helper::tmpFile($extension); $target=fopen($tmpFile,'w'); - $count=OC_Helper::streamCopy($source,$target); + OC_Helper::streamCopy($source,$target); return $tmpFile; } // abstract public function touch($path, $mtime=null); diff --git a/lib/group/database.php b/lib/group/database.php index fb173665eb8..2770ec185c4 100644 --- a/lib/group/database.php +++ b/lib/group/database.php @@ -41,7 +41,6 @@ * Class for group management in a SQL Database (e.g. MySQL, SQLite) */ class OC_Group_Database extends OC_Group_Backend { - private $userGroupCache=array(); /** * @brief Try to create a new group @@ -116,7 +115,7 @@ class OC_Group_Database extends OC_Group_Backend { // No duplicate entries! if( !$this->inGroup( $uid, $gid )){ $query = OC_DB::prepare( "INSERT INTO `*PREFIX*group_user` ( `uid`, `gid` ) VALUES( ?, ? )" ); - $result = $query->execute( array( $uid, $gid )); + $query->execute( array( $uid, $gid )); return true; }else{ return false; @@ -133,7 +132,7 @@ class OC_Group_Database extends OC_Group_Backend { */ public function removeFromGroup( $uid, $gid ){ $query = OC_DB::prepare( "DELETE FROM *PREFIX*group_user WHERE uid = ? AND gid = ?" ); - $result = $query->execute( array( $uid, $gid )); + $query->execute( array( $uid, $gid )); return true; } diff --git a/lib/group/dummy.php b/lib/group/dummy.php index 0825b10708a..1243891023f 100644 --- a/lib/group/dummy.php +++ b/lib/group/dummy.php @@ -126,7 +126,8 @@ class OC_Group_Dummy extends OC_Group_Backend { */ public function getUserGroups($uid){ $groups=array(); - foreach($this->groups as $group=>$user){ + $allGroups=array_keys($this->groups); + foreach($allGroups as $group){ if($this->inGroup($uid,$group)){ $groups[]=$group; } diff --git a/lib/group/example.php b/lib/group/example.php index c18562db7a4..f9c62fb9789 100644 --- a/lib/group/example.php +++ b/lib/group/example.php @@ -34,7 +34,7 @@ abstract class OC_Group_Example { * Trys to create a new group. If the group name already exists, false will * be returned. */ - public static function createGroup($gid){} + abstract public static function createGroup($gid); /** * @brief delete a group @@ -43,7 +43,7 @@ abstract class OC_Group_Example { * * Deletes a group and removes it from the group_user-table */ - public static function deleteGroup($gid){} + abstract public static function deleteGroup($gid); /** * @brief is user in group? @@ -53,7 +53,7 @@ abstract class OC_Group_Example { * * Checks whether the user is member of a group or not. */ - public static function inGroup($uid, $gid){} + abstract public static function inGroup($uid, $gid); /** * @brief Add a user to a group @@ -63,7 +63,7 @@ abstract class OC_Group_Example { * * Adds a user to a group. */ - public static function addToGroup($uid, $gid){} + abstract public static function addToGroup($uid, $gid); /** * @brief Removes a user from a group @@ -73,7 +73,7 @@ abstract class OC_Group_Example { * * removes the user from a group. */ - public static function removeFromGroup($uid,$gid){} + abstract public static function removeFromGroup($uid,$gid); /** * @brief Get all groups a user belongs to @@ -83,7 +83,7 @@ abstract class OC_Group_Example { * This function fetches all groups a user belongs to. It does not check * if the user exists at all. */ - public static function getUserGroups($uid){} + abstract public static function getUserGroups($uid); /** * @brief get a list of all groups @@ -91,19 +91,19 @@ abstract class OC_Group_Example { * * Returns a list with all groups */ - public static function getGroups(){} + abstract public static function getGroups(); /** * check if a group exists * @param string $gid * @return bool */ - public function groupExists($gid){} + public function groupExists($gid); /** * @brief get a list of all users in a group * @returns array with user ids */ - public static function usersInGroup($gid){} + abstract public static function usersInGroup($gid); } diff --git a/lib/public/app.php b/lib/public/app.php index 38c51af9cdb..28411933beb 100644 --- a/lib/public/app.php +++ b/lib/public/app.php @@ -34,28 +34,6 @@ namespace OCP; * This class provides functions to manage apps in ownCloud */ class App { - - /** - * @brief Makes owncloud aware of this app - * @brief This call is deprecated and not necessary to use. - * @param $data array with all information - * @returns true/false - * - * This function registers the application. $data is an associative array. - * The following keys are required: - * - id: id of the application, has to be unique ('addressbook') - * - name: Human readable name ('Addressbook') - * - version: array with Version (major, minor, bugfix) ( array(1, 0, 2)) - * - * The following keys are optional: - * - order: integer, that influences the position of your application in - * a list of applications. Lower values come first. - * - */ - public static function register( $data ){ - } - - /** * @brief adds an entry to the navigation * @param $data array containing the data diff --git a/lib/search/provider.php b/lib/search/provider.php index 838ab696d04..b3ee79b4770 100644 --- a/lib/search/provider.php +++ b/lib/search/provider.php @@ -2,13 +2,17 @@ /** * provides search functionalty */ -class OC_Search_Provider { - public function __construct($options){} +abstract class OC_Search_Provider { + private $options; + + public function __construct($options){ + $this->options=$options; + } /** * search for $query * @param string $query * @return array An array of OC_Search_Result's */ - public function search($query){} + abstract public function search($query); } diff --git a/lib/user/database.php b/lib/user/database.php index a48b8357d64..cc27b3ddbfd 100644 --- a/lib/user/database.php +++ b/lib/user/database.php @@ -39,7 +39,6 @@ require_once 'phpass/PasswordHash.php'; * Class for user management in a SQL Database (e.g. MySQL, SQLite) */ class OC_User_Database extends OC_User_Backend { - static private $userGroupCache=array(); /** * @var PasswordHash */ @@ -87,7 +86,7 @@ class OC_User_Database extends OC_User_Backend { public function deleteUser( $uid ){ // Delete user-group-relation $query = OC_DB::prepare( "DELETE FROM `*PREFIX*users` WHERE uid = ?" ); - $result = $query->execute( array( $uid )); + $query->execute( array( $uid )); return true; } @@ -104,11 +103,10 @@ class OC_User_Database extends OC_User_Backend { $hasher=$this->getHasher(); $hash = $hasher->HashPassword($password.OC_Config::getValue('passwordsalt', '')); $query = OC_DB::prepare( "UPDATE *PREFIX*users SET password = ? WHERE uid = ?" ); - $result = $query->execute( array( $hash, $uid )); + $query->execute( array( $hash, $uid )); return true; - } - else{ + }else{ return false; } } diff --git a/lib/user/example.php b/lib/user/example.php index 7f3fd1b8578..77246d8136c 100644 --- a/lib/user/example.php +++ b/lib/user/example.php @@ -35,9 +35,7 @@ abstract class OC_User_Example extends OC_User_Backend { * Creates a new user. Basic checking of username is done in OC_User * itself, not in its subclasses. */ - public function createUser($uid, $password){ - return OC_USER_BACKEND_NOT_IMPLEMENTED; - } + abstract public function createUser($uid, $password); /** * @brief Set password @@ -47,9 +45,7 @@ abstract class OC_User_Example extends OC_User_Backend { * * Change the password of a user */ - public function setPassword($uid, $password){ - return OC_USER_BACKEND_NOT_IMPLEMENTED; - } + abstract public function setPassword($uid, $password); /** * @brief Check if the password is correct @@ -60,7 +56,5 @@ abstract class OC_User_Example extends OC_User_Backend { * Check if the password is correct without logging in the user * returns the user id or false */ - public function checkPassword($uid, $password){ - return OC_USER_BACKEND_NOT_IMPLEMENTED; - } + abstract public function checkPassword($uid, $password); } diff --git a/tests/lib/user/database.php b/tests/lib/user/database.php index b2fcce93c5b..f484ffa78f7 100644 --- a/tests/lib/user/database.php +++ b/tests/lib/user/database.php @@ -21,7 +21,6 @@ */ class Test_User_Database extends Test_User_Backend { - private $user=array(); /** * get a new unique user name * test cases can override this in order to clean up created user -- cgit v1.2.3 From d393638cc89d029ce07688c98ee4a16161f8d8ab Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 20 Jul 2012 19:03:33 +0200 Subject: forgot to make one function abstract --- lib/group/example.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/group/example.php b/lib/group/example.php index f9c62fb9789..9c9ece5ac77 100644 --- a/lib/group/example.php +++ b/lib/group/example.php @@ -98,7 +98,7 @@ abstract class OC_Group_Example { * @param string $gid * @return bool */ - public function groupExists($gid); + abstract public function groupExists($gid); /** * @brief get a list of all users in a group -- cgit v1.2.3 From 10337c059c7eb822944973b6febe8234cbbbca3e Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Fri, 20 Jul 2012 20:15:00 +0200 Subject: Added some documentation for OCP\JSON::callCheck() --- lib/public/json.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lib') diff --git a/lib/public/json.php b/lib/public/json.php index 1bc1e3ab4d5..19c563ed83f 100644 --- a/lib/public/json.php +++ b/lib/public/json.php @@ -55,6 +55,21 @@ class JSON { /** * @brief Check an ajax get/post call if the request token is valid. + * + * This method checks for a valid variable 'requesttoken' in $_GET, + * $_POST and $_SERVER. If a valid token is not found, an json error + * response will be return and the method will exit from execution + * of the script. + * The returned json will be in the format: + * + * {"status":"error","data":{"message":"Token expired. Please reload page."}} + * + * Add this call to the start of all ajax method files that creates, + * updates or deletes anything. + * In cases where you e.g. use an ajax call to load a dialog containing + * a submittable form, you will need to add the requesttoken first as a + * parameter to the ajax call, then assign it to the template and finally + * add a hidden input field also named 'requesttoken' containing the value. * @return json Error msg if not valid. */ public static function callCheck(){ -- cgit v1.2.3 From de8ed98541936d2e109bcdc99875637d671c1bcd Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Fri, 20 Jul 2012 21:20:51 +0200 Subject: Added some more documentation to OCP\JSON. --- lib/public/json.php | 65 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/public/json.php b/lib/public/json.php index 19c563ed83f..d639de01757 100644 --- a/lib/public/json.php +++ b/lib/public/json.php @@ -47,22 +47,34 @@ class JSON { /** - * @brief Check if the user is logged in, send json error msg if not - */ + * Check if the user is logged in, send json error msg if not. + * + * This method checks if a user is logged in. If not, a json error + * response will be return and the method will exit from execution + * of the script. + * The returned json will be in the format: + * + * {"status":"error","data":{"message":"Authentication error."}} + * + * Add this call to the start of all ajax method files that requires + * an authenticated user. + * + * @return json Error msg if not valid. + */ public static function checkLoggedIn(){ return(\OC_JSON::checkLoggedIn()); } /** - * @brief Check an ajax get/post call if the request token is valid. + * Check an ajax get/post call if the request token is valid. * * This method checks for a valid variable 'requesttoken' in $_GET, - * $_POST and $_SERVER. If a valid token is not found, an json error + * $_POST and $_SERVER. If a valid token is not found, a json error * response will be return and the method will exit from execution * of the script. * The returned json will be in the format: * - * {"status":"error","data":{"message":"Token expired. Please reload page."}} + * {"status":"error","data":{"message":"Token expired. Please reload page."}} * * Add this call to the start of all ajax method files that creates, * updates or deletes anything. @@ -70,6 +82,7 @@ class JSON { * a submittable form, you will need to add the requesttoken first as a * parameter to the ajax call, then assign it to the template and finally * add a hidden input field also named 'requesttoken' containing the value. + * * @return json Error msg if not valid. */ public static function callCheck(){ @@ -86,8 +99,22 @@ class JSON { /** - * @brief Send json error msg + * Send json error msg + * + * Return a json error message with optional extra data for + * error message or app specific data. + * + * Example use: + * + * $id = [some value] + * OCP\JSON::error(array('data':array('message':'An error happened', 'id': $id))); + * + * Will return the json formatted string: + * + * {"status":"error","data":{"message":"An error happened", "id":[some value]}} + * * @param array $data The data to use + * @return json formatted error string. */ public static function error( $data = array() ){ return(\OC_JSON::error( $data )); @@ -104,7 +131,18 @@ class JSON { /** - * @brief Check if the App is enabled and send JSON error message instead + * Check if the App is enabled and send JSON error message instead + * + * This method checks if a specific app is enabled. If not, a json error + * response will be return and the method will exit from execution + * of the script. + * The returned json will be in the format: + * + * {"status":"error","data":{"message":"Application is not enabled."}} + * + * Add this call to the start of all ajax method files that requires + * a specific app to be enabled. + * * @param string $app The app to check */ public static function checkAppEnabled( $app ){ @@ -113,7 +151,18 @@ class JSON { /** - * @brief Check if the user is a admin, send json error msg if not + * Check if the user is a admin, send json error msg if not + * + * This method checks if the current user has admin rights. If not, a json error + * response will be return and the method will exit from execution + * of the script. + * The returned json will be in the format: + * + * {"status":"error","data":{"message":"Authentication error."}} + * + * Add this call to the start of all ajax method files that requires + * administrative rights. + * */ public static function checkAdminUser(){ return(\OC_JSON::checkAdminUser()); -- cgit v1.2.3 From 29d16f61fae1a1a658ae1edc35f3dd15ca582ca7 Mon Sep 17 00:00:00 2001 From: Tom Needham Date: Fri, 20 Jul 2012 19:27:51 +0000 Subject: Fix strict standards warnings --- lib/MDB2/Driver/sqlite3.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/MDB2/Driver/sqlite3.php b/lib/MDB2/Driver/sqlite3.php index 25927aff637..6bfccadad9a 100644 --- a/lib/MDB2/Driver/sqlite3.php +++ b/lib/MDB2/Driver/sqlite3.php @@ -1221,7 +1221,7 @@ class MDB2_Statement_sqlite3 extends MDB2_Statement_Common return $affected_rows; } - $result =& $this->db->_wrapResult($result, $this->result_types, + $result = $this->db->_wrapResult($result, $this->result_types, $result_class, $result_wrap_class, $this->limit, $this->offset); $this->db->debug($this->query, 'execute', array('is_manip' => $this->is_manip, 'when' => 'post', 'result' => $result)); return $result; -- cgit v1.2.3 From 0af454a23bed216ffb21c2d0398e79648c688bcb Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Fri, 20 Jul 2012 23:11:06 +0200 Subject: Trying to get documentation to "Do The Right Thing" (TM) --- lib/public/json.php | 143 +++++++++++++++++++++++++++------------------------- 1 file changed, 73 insertions(+), 70 deletions(-) (limited to 'lib') diff --git a/lib/public/json.php b/lib/public/json.php index d639de01757..99df79173eb 100644 --- a/lib/public/json.php +++ b/lib/public/json.php @@ -35,69 +35,72 @@ namespace OCP; */ class JSON { - /** * @brief Encode and print $data in JSON format * @param array $data The data to use * @param string $setContentType the optional content type + * @return string json formatted string. */ public static function encodedPrint( $data, $setContentType=true ){ return(\OC_JSON::encodedPrint( $data, $setContentType )); } - /** - * Check if the user is logged in, send json error msg if not. - * - * This method checks if a user is logged in. If not, a json error - * response will be return and the method will exit from execution - * of the script. - * The returned json will be in the format: - * - * {"status":"error","data":{"message":"Authentication error."}} - * - * Add this call to the start of all ajax method files that requires - * an authenticated user. - * - * @return json Error msg if not valid. - */ + * Check if the user is logged in, send json error msg if not. + * + * This method checks if a user is logged in. If not, a json error + * response will be return and the method will exit from execution + * of the script. + * The returned json will be in the format: + * + * {"status":"error","data":{"message":"Authentication error."}} + * + * Add this call to the start of all ajax method files that requires + * an authenticated user. + * + * @return string json formatted error string if not authenticated. + */ public static function checkLoggedIn(){ return(\OC_JSON::checkLoggedIn()); } /** - * Check an ajax get/post call if the request token is valid. - * - * This method checks for a valid variable 'requesttoken' in $_GET, - * $_POST and $_SERVER. If a valid token is not found, a json error - * response will be return and the method will exit from execution - * of the script. - * The returned json will be in the format: - * - * {"status":"error","data":{"message":"Token expired. Please reload page."}} - * - * Add this call to the start of all ajax method files that creates, - * updates or deletes anything. - * In cases where you e.g. use an ajax call to load a dialog containing - * a submittable form, you will need to add the requesttoken first as a - * parameter to the ajax call, then assign it to the template and finally - * add a hidden input field also named 'requesttoken' containing the value. - * - * @return json Error msg if not valid. - */ + * Check an ajax get/post call if the request token is valid. + * + * This method checks for a valid variable 'requesttoken' in $_GET, + * $_POST and $_SERVER. If a valid token is not found, a json error + * response will be return and the method will exit from execution + * of the script. + * The returned json will be in the format: + * + * {"status":"error","data":{"message":"Token expired. Please reload page."}} + * + * Add this call to the start of all ajax method files that creates, + * updates or deletes anything. + * In cases where you e.g. use an ajax call to load a dialog containing + * a submittable form, you will need to add the requesttoken first as a + * parameter to the ajax call, then assign it to the template and finally + * add a hidden input field also named 'requesttoken' containing the value. + * + * @return string json formatted error string if not valid. + */ public static function callCheck(){ return(\OC_JSON::callCheck()); } /** - * @brief Send json success msg + * Send json success msg + * + * Return a json success message with optional extra data. + * @see OCP\JSON::error() for the format to use. + * * @param array $data The data to use + * @return string json formatted string. */ public static function success( $data = array() ){ return(\OC_JSON::success( $data )); } - /** * Send json error msg * @@ -114,55 +117,55 @@ class JSON { * {"status":"error","data":{"message":"An error happened", "id":[some value]}} * * @param array $data The data to use - * @return json formatted error string. + * @return string json formatted error string. */ public static function error( $data = array() ){ return(\OC_JSON::error( $data )); } - /** - * @brief set Content-Type header to jsonrequest - * @param array $type The contwnt type header - */ + * @brief set Content-Type header to jsonrequest + * @param array $type The contwnt type header + * @return string json formatted string. + */ public static function setContentTypeHeader( $type='application/json' ){ return(\OC_JSON::setContentTypeHeader( $type )); } - /** - * Check if the App is enabled and send JSON error message instead - * - * This method checks if a specific app is enabled. If not, a json error - * response will be return and the method will exit from execution - * of the script. - * The returned json will be in the format: - * - * {"status":"error","data":{"message":"Application is not enabled."}} - * - * Add this call to the start of all ajax method files that requires - * a specific app to be enabled. - * - * @param string $app The app to check - */ + * Check if the App is enabled and send JSON error message instead + * + * This method checks if a specific app is enabled. If not, a json error + * response will be return and the method will exit from execution + * of the script. + * The returned json will be in the format: + * + * {"status":"error","data":{"message":"Application is not enabled."}} + * + * Add this call to the start of all ajax method files that requires + * a specific app to be enabled. + * + * @param string $app The app to check + * @return string json formatted string if not enabled. + */ public static function checkAppEnabled( $app ){ return(\OC_JSON::checkAppEnabled( $app )); } - /** - * Check if the user is a admin, send json error msg if not - * - * This method checks if the current user has admin rights. If not, a json error - * response will be return and the method will exit from execution - * of the script. - * The returned json will be in the format: - * - * {"status":"error","data":{"message":"Authentication error."}} - * - * Add this call to the start of all ajax method files that requires - * administrative rights. - * + * Check if the user is a admin, send json error msg if not + * + * This method checks if the current user has admin rights. If not, a json error + * response will be return and the method will exit from execution + * of the script. + * The returned json will be in the format: + * + * {"status":"error","data":{"message":"Authentication error."}} + * + * Add this call to the start of all ajax method files that requires + * administrative rights. + * + * @return string json formatted string if not admin user. */ public static function checkAdminUser(){ return(\OC_JSON::checkAdminUser()); -- cgit v1.2.3 From 53bdb049cb3d2b005e5f6d17117f878b74aa0194 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 20 Jul 2012 23:31:08 +0200 Subject: adapted to new SabreDav version --- lib/connector/sabre/client.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/connector/sabre/client.php b/lib/connector/sabre/client.php index 87f9d59b3ae..7e8f21264f9 100644 --- a/lib/connector/sabre/client.php +++ b/lib/connector/sabre/client.php @@ -68,18 +68,13 @@ class OC_Connector_Sabre_Client extends Sabre_DAV_Client { // Automatically follow redirects CURLOPT_FOLLOWLOCATION => true, CURLOPT_MAXREDIRS => 5, - CURLOPT_SSL_VERIFYPEER => true, - //CURLOPT_SSL_VERIFYPEER => false, ); - + if($this->trustedCertificates) { $curlSettings[CURLOPT_CAINFO] = $this->trustedCertificates; } - + switch ($method) { - case 'PUT': - $curlSettings[CURLOPT_PUT] = true; - break; case 'HEAD' : // do not read body with HEAD requests (this is neccessary because cURL does not ignore the body with HEAD @@ -110,8 +105,15 @@ class OC_Connector_Sabre_Client extends Sabre_DAV_Client { $curlSettings[CURLOPT_PROXY] = $this->proxy; } - if ($this->userName) { - $curlSettings[CURLOPT_HTTPAUTH] = CURLAUTH_BASIC | CURLAUTH_DIGEST; + if ($this->userName && $this->authType) { + $curlType = 0; + if ($this->authType & self::AUTH_BASIC) { + $curlType |= CURLAUTH_BASIC; + } + if ($this->authType & self::AUTH_DIGEST) { + $curlType |= CURLAUTH_DIGEST; + } + $curlSettings[CURLOPT_HTTPAUTH] = $curlType; $curlSettings[CURLOPT_USERPWD] = $this->userName . ':' . $this->password; } @@ -167,5 +169,5 @@ class OC_Connector_Sabre_Client extends Sabre_DAV_Client { return $response; - } + } } \ No newline at end of file -- cgit v1.2.3 From cdd9ffc8a5dba2d4c3d83d77fc7806fd017a6b97 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 20 Jul 2012 23:52:47 +0200 Subject: Add ETag support to the Sabre file connector. This is based on the md5 of the file, can be changed later --- lib/connector/sabre/directory.php | 22 +++++++++++++++++++--- lib/connector/sabre/file.php | 25 +++++++++++++++++++++---- lib/connector/sabre/node.php | 26 ++++++++++++++++++++++++++ lib/filesystem.php | 8 ++++++++ 4 files changed, 74 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php index f3f6541a8d4..0842fc4fc65 100644 --- a/lib/connector/sabre/directory.php +++ b/lib/connector/sabre/directory.php @@ -26,17 +26,33 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa /** * Creates a new file in the directory * - * data is a readable stream resource + * Data will either be supplied as a stream resource, or in certain cases + * as a string. Keep in mind that you may have to support either. + * + * After succesful creation of the file, you may choose to return the ETag + * of the new file here. + * + * The returned ETag must be surrounded by double-quotes (The quotes should + * be part of the actual string). + * + * If you cannot accurately determine the ETag, you should not return it. + * If you don't store the file exactly as-is (you're transforming it + * somehow) you should also not return an ETag. + * + * This means that if a subsequent GET to this new file does not exactly + * return the same contents of what was submitted here, you are strongly + * recommended to omit the ETag. * * @param string $name Name of the file - * @param resource $data Initial payload - * @return void + * @param resource|string $data Initial payload + * @return null|string */ public function createFile($name, $data = null) { $newPath = $this->path . '/' . $name; OC_Filesystem::file_put_contents($newPath,$data); + return OC_Connector_Sabre_Node::getETagPropertyForFile($newPath); } /** diff --git a/lib/connector/sabre/file.php b/lib/connector/sabre/file.php index 4700dbf8b89..80f0a0ab4d8 100644 --- a/lib/connector/sabre/file.php +++ b/lib/connector/sabre/file.php @@ -26,13 +26,28 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D /** * Updates the data * + * The data argument is a readable stream resource. + * + * After a succesful put operation, you may choose to return an ETag. The + * etag must always be surrounded by double-quotes. These quotes must + * appear in the actual string you're returning. + * + * Clients may use the ETag from a PUT request to later on make sure that + * when they update the file, the contents haven't changed in the mean + * time. + * + * If you don't plan to store the file byte-by-byte, and you return a + * different object on a subsequent GET you are strongly recommended to not + * return an ETag, and just return null. + * * @param resource $data - * @return void + * @return string|null */ public function put($data) { OC_Filesystem::file_put_contents($this->path,$data); + return OC_Connector_Sabre_Node::getETagPropertyForFile($this->path); } /** @@ -79,9 +94,11 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D * @return mixed */ public function getETag() { - - return null; - + $properties = $this->getProperties(array(self::GETETAG_PROPERTYNAME)); + if (isset($properties[self::GETETAG_PROPERTYNAME])) { + return $properties[self::GETETAG_PROPERTYNAME]; + } + return $this->getETagPropertyForFile($this->path); } /** diff --git a/lib/connector/sabre/node.php b/lib/connector/sabre/node.php index be315a0ffd9..5bb92922f8f 100644 --- a/lib/connector/sabre/node.php +++ b/lib/connector/sabre/node.php @@ -22,6 +22,7 @@ */ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IProperties { + const GETETAG_PROPERTYNAME = '{DAV:}getetag'; /** * The path to the current node @@ -200,4 +201,29 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr } return $props; } + + /** + * Returns the ETag surrounded by double-quotes for this path. + * @param string $path Path of the file + * @return string|null Returns null if the ETag can not effectively be determined + */ + static public function getETagPropertyForFile($path) { + $tag = OC_Filesystem::hash('md5', $path); + if (empty($tag)) { + return null; + } + $etag = '"'.$tag.'"'; + $query = OC_DB::prepare( 'INSERT INTO *PREFIX*properties (userid,propertypath,propertyname,propertyvalue) VALUES(?,?,?,?)' ); + $query->execute( array( OC_User::getUser(), $path, self::GETETAG_PROPERTYNAME, $etag )); + return $etag; + } + + /** + * Remove the ETag from the cache. + * @param string $path Path of the file + */ + static public function removeETagPropertyForFile($path) { + $query = OC_DB::prepare( 'DELETE FROM *PREFIX*properties WHERE userid = ? AND propertypath = ? AND propertyname = ?' ); + $query->execute( array( OC_User::getUser(), $path, self::GETETAG_PROPERTYNAME )); + } } diff --git a/lib/filesystem.php b/lib/filesystem.php index 148656be00f..67dff95a183 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -483,7 +483,15 @@ class OC_Filesystem{ static public function hasUpdated($path,$time){ return self::$defaultInstance->hasUpdated($path,$time); } + + static public function removeETagHook() { + $path=$params['path']; + OC_Connector_Sabre_Node::removeETagPropertyForFile($path); + } } +OC_Hook::connect('OC_Filesystem','post_write', 'OC_Filesystem','removeETagHook'); +OC_Hook::connect('OC_Filesystem','post_delete','OC_Filesystem','removeETagHook'); +OC_Hook::connect('OC_Filesystem','post_rename','OC_Filesystem','removeETagHook'); OC_Util::setupFS(); require_once('filecache.php'); -- cgit v1.2.3 From 14af503374f5667e474de9c7f3762c7624d179a1 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sat, 21 Jul 2012 00:12:04 +0200 Subject: Fix parameter order in OC_Filestorage_Common->hash --- lib/filestorage/local.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php index 0ed184c8025..d60f32b15be 100644 --- a/lib/filestorage/local.php +++ b/lib/filestorage/local.php @@ -156,7 +156,7 @@ class OC_Filestorage_Local extends OC_Filestorage_Common{ return $return; } - public function hash($type,$path,$raw){ + public function hash($path,$type,$raw=false){ return hash_file($type,$this->datadir.$path,$raw); } -- cgit v1.2.3 From 0b338a7a413a3975ac1865e56c70b9c5a668a21f Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sat, 21 Jul 2012 00:13:23 +0200 Subject: Add missing public to function definition --- lib/connector/sabre/node.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/connector/sabre/node.php b/lib/connector/sabre/node.php index 5bb92922f8f..3cb5412f09f 100644 --- a/lib/connector/sabre/node.php +++ b/lib/connector/sabre/node.php @@ -179,7 +179,7 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr * @param array $properties * @return void */ - function getProperties($properties) { + public function getProperties($properties) { if (is_null($this->property_cache)) { $query = OC_DB::prepare( 'SELECT * FROM *PREFIX*properties WHERE userid = ? AND propertypath = ?' ); $result = $query->execute( array( OC_User::getUser(), $this->path )); -- cgit v1.2.3 From aa118a4c64c5958dcea1cdef299a8b22293ed2db Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 21 Jul 2012 00:06:01 +0200 Subject: remove obsolete oc_filesystem::mountall --- lib/filesystem.php | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'lib') diff --git a/lib/filesystem.php b/lib/filesystem.php index 67dff95a183..7402d2cc25b 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -321,17 +321,6 @@ class OC_Filesystem{ } self::$mounts[$mountpoint]=array('class'=>$class,'arguments'=>$arguments); } - - /** - * create all storage backends mounted in the filesystem - */ - static private function mountAll(){ - foreach(self::$mounts as $mountPoint=>$mount){ - if(!isset(self::$storages[$mountPoint])){ - self::$storages[$mountPoint]=self::createStorage($mount['type'],$mount['arguments']); - } - } - } /** * return the path to a local version of the file -- cgit v1.2.3 From 8a19e134df09dd9a3e49736489f28ad0aee79803 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 21 Jul 2012 00:20:04 +0200 Subject: fix ununsed variables --- apps/files_versions/lib/versions.php | 6 +++--- lib/connector/sabre/locks.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/apps/files_versions/lib/versions.php b/apps/files_versions/lib/versions.php index 0ce884c3ea0..f146676757d 100644 --- a/apps/files_versions/lib/versions.php +++ b/apps/files_versions/lib/versions.php @@ -227,13 +227,13 @@ class Storage { } $versions = array_reverse( $versions ); - + foreach( $versions as $key => $value ) { // flag the first matched file in array (which will have latest modification date) as current version - if ( $versions[$key]['fileMatch'] ) { + if ( $value['fileMatch'] ) { - $versions[$key]['cur'] = 1; + $value['cur'] = 1; break; } diff --git a/lib/connector/sabre/locks.php b/lib/connector/sabre/locks.php index 94382e68a1a..e95dcf02d27 100644 --- a/lib/connector/sabre/locks.php +++ b/lib/connector/sabre/locks.php @@ -108,7 +108,7 @@ class OC_Connector_Sabre_Locks extends Sabre_DAV_Locks_Backend_Abstract { $locks = $this->getLocks($uri,false); $exists = false; - foreach($locks as $k=>$lock) { + foreach($locks as $lock) { if ($lock->token == $lockInfo->token) $exists = true; } -- cgit v1.2.3 From 5381cc74188961899c3797c7d1634122bc8d0979 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sat, 21 Jul 2012 01:18:51 +0200 Subject: Fix missing parameter decleration, thanks Jenkins :-) --- lib/filesystem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/filesystem.php b/lib/filesystem.php index 7402d2cc25b..ec30ffb8f4c 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -473,7 +473,7 @@ class OC_Filesystem{ return self::$defaultInstance->hasUpdated($path,$time); } - static public function removeETagHook() { + static public function removeETagHook($params) { $path=$params['path']; OC_Connector_Sabre_Node::removeETagPropertyForFile($path); } -- cgit v1.2.3 From 0eade1b0d5ed6431c90b02a5b9df31b46674dcb9 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Sat, 21 Jul 2012 21:44:10 +0200 Subject: Code style. One down... --- lib/filesystemview.php | 436 +++++++++++++++++++++++++++++-------------------- 1 file changed, 262 insertions(+), 174 deletions(-) (limited to 'lib') diff --git a/lib/filesystemview.php b/lib/filesystemview.php index a23d7bbe7fd..9beda01e5a1 100644 --- a/lib/filesystemview.php +++ b/lib/filesystemview.php @@ -22,19 +22,19 @@ /** - * Class to provide access to ownCloud filesystem via a "view", and methods for - * working with files within that view (e.g. read, write, delete, etc.). Each - * view is restricted to a set of directories via a virtual root. The default view - * uses the currently logged in user's data directory as root (parts of + * Class to provide access to ownCloud filesystem via a "view", and methods for + * working with files within that view (e.g. read, write, delete, etc.). Each + * view is restricted to a set of directories via a virtual root. The default view + * uses the currently logged in user's data directory as root (parts of * OC_Filesystem are merely a wrapper for OC_FilesystemView). - * + * * Apps that need to access files outside of the user data folders (to modify files * belonging to a user other than the one currently logged in, for example) should * use this class directly rather than using OC_Filesystem, or making use of PHP's - * built-in file manipulation functions. This will ensure all hooks and proxies + * built-in file manipulation functions. This will ensure all hooks and proxies * are triggered correctly. * - * Filesystem functions are not called directly; they are passed to the correct + * Filesystem functions are not called directly; they are passed to the correct * OC_Filestorage object */ @@ -43,11 +43,11 @@ class OC_FilesystemView { private $internal_path_cache=array(); private $storage_cache=array(); - public function __construct($root){ + public function __construct($root) { $this->fakeRoot=$root; } - public function getAbsolutePath($path){ + public function getAbsolutePath($path) { if(!$path){ $path='/'; } @@ -63,9 +63,9 @@ class OC_FilesystemView { * @param string fakeRoot * @return bool */ - public function chroot($fakeRoot){ + public function chroot($fakeRoot) { if(!$fakeRoot==''){ - if($fakeRoot[0]!=='/'){ + if($fakeRoot[0]!=='/') { $fakeRoot='/'.$fakeRoot; } } @@ -76,7 +76,7 @@ class OC_FilesystemView { * get the fake root * @return string */ - public function getRoot(){ + public function getRoot() { return $this->fakeRoot; } @@ -85,7 +85,7 @@ class OC_FilesystemView { * @param string path * @return bool */ - public function getInternalPath($path){ + public function getInternalPath($path) { if (!isset($this->internal_path_cache[$path])) { $this->internal_path_cache[$path] = OC_Filesystem::getInternalPath($this->getAbsolutePath($path)); } @@ -97,23 +97,23 @@ class OC_FilesystemView { * @param string path * @return string */ - public function getRelativePath($path){ - if($this->fakeRoot==''){ + public function getRelativePath($path) { + if($this->fakeRoot=='') { return $path; } - if(strpos($path,$this->fakeRoot)!==0){ + if(strpos($path, $this->fakeRoot)!==0) { return null; }else{ - return substr($path,strlen($this->fakeRoot)); + return substr($path, strlen($this->fakeRoot)); } } - + /** * get the storage object for a path * @param string path * @return OC_Filestorage */ - public function getStorage($path){ + public function getStorage($path) { if (!isset($this->storage_cache[$path])) { $this->storage_cache[$path] = OC_Filesystem::getStorage($this->getAbsolutePath($path)); } @@ -127,7 +127,7 @@ class OC_FilesystemView { * @param string path * @return string */ - public function getMountPoint($path){ + public function getMountPoint($path) { return OC_Filesystem::getMountPoint($this->getAbsolutePath($path)); } @@ -137,55 +137,55 @@ class OC_FilesystemView { * @param string path * @return string */ - public function getLocalFile($path){ - $parent=substr($path,0,strrpos($path,'/')); - if(OC_Filesystem::isValidPath($parent) and $storage=$this->getStorage($path)){ + public function getLocalFile($path) { + $parent=substr($path, 0, strrpos($path,'/')); + if(OC_Filesystem::isValidPath($parent) and $storage=$this->getStorage($path)) { return $storage->getLocalFile($this->getInternalPath($path)); } } /** - * the following functions operate with arguments and return values identical - * to those of their PHP built-in equivalents. Mostly they are merely wrappers + * the following functions operate with arguments and return values identical + * to those of their PHP built-in equivalents. Mostly they are merely wrappers * for OC_Filestorage via basicOperation(). */ - public function mkdir($path){ - return $this->basicOperation('mkdir',$path,array('create','write')); + public function mkdir($path) { + return $this->basicOperation('mkdir', $path, array('create', 'write')); } - public function rmdir($path){ - return $this->basicOperation('rmdir',$path,array('delete')); + public function rmdir($path) { + return $this->basicOperation('rmdir', $path, array('delete')); } - public function opendir($path){ - return $this->basicOperation('opendir',$path,array('read')); + public function opendir($path) { + return $this->basicOperation('opendir', $path, array('read')); } - public function readdir($handle){ + public function readdir($handle) { $fsLocal= new OC_Filestorage_Local( array( 'datadir' => '/' ) ); return $fsLocal->readdir( $handle ); } - public function is_dir($path){ + public function is_dir($path) { if($path=='/'){ return true; } - return $this->basicOperation('is_dir',$path); + return $this->basicOperation('is_dir', $path); } - public function is_file($path){ + public function is_file($path) { if($path=='/'){ return false; } - return $this->basicOperation('is_file',$path); + return $this->basicOperation('is_file', $path); } - public function stat($path){ - return $this->basicOperation('stat',$path); + public function stat($path) { + return $this->basicOperation('stat', $path); } - public function filetype($path){ - return $this->basicOperation('filetype',$path); + public function filetype($path) { + return $this->basicOperation('filetype', $path); } - public function filesize($path){ - return $this->basicOperation('filesize',$path); + public function filesize($path) { + return $this->basicOperation('filesize', $path); } - public function readfile($path){ + public function readfile($path) { @ob_end_clean(); - $handle=$this->fopen($path,'rb'); + $handle=$this->fopen($path, 'rb'); if ($handle) { $chunkSize = 8192;// 8 MB chunks while (!feof($handle)) { @@ -197,137 +197,210 @@ class OC_FilesystemView { } return false; } - public function is_readable($path){ - return $this->basicOperation('is_readable',$path); + public function is_readable($path) { + return $this->basicOperation('is_readable', $path); } - public function is_writable($path){ - return $this->basicOperation('is_writable',$path); + public function is_writable($path) { + return $this->basicOperation('is_writable', $path); } - public function file_exists($path){ + public function file_exists($path) { if($path=='/'){ return true; } - return $this->basicOperation('file_exists',$path); + return $this->basicOperation('file_exists', $path); } - public function filectime($path){ - return $this->basicOperation('filectime',$path); + public function filectime($path) { + return $this->basicOperation('filectime', $path); } - public function filemtime($path){ - return $this->basicOperation('filemtime',$path); + public function filemtime($path) { + return $this->basicOperation('filemtime', $path); } - public function touch($path, $mtime=null){ + public function touch($path, $mtime=null) { return $this->basicOperation('touch', $path, array('write'), $mtime); } - public function file_get_contents($path){ - return $this->basicOperation('file_get_contents',$path,array('read')); - } - public function file_put_contents($path,$data){ - if(is_resource($data)){//not having to deal with streams in file_put_contents makes life easier - $exists=$this->file_exists($path); - $run=true; - if(!$exists){ - OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_create, array( OC_Filesystem::signal_param_path => $path, OC_Filesystem::signal_param_run => &$run)); + public function file_get_contents($path) { + return $this->basicOperation('file_get_contents', $path, array('read')); + } + public function file_put_contents($path, $data) { + if(is_resource($data)) {//not having to deal with streams in file_put_contents makes life easier + $exists = $this->file_exists($path); + $run = true; + if(!$exists) { + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_create, + array( + OC_Filesystem::signal_param_path => $path, + OC_Filesystem::signal_param_run => &$run + ) + ); } - OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_write, array( OC_Filesystem::signal_param_path => $path, OC_Filesystem::signal_param_run => &$run)); - if(!$run){ + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_write, + array( + OC_Filesystem::signal_param_path => $path, + OC_Filesystem::signal_param_run => &$run + ) + ); + if(!$run) { return false; } - $target=$this->fopen($path,'w'); - if($target){ - $count=OC_Helper::streamCopy($data,$target); + $target=$this->fopen($path, 'w'); + if($target) { + $count=OC_Helper::streamCopy($data, $target); fclose($target); fclose($data); - if(!$exists){ - OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_create, array( OC_Filesystem::signal_param_path => $path)); + if(!$exists) { + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_post_create, + array( OC_Filesystem::signal_param_path => $path) + ); } - OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_write, array( OC_Filesystem::signal_param_path => $path)); - return $count>0; + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_post_write, + array( OC_Filesystem::signal_param_path => $path) + ); + return $count > 0; }else{ return false; } }else{ - return $this->basicOperation('file_put_contents',$path,array('create','write'),$data); + return $this->basicOperation('file_put_contents', $path, array('create', 'write'), $data); } } - public function unlink($path){ - return $this->basicOperation('unlink',$path,array('delete')); + public function unlink($path) { + return $this->basicOperation('unlink', $path, array('delete')); } public function deleteAll( $directory, $empty = false ) { return $this->basicOperation( 'deleteAll', $directory, array('delete'), $empty ); } - public function rename($path1,$path2){ - $absolutePath1=$this->getAbsolutePath($path1); - $absolutePath2=$this->getAbsolutePath($path2); - if(OC_FileProxy::runPreProxies('rename',$absolutePath1,$absolutePath2) and OC_Filesystem::isValidPath($path2)){ - $path1=$this->getRelativePath($absolutePath1); - $path2=$this->getRelativePath($absolutePath2); - if($path1==null or $path2==null){ + public function rename($path1, $path2) { + $absolutePath1 = $this->getAbsolutePath($path1); + $absolutePath2 = $this->getAbsolutePath($path2); + if(OC_FileProxy::runPreProxies('rename', $absolutePath1, $absolutePath2) and OC_Filesystem::isValidPath($path2)) { + $path1 = $this->getRelativePath($absolutePath1); + $path2 = $this->getRelativePath($absolutePath2); + if($path1 == null or $path2 == null) { return false; } $run=true; - OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_rename, array( OC_Filesystem::signal_param_oldpath => $path1 , OC_Filesystem::signal_param_newpath=>$path2, OC_Filesystem::signal_param_run => &$run)); - if($run){ - $mp1=$this->getMountPoint($path1); - $mp2=$this->getMountPoint($path2); - if($mp1==$mp2){ - if($storage=$this->getStorage($path1)){ - $result=$storage->rename($this->getInternalPath($path1),$this->getInternalPath($path2)); + OC_Hook::emit( + OC_Filesystem::CLASSNAME, OC_Filesystem::signal_rename, + array( + OC_Filesystem::signal_param_oldpath => $path1, + OC_Filesystem::signal_param_newpath => $path2, + OC_Filesystem::signal_param_run => &$run + ) + ); + if($run) { + $mp1 = $this->getMountPoint($path1); + $mp2 = $this->getMountPoint($path2); + if($mp1 == $mp2) { + if($storage = $this->getStorage($path1)) { + $result = $storage->rename($this->getInternalPath($path1), $this->getInternalPath($path2)); } - }else{ - $source=$this->fopen($path1,'r'); - $target=$this->fopen($path2,'w'); - $count=OC_Helper::streamCopy($source,$target); - $storage1=$this->getStorage($path1); + } else { + $source = $this->fopen($path1, 'r'); + $target = $this->fopen($path2, 'w'); + $count = OC_Helper::streamCopy($source, $target); + $storage1 = $this->getStorage($path1); $storage1->unlink($this->getInternalPath($path1)); - $result=$count>0; + $result = $count>0; } - OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_rename, array( OC_Filesystem::signal_param_oldpath => $path1, OC_Filesystem::signal_param_newpath=>$path2)); + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_post_rename, + array( + OC_Filesystem::signal_param_oldpath => $path1, + OC_Filesystem::signal_param_newpath => $path2 + ) + ); return $result; } } } - public function copy($path1,$path2){ - $absolutePath1=$this->getAbsolutePath($path1); - $absolutePath2=$this->getAbsolutePath($path2); - if(OC_FileProxy::runPreProxies('copy',$absolutePath1,$absolutePath2) and OC_Filesystem::isValidPath($path2)){ - $path1=$this->getRelativePath($absolutePath1); - $path2=$this->getRelativePath($absolutePath2); - if($path1==null or $path2==null){ + public function copy($path1, $path2) { + $absolutePath1 = $this->getAbsolutePath($path1); + $absolutePath2 = $this->getAbsolutePath($path2); + if(OC_FileProxy::runPreProxies('copy', $absolutePath1, $absolutePath2) and OC_Filesystem::isValidPath($path2)) { + $path1 = $this->getRelativePath($absolutePath1); + $path2 = $this->getRelativePath($absolutePath2); + if($path1 == null or $path2 == null) { return false; } $run=true; - OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_copy, array( OC_Filesystem::signal_param_oldpath => $path1 , OC_Filesystem::signal_param_newpath=>$path2, OC_Filesystem::signal_param_run => &$run)); + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_copy, + array( + OC_Filesystem::signal_param_oldpath => $path1, + OC_Filesystem::signal_param_newpath=>$path2, + OC_Filesystem::signal_param_run => &$run + ) + ); $exists=$this->file_exists($path2); - if($run and !$exists){ - OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_create, array( OC_Filesystem::signal_param_path => $path2, OC_Filesystem::signal_param_run => &$run)); + if($run and !$exists) { + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_create, + array( + OC_Filesystem::signal_param_path => $path2, + OC_Filesystem::signal_param_run => &$run + ) + ); } - if($run){ - OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_write, array( OC_Filesystem::signal_param_path => $path2, OC_Filesystem::signal_param_run => &$run)); + if($run) { + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_write, + array( + OC_Filesystem::signal_param_path => $path2, + OC_Filesystem::signal_param_run => &$run + ) + ); } - if($run){ + if($run) { $mp1=$this->getMountPoint($path1); $mp2=$this->getMountPoint($path2); - if($mp1==$mp2){ - if($storage=$this->getStorage($path1)){ - $result=$storage->copy($this->getInternalPath($path1),$this->getInternalPath($path2)); + if($mp1 == $mp2){ + if($storage = $this->getStorage($path1)) { + $result=$storage->copy($this->getInternalPath($path1), $this->getInternalPath($path2)); } - }else{ - $source=$this->fopen($path1,'r'); - $target=$this->fopen($path2,'w'); - $result=OC_Helper::streamCopy($source,$target); + } else { + $source = $this->fopen($path1, 'r'); + $target = $this->fopen($path2, 'w'); + $result = OC_Helper::streamCopy($source, $target); } - OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_copy, array( OC_Filesystem::signal_param_oldpath => $path1 , OC_Filesystem::signal_param_newpath=>$path2)); - if(!$exists){ - OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_create, array( OC_Filesystem::signal_param_path => $path2)); + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_post_copy, + array( + OC_Filesystem::signal_param_oldpath => $path1, + OC_Filesystem::signal_param_newpath=>$path2 + ) + ); + if(!$exists) { + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_post_create, + array(OC_Filesystem::signal_param_path => $path2) + ); } - OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_write, array( OC_Filesystem::signal_param_path => $path2)); + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_post_write, + array( OC_Filesystem::signal_param_path => $path2) + ); return $result; } } } - public function fopen($path,$mode){ + public function fopen($path, $mode) { $hooks=array(); - switch($mode){ + switch($mode) { case 'r': case 'rb': $hooks[]='read'; @@ -355,49 +428,49 @@ class OC_FilesystemView { OC_Log::write('core','invalid mode ('.$mode.') for '.$path,OC_Log::ERROR); } - return $this->basicOperation('fopen',$path,$hooks,$mode); + return $this->basicOperation('fopen', $path, $hooks, $mode); } - public function toTmpFile($path){ - if(OC_Filesystem::isValidPath($path)){ - $source=$this->fopen($path,'r'); - if($source){ + public function toTmpFile($path) { + if(OC_Filesystem::isValidPath($path)) { + $source = $this->fopen($path, 'r'); + if($source) { $extension=''; - $extOffset=strpos($path,'.'); + $extOffset=strpos($path, '.'); if($extOffset !== false) { - $extension=substr($path,strrpos($path,'.')); + $extension=substr($path, strrpos($path,'.')); } - $tmpFile=OC_Helper::tmpFile($extension); - file_put_contents($tmpFile,$source); + $tmpFile = OC_Helper::tmpFile($extension); + file_put_contents($tmpFile, $source); return $tmpFile; } } } - public function fromTmpFile($tmpFile,$path){ - if(OC_Filesystem::isValidPath($path)){ - if(!$tmpFile){ + public function fromTmpFile($tmpFile, $path) { + if(OC_Filesystem::isValidPath($path)) { + if(!$tmpFile) { debug_print_backtrace(); } - $source=fopen($tmpFile,'r'); - if($source){ - $this->file_put_contents($path,$source); + $source=fopen($tmpFile, 'r'); + if($source) { + $this->file_put_contents($path, $source); unlink($tmpFile); return true; - }else{ + } else { } - }else{ + } else { return false; } } - public function getMimeType($path){ - return $this->basicOperation('getMimeType',$path); + public function getMimeType($path) { + return $this->basicOperation('getMimeType', $path); } - public function hash($type,$path){ - return $this->basicOperation('hash',$path,array('read'),$type); + public function hash($type, $path) { + return $this->basicOperation('hash', $path, array('read'), $type); } - public function free_space($path='/'){ - return $this->basicOperation('free_space',$path); + public function free_space($path='/') { + return $this->basicOperation('free_space', $path); } /** @@ -407,41 +480,56 @@ class OC_FilesystemView { * @param array (optional) hooks * @param mixed (optional) $extraParam * @return mixed - * - * This method takes requests for basic filesystem functions (e.g. reading & writing - * files), processes hooks and proxies, sanitises paths, and finally passes them on to + * + * This method takes requests for basic filesystem functions (e.g. reading & writing + * files), processes hooks and proxies, sanitises paths, and finally passes them on to * OC_Filestorage for delegation to a storage backend for execution */ - private function basicOperation($operation,$path,$hooks=array(),$extraParam=null){ - $absolutePath=$this->getAbsolutePath($path); - if(OC_FileProxy::runPreProxies($operation,$absolutePath, $extraParam) and OC_Filesystem::isValidPath($path)){ - $path=$this->getRelativePath($absolutePath); - if($path==null){ + private function basicOperation($operation, $path, $hooks=array(), $extraParam=null) { + $absolutePath = $this->getAbsolutePath($path); + if(OC_FileProxy::runPreProxies($operation, $absolutePath, $extraParam) and OC_Filesystem::isValidPath($path)) { + $path = $this->getRelativePath($absolutePath); + if($path == null) { return false; } - $internalPath=$this->getInternalPath($path); - $run=true; - if(OC_Filesystem::$loaded and $this->fakeRoot==OC_Filesystem::getRoot()){ - foreach($hooks as $hook){ - if($hook!='read'){ - OC_Hook::emit( OC_Filesystem::CLASSNAME, $hook, array( OC_Filesystem::signal_param_path => $path, OC_Filesystem::signal_param_run => &$run)); - }else{ - OC_Hook::emit( OC_Filesystem::CLASSNAME, $hook, array( OC_Filesystem::signal_param_path => $path)); + $internalPath = $this->getInternalPath($path); + $run = true; + if(OC_Filesystem::$loaded and $this->fakeRoot==OC_Filesystem::getRoot()) { + foreach($hooks as $hook) { + if($hook!='read') { + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + $hook, + array( + OC_Filesystem::signal_param_path => $path, + OC_Filesystem::signal_param_run => &$run + ) + ); + } else { + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + $hook, + array( OC_Filesystem::signal_param_path => $path) + ); } } } - if($run and $storage=$this->getStorage($path)){ - if(!is_null($extraParam)){ - $result=$storage->$operation($internalPath,$extraParam); - }else{ - $result=$storage->$operation($internalPath); + if($run and $storage = $this->getStorage($path)) { + if(!is_null($extraParam)) { + $result = $storage->$operation($internalPath, $extraParam); + } else { + $result = $storage->$operation($internalPath); } - $result=OC_FileProxy::runPostProxies($operation,$this->getAbsolutePath($path),$result); - if(OC_Filesystem::$loaded and $this->fakeRoot==OC_Filesystem::getRoot()){ - if($operation!='fopen'){//no post hooks for fopen, the file stream is still open - foreach($hooks as $hook){ + $result = OC_FileProxy::runPostProxies($operation, $this->getAbsolutePath($path), $result); + if(OC_Filesystem::$loaded and $this->fakeRoot==OC_Filesystem::getRoot()) { + if($operation!='fopen') {//no post hooks for fopen, the file stream is still open + foreach($hooks as $hook) { if($hook!='read'){ - OC_Hook::emit( OC_Filesystem::CLASSNAME, 'post_'.$hook, array( OC_Filesystem::signal_param_path => $path)); + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + 'post_'.$hook, + array( OC_Filesystem::signal_param_path => $path) + ); } } } @@ -457,7 +545,7 @@ class OC_FilesystemView { * @param int $time * @return bool */ - public function hasUpdated($path,$time){ - return $this->basicOperation('hasUpdated',$path,array(),$time); + public function hasUpdated($path, $time) { + return $this->basicOperation('hasUpdated', $path, array(), $time); } } -- cgit v1.2.3 From 2a73678fef47f8230f6caf546e42b22d722973b0 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 22 Jul 2012 01:49:42 +0200 Subject: use file extension for determining mimetypes on default should be more reliable for files that "look like" other types based on their magic numbers such as odf and docx files also a lot faster then the old way --- lib/helper.php | 29 +++++++++++++---------------- lib/mimetypes.fixlist.php | 22 ---------------------- lib/mimetypes.list.php | 13 ++++++++++++- 3 files changed, 25 insertions(+), 39 deletions(-) delete mode 100644 lib/mimetypes.fixlist.php (limited to 'lib') diff --git a/lib/helper.php b/lib/helper.php index c4f7e8b2e19..59d88f46dad 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -345,18 +345,24 @@ class OC_Helper { */ static function getMimeType($path){ $isWrapped=(strpos($path,'://')!==false) and (substr($path,0,7)=='file://'); - $mimeType='application/octet-stream'; - if ($mimeType=='application/octet-stream') { - self::$mimetypes = include('mimetypes.fixlist.php'); - $extension=strtolower(strrchr(basename($path), ".")); - $extension=substr($extension,1);//remove leading . - $mimeType=(isset(self::$mimetypes[$extension]))?self::$mimetypes[$extension]:'application/octet-stream'; - } if (@is_dir($path)) { // directories are easy return "httpd/unix-directory"; } + + if(strpos($path,'.')){ + //try to guess the type by the file extension + if(!self::$mimetypes || self::$mimetypes != include('mimetypes.list.php')){ + self::$mimetypes=include('mimetypes.list.php'); + } + $extension=strtolower(strrchr(basename($path), ".")); + $extension=substr($extension,1);//remove leading . + $mimeType=(isset(self::$mimetypes[$extension]))?self::$mimetypes[$extension]:'application/octet-stream'; + }else{ + $mimeType='application/octet-stream'; + } + if($mimeType=='application/octet-stream' and function_exists('finfo_open') and function_exists('finfo_file') and $finfo=finfo_open(FILEINFO_MIME)){ $info = @strtolower(finfo_file($finfo,$path)); if($info){ @@ -385,15 +391,6 @@ class OC_Helper { } } - if ($mimeType=='application/octet-stream') { - // Fallback solution: (try to guess the type by the file extension - if(!self::$mimetypes || self::$mimetypes != include('mimetypes.list.php')){ - self::$mimetypes=include('mimetypes.list.php'); - } - $extension=strtolower(strrchr(basename($path), ".")); - $extension=substr($extension,1);//remove leading . - $mimeType=(isset(self::$mimetypes[$extension]))?self::$mimetypes[$extension]:'application/octet-stream'; - } return $mimeType; } diff --git a/lib/mimetypes.fixlist.php b/lib/mimetypes.fixlist.php deleted file mode 100644 index 13e3f16b369..00000000000 --- a/lib/mimetypes.fixlist.php +++ /dev/null @@ -1,22 +0,0 @@ -'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', - 'doc'=>'application/msword', - 'docx'=>'application/msword', - 'xls'=>'application/msexcel', - 'xlsx'=>'application/msexcel', - 'ppt'=>'application/mspowerpoint', - 'pptx'=>'application/mspowerpoint', - 'sgf' => 'application/sgf', - 'cdr' => 'application/coreldraw' -); diff --git a/lib/mimetypes.list.php b/lib/mimetypes.list.php index ccf47999b1c..f7207493f7f 100644 --- a/lib/mimetypes.list.php +++ b/lib/mimetypes.list.php @@ -78,5 +78,16 @@ return array( 'mpeg'=>'video/mpeg', 'mov'=>'video/quicktime', 'webm'=>'video/webm', - 'wmv'=>'video/x-ms-asf' + 'wmv'=>'video/x-ms-asf', + 'py'=>'text/x-script.phyton', + 'vcf' => 'text/vcard', + 'vcard' => 'text/vcard', + 'doc'=>'application/msword', + 'docx'=>'application/msword', + 'xls'=>'application/msexcel', + 'xlsx'=>'application/msexcel', + 'ppt'=>'application/mspowerpoint', + 'pptx'=>'application/mspowerpoint', + 'sgf' => 'application/sgf', + 'cdr' => 'application/coreldraw', ); -- cgit v1.2.3 From 2b747789588e34bce24bd558f7e979a6e0ea8047 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 22 Jul 2012 02:23:24 +0200 Subject: add method to OC_Cache to check whether a fast cache (apc/xdebug/etc) is available --- lib/cache.php | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'lib') diff --git a/lib/cache.php b/lib/cache.php index 1f269174fad..6f4b3e6e3f6 100644 --- a/lib/cache.php +++ b/lib/cache.php @@ -7,9 +7,20 @@ */ class OC_Cache { + /** + * @var OC_Cache $user_cache + */ static protected $user_cache; + /** + * @var OC_Cache $global_cache + */ static protected $global_cache; + static protected $isFast=null; + /** + * get the global cache + * @return OC_Cache + */ static public function getGlobalCache() { if (!self::$global_cache) { $fast_cache = null; @@ -27,6 +38,10 @@ class OC_Cache { return self::$global_cache; } + /** + * get the user cache + * @return OC_Cache + */ static public function getUserCache() { if (!self::$user_cache) { $fast_cache = null; @@ -44,11 +59,19 @@ class OC_Cache { return self::$user_cache; } + /** + * get a value from the user cache + * @return mixed + */ static public function get($key) { $user_cache = self::getUserCache(); return $user_cache->get($key); } + /** + * set a value in the user cache + * @return bool + */ static public function set($key, $value, $ttl=0) { if (empty($key)) { return false; @@ -57,19 +80,42 @@ class OC_Cache { return $user_cache->set($key, $value, $ttl); } + /** + * check if a value is set in the user cache + * @return bool + */ static public function hasKey($key) { $user_cache = self::getUserCache(); return $user_cache->hasKey($key); } + /** + * remove an item from the user cache + * @return bool + */ static public function remove($key) { $user_cache = self::getUserCache(); return $user_cache->remove($key); } + /** + * clear the user cache + * @return bool + */ static public function clear() { $user_cache = self::getUserCache(); return $user_cache->clear(); } + /** + * check if a fast memory based cache is available + * @return true + */ + static public function isFast() { + if(is_null(self::$isFast)){ + self::$isFast=function_exists('xcache_set') || function_exists('apc_store'); + } + return self::$isFast; + } + } -- cgit v1.2.3 From 51566e87c7343385ae3b6854386c20974c94a53d Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 22 Jul 2012 02:31:43 +0200 Subject: add prefix option to OC_Cache::clear --- lib/cache.php | 7 ++++--- lib/cache/apc.php | 5 +++-- lib/cache/broker.php | 6 +++--- lib/cache/file.php | 5 +++-- lib/cache/xcache.php | 5 +++-- tests/lib/cache.php | 21 +++++++++++++++++++++ 6 files changed, 37 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/lib/cache.php b/lib/cache.php index 6f4b3e6e3f6..36f409ab71a 100644 --- a/lib/cache.php +++ b/lib/cache.php @@ -99,12 +99,13 @@ class OC_Cache { } /** - * clear the user cache + * clear the user cache of all entries starting with a prefix + * @param string prefix (optional) * @return bool */ - static public function clear() { + static public function clear($prefix='') { $user_cache = self::getUserCache(); - return $user_cache->clear(); + return $user_cache->clear($prefix); } /** diff --git a/lib/cache/apc.php b/lib/cache/apc.php index 6cf47d0c158..c192fe2f196 100644 --- a/lib/cache/apc.php +++ b/lib/cache/apc.php @@ -43,14 +43,15 @@ class OC_Cache_APC { return apc_delete($this->getNamespace().$key); } - public function clear(){ - $ns = $this->getNamespace(); + public function clear($prefix=''){ + $ns = $this->getNamespace().$prefix; $cache = apc_cache_info('user'); foreach($cache['cache_list'] as $entry) { if (strpos($entry['info'], $ns) === 0) { apc_delete($entry['info']); } } + return true; } } if(!function_exists('apc_exists')) { diff --git a/lib/cache/broker.php b/lib/cache/broker.php index 931d0dd407e..c2aceabaf53 100644 --- a/lib/cache/broker.php +++ b/lib/cache/broker.php @@ -46,8 +46,8 @@ class OC_Cache_Broker { return $this->slow_cache->remove($key); } - public function clear(){ - $this->fast_cache->clear(); - $this->slow_cache->clear(); + public function clear($prefix=''){ + $this->fast_cache->clear($prefix); + $this->slow_cache->clear($prefix); } } diff --git a/lib/cache/file.php b/lib/cache/file.php index 0b7d3e30508..562c3d17167 100644 --- a/lib/cache/file.php +++ b/lib/cache/file.php @@ -62,15 +62,16 @@ class OC_Cache_File{ return $storage->unlink($key); } - public function clear(){ + public function clear($prefix=''){ $storage = $this->getStorage(); if($storage and $storage->is_dir('/')){ $dh=$storage->opendir('/'); while($file=readdir($dh)){ - if($file!='.' and $file!='..'){ + if($file!='.' and $file!='..' and ($prefix==='' || strpos($file, $prefix) === 0)){ $storage->unlink('/'.$file); } } } + return true; } } diff --git a/lib/cache/xcache.php b/lib/cache/xcache.php index bd55cee8f6b..951f9b47545 100644 --- a/lib/cache/xcache.php +++ b/lib/cache/xcache.php @@ -43,7 +43,8 @@ class OC_Cache_XCache { return xcache_unset($this->getNamespace().$key); } - public function clear(){ - return xcache_unset_by_prefix($this->getNamespace()); + public function clear($prefix=''){ + xcache_unset_by_prefix($this->getNamespace().$prefix); + return true; } } diff --git a/tests/lib/cache.php b/tests/lib/cache.php index bb5cfc6ee19..511999be956 100644 --- a/tests/lib/cache.php +++ b/tests/lib/cache.php @@ -42,6 +42,27 @@ abstract class Test_Cache extends UnitTestCase { $this->assertNull($this->instance->get('not_set'),'Unset value not equal to null'); $this->assertTrue($this->instance->remove('value1')); + $this->assertFalse($this->instance->hasKey('value1')); + } + + function testClear(){ + $value='ipsum lorum'; + $this->instance->set('1_value1',$value); + $this->instance->set('1_value2',$value); + $this->instance->set('2_value1',$value); + $this->instance->set('3_value1',$value); + + $this->assertTrue($this->instance->clear('1_')); + $this->assertFalse($this->instance->hasKey('1_value1')); + $this->assertFalse($this->instance->hasKey('1_value2')); + $this->assertTrue($this->instance->hasKey('2_value1')); + $this->assertTrue($this->instance->hasKey('3_value1')); + + $this->assertTrue($this->instance->clear()); + $this->assertFalse($this->instance->hasKey('1_value1')); + $this->assertFalse($this->instance->hasKey('1_value2')); + $this->assertFalse($this->instance->hasKey('2_value1')); + $this->assertFalse($this->instance->hasKey('3_value1')); } function testTTL(){ -- cgit v1.2.3 From 6843beeae97835573cf792c8367b41ecfeef5342 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 22 Jul 2012 03:21:20 +0200 Subject: add option to only get fast cache --- lib/cache.php | 57 +++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 16 deletions(-) (limited to 'lib') diff --git a/lib/cache.php b/lib/cache.php index 36f409ab71a..55f189a5da8 100644 --- a/lib/cache.php +++ b/lib/cache.php @@ -15,24 +15,40 @@ class OC_Cache { * @var OC_Cache $global_cache */ static protected $global_cache; + /** + * @var OC_Cache $global_cache_fast + */ + static protected $global_cache_fast; + /** + * @var OC_Cache $user_cache_fast + */ + static protected $user_cache_fast; static protected $isFast=null; /** * get the global cache * @return OC_Cache */ - static public function getGlobalCache() { + static public function getGlobalCache($fast=false) { if (!self::$global_cache) { - $fast_cache = null; - if (!$fast_cache && function_exists('xcache_set')) { - $fast_cache = new OC_Cache_XCache(true); + self::$global_cache_fast = null; + if (!self::$global_cache_fast && function_exists('xcache_set')) { + self::$global_cache_fast = new OC_Cache_XCache(true); } - if (!$fast_cache && function_exists('apc_store')) { - $fast_cache = new OC_Cache_APC(true); + if (!self::$global_cache_fast && function_exists('apc_store')) { + self::$global_cache_fast = new OC_Cache_APC(true); } + self::$global_cache = new OC_Cache_FileGlobal(); - if ($fast_cache) { - self::$global_cache = new OC_Cache_Broker($fast_cache, self::$global_cache); + if (self::$global_cache_fast) { + self::$global_cache = new OC_Cache_Broker(self::$global_cache_fast, self::$global_cache); + } + } + if($fast){ + if(self::$global_cache_fast){ + return self::$global_cache_fast; + }else{ + return false; } } return self::$global_cache; @@ -42,18 +58,27 @@ class OC_Cache { * get the user cache * @return OC_Cache */ - static public function getUserCache() { + static public function getUserCache($fast=false) { if (!self::$user_cache) { - $fast_cache = null; - if (!$fast_cache && function_exists('xcache_set')) { - $fast_cache = new OC_Cache_XCache(); + self::$user_cache_fast = null; + if (!self::$user_cache_fast && function_exists('xcache_set')) { + self::$user_cache_fast = new OC_Cache_XCache(); } - if (!$fast_cache && function_exists('apc_store')) { - $fast_cache = new OC_Cache_APC(); + if (!self::$user_cache_fast && function_exists('apc_store')) { + self::$user_cache_fast = new OC_Cache_APC(); } + self::$user_cache = new OC_Cache_File(); - if ($fast_cache) { - self::$user_cache = new OC_Cache_Broker($fast_cache, self::$user_cache); + if (self::$user_cache_fast) { + self::$user_cache = new OC_Cache_Broker(self::$user_cache_fast, self::$user_cache); + } + } + + if($fast){ + if(self::$user_cache_fast){ + return self::$user_cache_fast; + }else{ + return false; } } return self::$user_cache; -- cgit v1.2.3 From 59ab8b14c74c491fc1309e96f58d4ebc6ffd95d4 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 22 Jul 2012 03:24:34 +0200 Subject: cache fileid's in oc_cache --- apps/files/ajax/scan.php | 5 +++++ lib/filecache.php | 32 +++++++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/apps/files/ajax/scan.php b/apps/files/ajax/scan.php index 6fcf97688c2..eef38858516 100644 --- a/apps/files/ajax/scan.php +++ b/apps/files/ajax/scan.php @@ -16,6 +16,11 @@ session_write_close(); if($force or !OC_FileCache::inCache('')){ if(!$checkOnly){ OCP\DB::beginTransaction(); + + if(OC_Cache::isFast()){ + OC_Cache::clear('fileid/'); //make sure the old fileid's don't mess things up + } + OC_FileCache::scan($dir,$eventSource); OC_FileCache::clean(); OCP\DB::commit(); diff --git a/lib/filecache.php b/lib/filecache.php index 4b1774925c3..22f7427ae42 100644 --- a/lib/filecache.php +++ b/lib/filecache.php @@ -98,6 +98,10 @@ class OC_FileCache{ if(OC_DB::isError($result)){ OC_Log::write('files','error while writing file('.$path.') to cache',OC_Log::ERROR); } + + if($cache=OC_Cache::getUserCache(true)){ + $cache->remove('fileid/'.$path);//ensure we don't have -1 cached + } } /** @@ -146,6 +150,11 @@ class OC_FileCache{ $query=OC_DB::prepare('UPDATE *PREFIX*fscache SET parent=? ,name=?, path=?, path_hash=? WHERE path_hash=?'); $query->execute(array($newParent,basename($newPath),$newPath,md5($newPath),md5($oldPath))); + if(($cache=OC_Cache::getUserCache(true)) && $cache->hasKey('fileid/'.$oldPath)){ + $cache->set('fileid/'.$newPath,$cache->get('fileid/'.$oldPath)); + $cache->remove('fileid/'.$oldPath); + } + $query=OC_DB::prepare('SELECT path FROM *PREFIX*fscache WHERE path LIKE ?'); $oldLength=strlen($oldPath); $updateQuery=OC_DB::prepare('UPDATE *PREFIX*fscache SET path=?, path_hash=? WHERE path_hash=?'); @@ -153,6 +162,11 @@ class OC_FileCache{ $old=$row['path']; $new=$newPath.substr($old,$oldLength); $updateQuery->execute(array($new,md5($new),md5($old))); + + if(($cache=OC_Cache::getUserCache(true)) && $cache->hasKey('fileid/'.$old)){ + $cache->set('fileid/'.$new,$cache->get('fileid/'.$old)); + $cache->remove('fileid/'.$old); + } } } @@ -171,6 +185,8 @@ class OC_FileCache{ //delete everything inside the folder $query=OC_DB::prepare('DELETE FROM *PREFIX*fscache WHERE path LIKE ?'); $query->execute(array($root.$path.'/%')); + + OC_Cache::remove('fileid/'.$root.$path); } /** @@ -245,9 +261,14 @@ class OC_FileCache{ if($root===false){ $root=OC_Filesystem::getRoot(); } + + $fullPath=$root.$path; + if(($cache=OC_Cache::getUserCache(true)) && $cache->hasKey('fileid/'.$fullPath)){ + return $cache->get('fileid/'.$fullPath); + } $query=OC_DB::prepare('SELECT id FROM *PREFIX*fscache WHERE path_hash=?'); - $result=$query->execute(array(md5($root.$path))); + $result=$query->execute(array(md5($fullPath))); if(OC_DB::isError($result)){ OC_Log::write('files','error while getting file id of '.$path,OC_Log::ERROR); return -1; @@ -255,10 +276,15 @@ class OC_FileCache{ $result=$result->fetchRow(); if(is_array($result)){ - return $result['id']; + $id=$result['id']; }else{ - return -1; + $id=-1; + } + if($cache=OC_Cache::getUserCache(true)){ + $cache->set('fileid/'.$fullPath,$id); } + + return $id; } /** -- cgit v1.2.3 From b1010160b363223c1e1c1cc7137dfb8e9aa3ab5b Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 22 Jul 2012 16:36:09 +0200 Subject: CSRF protection for eventsource --- apps/files/ajax/newfile.php | 2 ++ core/js/eventsource.js | 1 + core/templates/layout.user.php | 1 + lib/eventsource.php | 3 +++ 4 files changed, 7 insertions(+) (limited to 'lib') diff --git a/apps/files/ajax/newfile.php b/apps/files/ajax/newfile.php index de054d9ce0c..cc9208ad08f 100644 --- a/apps/files/ajax/newfile.php +++ b/apps/files/ajax/newfile.php @@ -17,6 +17,8 @@ $source = isset( $_REQUEST['source'] ) ? stripslashes($_REQUEST['source']) : ''; if($source){ $eventSource=new OC_EventSource(); +}else{ + OC_JSON::callCheck(); } if($filename == '') { diff --git a/core/js/eventsource.js b/core/js/eventsource.js index 08259e02cae..e3ad7e3a671 100644 --- a/core/js/eventsource.js +++ b/core/js/eventsource.js @@ -40,6 +40,7 @@ OC.EventSource=function(src,data){ dataStr+=name+'='+encodeURIComponent(data[name])+'&'; } } + dataStr+='requesttoken='+OC.EventSource.requesttoken; if(!this.useFallBack && typeof EventSource !='undefined'){ this.source=new EventSource(src+'?'+dataStr); this.source.onmessage=function(e){ diff --git a/core/templates/layout.user.php b/core/templates/layout.user.php index 7e98fdedc2d..dc303ffc1a7 100644 --- a/core/templates/layout.user.php +++ b/core/templates/layout.user.php @@ -33,6 +33,7 @@