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/filesystem.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'lib/filesystem.php') 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); } } -- 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/filesystem.php') 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 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/filesystem.php') 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 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/filesystem.php') 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 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/filesystem.php') 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 856d9c0b54cc971940df4ed64429d994faf770f9 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 24 Jul 2012 00:39:59 +0200 Subject: some indention fixes --- lib/app.php | 6 +- lib/db.php | 6 +- lib/filesystem.php | 186 ++++++++++++++++++++++++++--------------------------- lib/helper.php | 2 - lib/image.php | 13 ++-- lib/installer.php | 30 ++++----- lib/json.php | 14 ++-- lib/ocs.php | 19 +----- lib/util.php | 59 ++++++++--------- 9 files changed, 152 insertions(+), 183 deletions(-) (limited to 'lib/filesystem.php') diff --git a/lib/app.php b/lib/app.php index 2b975de9ef0..56132c08671 100755 --- a/lib/app.php +++ b/lib/app.php @@ -195,7 +195,7 @@ class OC_App{ // check if the app is compatible with this version of ownCloud $info=OC_App::getAppInfo($app); $version=OC_Util::getVersion(); - if(!isset($info['require']) or ($version[0]>$info['require'])){ + if(!isset($info['require']) or ($version[0]>$info['require'])){ OC_Log::write('core','App "'.$info['name'].'" can\'t be installed because it is not compatible with this version of ownCloud',OC_Log::ERROR); return false; }else{ @@ -331,8 +331,8 @@ class OC_App{ } /** - * Get the path where to install apps - */ + * Get the path where to install apps + */ public static function getInstallPath() { if(OC_Config::getValue('appstoreenabled', true)==false) { return false; diff --git a/lib/db.php b/lib/db.php index 6f083d17cfb..6971fe4a583 100644 --- a/lib/db.php +++ b/lib/db.php @@ -368,9 +368,6 @@ class OC_DB { if( $definition instanceof MDB2_Schema_Error ){ die( $definition->getMessage().': '.$definition->getUserInfo()); } -// if(OC_Config::getValue('dbtype','sqlite')=='sqlite'){ -// $definition['overwrite']=true;//always overwrite for sqlite -// } $ret=self::$schema->createDatabase( $definition ); // Die in case something went wrong @@ -527,8 +524,7 @@ class OC_DB { * @brief replaces the owncloud tables with a new set * @param $file string path to the MDB2 xml db export file */ - public static function replaceDB( $file ){ - + public static function replaceDB( $file ){ $apps = OC_App::getAllApps(); self::beginTransaction(); // Delete the old tables diff --git a/lib/filesystem.php b/lib/filesystem.php index ec30ffb8f4c..a5edcf5bab3 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -53,99 +53,99 @@ class OC_Filesystem{ static private $defaultInstance; - /** - * classname which used for hooks handling - * used as signalclass in OC_Hooks::emit() - */ - const CLASSNAME = 'OC_Filesystem'; - - /** - * signalname emited before file renaming - * @param oldpath - * @param newpath - */ - const signal_rename = 'rename'; - - /** - * signal emited after file renaming - * @param oldpath - * @param newpath - */ - const signal_post_rename = 'post_rename'; - - /** - * signal emited before file/dir creation - * @param path - * @param run changing this flag to false in hook handler will cancel event - */ - const signal_create = 'create'; - - /** - * signal emited after file/dir creation - * @param path - * @param run changing this flag to false in hook handler will cancel event - */ - const signal_post_create = 'post_create'; - - /** - * signal emits before file/dir copy - * @param oldpath - * @param newpath - * @param run changing this flag to false in hook handler will cancel event - */ - const signal_copy = 'copy'; - - /** - * signal emits after file/dir copy - * @param oldpath - * @param newpath - */ - const signal_post_copy = 'post_copy'; - - /** - * signal emits before file/dir save - * @param path - * @param run changing this flag to false in hook handler will cancel event - */ - const signal_write = 'write'; - - /** - * signal emits after file/dir save - * @param path - */ - const signal_post_write = 'post_write'; - - /** - * signal emits when reading file/dir - * @param path - */ - const signal_read = 'read'; - - /** - * signal emits when removing file/dir - * @param path - */ - const signal_delete = 'delete'; - - /** - * parameters definitions for signals - */ - const signal_param_path = 'path'; - const signal_param_oldpath = 'oldpath'; - const signal_param_newpath = 'newpath'; - - /** - * run - changing this flag to false in hook handler will cancel event - */ - const signal_param_run = 'run'; - - /** - * get the mountpoint of the storage object for a path - ( note: because a storage is not always mounted inside the fakeroot, the returned mountpoint is relative to the absolute root of the filesystem and doesn't take the chroot into account - * - * @param string path - * @return string - */ + /** + * classname which used for hooks handling + * used as signalclass in OC_Hooks::emit() + */ + const CLASSNAME = 'OC_Filesystem'; + + /** + * signalname emited before file renaming + * @param oldpath + * @param newpath + */ + const signal_rename = 'rename'; + + /** + * signal emited after file renaming + * @param oldpath + * @param newpath + */ + const signal_post_rename = 'post_rename'; + + /** + * signal emited before file/dir creation + * @param path + * @param run changing this flag to false in hook handler will cancel event + */ + const signal_create = 'create'; + + /** + * signal emited after file/dir creation + * @param path + * @param run changing this flag to false in hook handler will cancel event + */ + const signal_post_create = 'post_create'; + + /** + * signal emits before file/dir copy + * @param oldpath + * @param newpath + * @param run changing this flag to false in hook handler will cancel event + */ + const signal_copy = 'copy'; + + /** + * signal emits after file/dir copy + * @param oldpath + * @param newpath + */ + const signal_post_copy = 'post_copy'; + + /** + * signal emits before file/dir save + * @param path + * @param run changing this flag to false in hook handler will cancel event + */ + const signal_write = 'write'; + + /** + * signal emits after file/dir save + * @param path + */ + const signal_post_write = 'post_write'; + + /** + * signal emits when reading file/dir + * @param path + */ + const signal_read = 'read'; + + /** + * signal emits when removing file/dir + * @param path + */ + const signal_delete = 'delete'; + + /** + * parameters definitions for signals + */ + const signal_param_path = 'path'; + const signal_param_oldpath = 'oldpath'; + const signal_param_newpath = 'newpath'; + + /** + * run - changing this flag to false in hook handler will cancel event + */ + const signal_param_run = 'run'; + + /** + * get the mountpoint of the storage object for a path + ( note: because a storage is not always mounted inside the fakeroot, the returned mountpoint is relative to the absolute root of the filesystem and doesn't take the chroot into account + * + * @param string path + * @return string + */ static public function getMountPoint($path){ OC_Hook::emit(self::CLASSNAME,'get_mountpoint',array('path'=>$path)); if(!$path){ diff --git a/lib/helper.php b/lib/helper.php index 59d88f46dad..f328c14ac77 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -175,10 +175,8 @@ class OC_Helper { */ public static function mimetypeIcon( $mimetype ){ $alias=array('application/xml'=>'code/xml'); -// echo $mimetype; if(isset($alias[$mimetype])){ $mimetype=$alias[$mimetype]; -// echo $mimetype; } // Replace slash with a minus $mimetype = str_replace( "/", "-", $mimetype ); diff --git a/lib/image.php b/lib/image.php index c438b3d67f6..90c64320a7c 100644 --- a/lib/image.php +++ b/lib/image.php @@ -23,12 +23,12 @@ //From user comments at http://dk2.php.net/manual/en/function.exif-imagetype.php if ( ! function_exists( 'exif_imagetype' ) ) { - function exif_imagetype ( $filename ) { - if ( ( $info = getimagesize( $filename ) ) !== false ) { - return $info[2]; - } - return false; - } + function exif_imagetype ( $filename ) { + if ( ( $info = getimagesize( $filename ) ) !== false ) { + return $info[2]; + } + return false; + } } function ellipsis($str, $maxlen) { @@ -66,7 +66,6 @@ class OC_Image { public function __construct($imageref = null) { //OC_Log::write('core',__METHOD__.'(): start', OC_Log::DEBUG); if(!extension_loaded('gd') || !function_exists('gd_info')) { - //if(!function_exists('imagecreatefromjpeg')) { OC_Log::write('core',__METHOD__.'(): GD module not installed', OC_Log::ERROR); return false; } diff --git a/lib/installer.php b/lib/installer.php index 00feb6d4709..a8b56cb34f2 100644 --- a/lib/installer.php +++ b/lib/installer.php @@ -126,19 +126,19 @@ class OC_Installer{ return false; } $info=OC_App::getAppInfo($extractDir.'/appinfo/info.xml',true); - // check the code for not allowed calls - if(!OC_Installer::checkCode($info['id'],$extractDir)){ + // check the code for not allowed calls + if(!OC_Installer::checkCode($info['id'],$extractDir)){ OC_Log::write('core','App can\'t be installed because of not allowed code in the App',OC_Log::ERROR); OC_Helper::rmdirr($extractDir); - return false; + return false; } - // check if the app is compatible with this version of ownCloud + // check if the app is compatible with this version of ownCloud $version=OC_Util::getVersion(); - if(!isset($info['require']) or ($version[0]>$info['require'])){ + if(!isset($info['require']) or ($version[0]>$info['require'])){ OC_Log::write('core','App can\'t be installed because it is not compatible with this version of ownCloud',OC_Log::ERROR); OC_Helper::rmdirr($extractDir); - return false; + return false; } //check if an app with the same id is already installed @@ -339,12 +339,12 @@ class OC_Installer{ } - /** - * check the code of an app with some static code checks - * @param string $folder the folder of the app to check - * @returns true for app is o.k. and false for app is not o.k. - */ - public static function checkCode($appname,$folder){ + /** + * check the code of an app with some static code checks + * @param string $folder the folder of the app to check + * @returns true for app is o.k. and false for app is not o.k. + */ + public static function checkCode($appname,$folder){ $blacklist=array( 'exec(', @@ -377,9 +377,7 @@ class OC_Installer{ return true; }else{ - return true; + return true; } - } - - + } } diff --git a/lib/json.php b/lib/json.php index c49b831c12b..b46878375d5 100644 --- a/lib/json.php +++ b/lib/json.php @@ -94,12 +94,12 @@ class OC_JSON{ * Encode and print $data in json format */ public static function encodedPrint($data,$setContentType=true){ - // Disable mimesniffing, don't move this to setContentTypeHeader! - header( 'X-Content-Type-Options: nosniff' ); - if($setContentType){ - self::setContentTypeHeader(); - } - array_walk_recursive($data, array('OC_JSON', 'to_string')); - echo json_encode($data); + // Disable mimesniffing, don't move this to setContentTypeHeader! + header( 'X-Content-Type-Options: nosniff' ); + if($setContentType){ + self::setContentTypeHeader(); + } + array_walk_recursive($data, array('OC_JSON', 'to_string')); + echo json_encode($data); } } diff --git a/lib/ocs.php b/lib/ocs.php index 0cd7888fcf9..9d30e172f55 100644 --- a/lib/ocs.php +++ b/lib/ocs.php @@ -111,21 +111,6 @@ class OC_OCS { $login = self::readData($method, 'login', 'text'); $passwd = self::readData($method, 'password', 'text'); OC_OCS::personcheck($format,$login,$passwd); -/* - } else if ($method == 'post' && $ex[$paracount - 4] == 'v1.php' && $ex[$paracount - 3] == 'person' && $ex[$paracount - 2] == 'add') { - if (OC_Group::inGroup(self::checkPassword(), 'admin')) { - $login = self::readData($method, 'login', 'text'); - $password = self::readData($method, 'password', 'text'); - try { - OC_User::createUser($login, $password); - echo self::generateXml($format, 'ok', 201, ''); - } catch (Exception $exception) { - echo self::generateXml($format, 'fail', 400, $exception->getMessage()); - } - } else { - echo self::generateXml($format, 'fail', 403, 'Permission denied'); - } -*/ // ACTIVITY // activityget - GET ACTIVITY page,pagesize als urlparameter @@ -149,8 +134,8 @@ class OC_OCS { }elseif(($method=='get') and ($ex[$paracount-5] == 'v1.php') and ($ex[$paracount-3] == 'getattribute')){ $app=$ex[$paracount-2]; OC_OCS::privateDataGet($format, $app); - }elseif(($method=='get') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-4] == 'getattribute')){ - + }elseif(($method=='get') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-4] == 'getattribute')){ + $key=$ex[$paracount-2]; $app=$ex[$paracount-3]; OC_OCS::privateDataGet($format, $app,$key); diff --git a/lib/util.php b/lib/util.php index f35e5a18e42..0c563278cc5 100755 --- a/lib/util.php +++ b/lib/util.php @@ -77,13 +77,13 @@ class OC_Util { return '5 pre alpha'; } - /** - * get the current installed edition of ownCloud. There is the community edition that just returns an empty string and the enterprise edition that returns "Enterprise". - * @return string - */ - public static function getEditionString(){ - return ''; - } + /** + * get the current installed edition of ownCloud. There is the community edition that just returns an empty string and the enterprise edition that returns "Enterprise". + * @return string + */ + public static function getEditionString(){ + return ''; + } /** * add a javascript file @@ -131,12 +131,12 @@ class OC_Util { self::$headers[]=array('tag'=>$tag,'attributes'=>$attributes,'text'=>$text); } - /** - * formats a timestamp in the "right" way - * - * @param int timestamp $timestamp - * @param bool dateOnly option to ommit time from the result - */ + /** + * formats a timestamp in the "right" way + * + * @param int timestamp $timestamp + * @param bool dateOnly option to ommit time from the result + */ public static function formatDate( $timestamp,$dateOnly=false){ if(isset($_SESSION['timezone'])){//adjust to clients timezone if we know it $systemTimeZone = intval(date('O')); @@ -438,26 +438,25 @@ class OC_Util { } - /** - * Check if the htaccess file is working by creating a test file in the data directory and trying to access via http - */ - public static function ishtaccessworking() { - + /** + * Check if the htaccess file is working by creating a test file in the data directory and trying to access via http + */ + public static function ishtaccessworking() { // testdata $filename='/htaccesstest.txt'; $testcontent='testcontent'; // creating a test file - $testfile = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ).'/'.$filename; - $fp = @fopen($testfile, 'w'); - @fwrite($fp, $testcontent); - @fclose($fp); + $testfile = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ).'/'.$filename; + $fp = @fopen($testfile, 'w'); + @fwrite($fp, $testcontent); + @fclose($fp); // accessing the file via http - $url = OC_Helper::serverProtocol(). '://' . OC_Helper::serverHost() . OC::$WEBROOT.'/data'.$filename; - $fp = @fopen($url, 'r'); - $content=@fread($fp, 2048); - @fclose($fp); + $url = OC_Helper::serverProtocol(). '://' . OC_Helper::serverHost() . OC::$WEBROOT.'/data'.$filename; + $fp = @fopen($url, 'r'); + $content=@fread($fp, 2048); + @fclose($fp); // cleanup @unlink($testfile); @@ -467,13 +466,7 @@ class OC_Util { return(false); }else{ return(true); - } - - } - - - - + } } -- cgit v1.2.3 From f25ccaff59c135d7f1f22196bf266916ef131b35 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 25 Jul 2012 16:54:46 -0400 Subject: Fix filesystem hash, no longer using basicOperation() --- apps/files_sharing/sharedstorage.php | 2 +- lib/filestorage.php | 2 +- lib/filestorage/common.php | 2 +- lib/filesystem.php | 4 ++-- lib/filesystemview.php | 23 +++++++++++++++++++++-- 5 files changed, 26 insertions(+), 7 deletions(-) (limited to 'lib/filesystem.php') diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 32fd2124429..fc0d272b54e 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -410,7 +410,7 @@ class OC_Filestorage_Shared extends OC_Filestorage_Common { } } - public function hash($type, $path, $raw) { + public function hash($type, $path, $raw = false) { $source = $this->getSource($path); if ($source) { $storage = OC_Filesystem::getStorage($source); diff --git a/lib/filestorage.php b/lib/filestorage.php index e786127d525..fd4ad36530e 100644 --- a/lib/filestorage.php +++ b/lib/filestorage.php @@ -45,7 +45,7 @@ abstract class OC_Filestorage{ abstract public function copy($path1,$path2); abstract public function fopen($path,$mode); abstract public function getMimeType($path); - abstract public function hash($type,$path,$raw); + abstract public function hash($type,$path,$raw = false); abstract public function free_space($path); abstract public function search($query); abstract public function touch($path, $mtime=null); diff --git a/lib/filestorage/common.php b/lib/filestorage/common.php index fd389d3e2d7..c77df38e6b1 100644 --- a/lib/filestorage/common.php +++ b/lib/filestorage/common.php @@ -195,7 +195,7 @@ abstract class OC_Filestorage_Common extends OC_Filestorage { unlink($tmpFile); return $mime; } - public function hash($type,$path,$raw){ + public function hash($type,$path,$raw = false){ $tmpFile=$this->getLocalFile(); $hash=hash($type,$tmpFile,$raw); unlink($tmpFile); diff --git a/lib/filesystem.php b/lib/filesystem.php index a5edcf5bab3..81370d4e178 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -452,8 +452,8 @@ class OC_Filesystem{ static public function getMimeType($path){ return self::$defaultInstance->getMimeType($path); } - static public function hash($type,$path){ - return self::$defaultInstance->hash($type,$path); + static public function hash($type,$path, $raw = false){ + return self::$defaultInstance->hash($type,$path, $raw); } static public function free_space($path='/'){ diff --git a/lib/filesystemview.php b/lib/filesystemview.php index 9beda01e5a1..3c989d7c36f 100644 --- a/lib/filesystemview.php +++ b/lib/filesystemview.php @@ -465,8 +465,27 @@ class OC_FilesystemView { 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, $raw = false) { + $absolutePath = $this->getAbsolutePath($path); + if (OC_FileProxy::runPreProxies('hash', $absolutePath) && OC_Filesystem::isValidPath($path)) { + $path = $this->getRelativePath($absolutePath); + if ($path == null) { + return false; + } + if (OC_Filesystem::$loaded && $this->fakeRoot == OC_Filesystem::getRoot()) { + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_read, + array( OC_Filesystem::signal_param_path => $path) + ); + } + if ($storage = $this->getStorage($path)) { + $result = $storage->hash($type, $this->getInternalPath($path), $raw); + $result = OC_FileProxy::runPostProxies('hash', $absolutePath, $result); + return $result; + } + } + return null; } public function free_space($path='/') { -- cgit v1.2.3