From bf66563cda15acbe8f5b12be76fb5ba387a6798c Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Thu, 16 Jun 2011 14:40:21 -0400 Subject: First version of shared storage provider - not functional --- lib/base.php | 4 ++++ lib/filesystem.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/base.php b/lib/base.php index c18ecd570db..199653e25e0 100644 --- a/lib/base.php +++ b/lib/base.php @@ -80,6 +80,7 @@ require_once('appconfig.php'); require_once('files.php'); require_once('filesystem.php'); require_once('filestorage.php'); +require_once('apps/files_sharing/sharedstorage.php'); require_once('log.php'); require_once('user.php'); require_once('group.php'); @@ -157,6 +158,9 @@ class OC_UTIL { // } OC_FILESYSTEM::mount($rootStorage,'/'); + $sharedStorage = OC_FILESYSTEM::createStorage('shared',array('datadir'=>$CONFIG_DATADIRECTORY)); + OC_FILESYSTEM::mount($sharedStorage,'MTGap/files/Test/'); + $CONFIG_DATADIRECTORY = "$CONFIG_DATADIRECTORY_ROOT/$user/$root"; if( !is_dir( $CONFIG_DATADIRECTORY )){ mkdir( $CONFIG_DATADIRECTORY, 0755, true ); diff --git a/lib/filesystem.php b/lib/filesystem.php index 2b5c3a56b6e..897efaa140e 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -155,7 +155,7 @@ class OC_FILESYSTEM{ * @param string path * @return OC_FILESTORAGE */ - static private function getStorage($path){ + static public function getStorage($path){ $mountpoint=self::getMountPoint($path); if($mountpoint){ return self::$storages[$mountpoint]; -- cgit v1.2.3 From 4e7d1c376f0ad85a32e285e512eb05e05219854e Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sat, 18 Jun 2011 13:49:52 -0400 Subject: OC_FILESTOAGE_SHARED now works with hard coded values for files --- apps/files_sharing/sharedstorage.php | 62 ++++++++++++++++++------------------ lib/filesystem.php | 2 +- 2 files changed, 32 insertions(+), 32 deletions(-) (limited to 'lib') diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 158d6006a47..bf6116c9ebb 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -34,7 +34,7 @@ class OC_FILESTORAGE_SHARED { } - public function getInternalPath($path) { + public static function getInternalPath($path) { $mountPoint = OC_FILESYSTEM::getMountPoint($path); $internalPath = substr($path,strlen($mountPoint)); return $internalPath; @@ -45,7 +45,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->mkdir(getInternalPath($source)); + return $storage->mkdir(self::getInternalPath($source)); } } @@ -54,7 +54,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->rmdir(getInternalPath($source)); + return $storage->rmdir(self::getInternalPath($source)); } } @@ -71,7 +71,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->is_dir(getInternalPath($source)); + return $storage->is_dir(self::getInternalPath($source)); } } } @@ -80,7 +80,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->is_file(getInternalPath($source)); + return $storage->is_file(self::getInternalPath($source)); } } public function stat($path) { @@ -103,19 +103,19 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->stat(getInternalPath($source)); + return $storage->stat(self::getInternalPath($source)); } } } public function filetype($path) { if ($path == "" || $path == "/") { - return "dir"; + return "httpd/unix-directory"; } else { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->filetype(getInternalPath($source)); + return $storage->filetype(self::getInternalPath($source)); } } @@ -129,7 +129,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->filesize(getInternalPath($source)); + return $storage->filesize(self::getInternalPath($source)); } } } @@ -142,7 +142,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->is_readable(getInternalPath($source)); + return $storage->is_readable(self::getInternalPath($source)); } } } @@ -155,7 +155,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->is_writeable(getInternalPath($source)); + return $storage->is_writeable(self::getInternalPath($source)); } } } @@ -167,7 +167,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->file_exists(getInternalPath($source)); + return $storage->file_exists(self::getInternalPath($source)); } } } @@ -176,7 +176,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->readfile(getInternalPath($source)); + return $storage->readfile(self::getInternalPath($source)); } } @@ -188,7 +188,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->filectime(getInternalPath($source)); + return $storage->filectime(self::getInternalPath($source)); } } } @@ -201,7 +201,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->filemtime(getInternalPath($source)); + return $storage->filemtime(self::getInternalPath($source)); } } } @@ -214,7 +214,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->fileatime(getInternalPath($source)); + return $storage->fileatime(self::getInternalPath($source)); } } } @@ -223,7 +223,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->file_get_contents(getInternalPath($source)); + return $storage->file_get_contents(self::getInternalPath($source)); } } @@ -232,7 +232,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->file_put_contents(getInternalPath($source), $data); + return $storage->file_put_contents(self::getInternalPath($source), $data); } } @@ -240,7 +240,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->unlink(getInternalPath($source)); + return $storage->unlink(self::getInternalPath($source)); } } @@ -250,7 +250,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path1); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->rename(getInternalPath($source), $path2); + return $storage->rename(self::getInternalPath($source), $path2); } } @@ -258,7 +258,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path1); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->copy(getInternalPath($source), $path2); + return $storage->copy(self::getInternalPath($source), $path2); } } @@ -266,7 +266,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->fopen(getInternalPath($source), $mode); + return $storage->fopen(self::getInternalPath($source), $mode); } } @@ -274,7 +274,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->toTmpFile(getInternalPath($source)); + return $storage->toTmpFile(self::getInternalPath($source)); } } @@ -282,7 +282,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($tmpPath); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->fromTmpFile(getInternalPath($source), $path); + return $storage->fromTmpFile(self::getInternalPath($source), $path); } } @@ -290,7 +290,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($tmpPath); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->fromUploadedFile(getInternalPath($source), $path); + return $storage->fromUploadedFile(self::getInternalPath($source), $path); } } @@ -298,7 +298,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->getMimeType(getInternalPath($source)); + return $storage->getMimeType(self::getInternalPath($source)); } } @@ -306,7 +306,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->delTree(getInternalPath($source)); + return $storage->delTree(self::getInternalPath($source)); } } @@ -314,7 +314,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->find(getInternalPath($source)); + return $storage->find(self::getInternalPath($source)); } } @@ -322,7 +322,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->getTree(getInternalPath($source)); + return $storage->getTree(self::getInternalPath($source)); } } @@ -330,7 +330,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->hash($type, getInternalPath($source), $raw); + return $storage->hash($type, self::getInternalPath($source), $raw); } } @@ -338,7 +338,7 @@ class OC_FILESTORAGE_SHARED { $source = OC_SHARE::getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->free_space(getInternalPath($source)); + return $storage->free_space(self::getInternalPath($source)); } } diff --git a/lib/filesystem.php b/lib/filesystem.php index 897efaa140e..a13363f832d 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -169,7 +169,7 @@ class OC_FILESYSTEM{ * @param string path * @return string */ - static private function getMountPoint($path){ + static public function getMountPoint($path){ if(!$path){ $path='/'; } -- cgit v1.2.3 From 18e776fa2f9c3d304e06e492c5b5e6059add9bd8 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 22 Jun 2011 11:40:09 -0400 Subject: Changed mount point to 'Share', fixed is_dir() --- apps/files_sharing/sharedstorage.php | 12 ++++++++++-- lib/base.php | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index bf6116c9ebb..4bb2ceb7c08 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -58,9 +58,14 @@ class OC_FILESTORAGE_SHARED { } } + // TODO add all files from db in array public function opendir($path) { global $FAKEDIRS; - $FAKEDIRS['shared'] = array(0 => 'test.txt'); + $sharedItems = OC_SHARE::getItemsSharedWith(); + foreach ($sharedItems as $item) { + $files[] = $item['target']; + } + $FAKEDIRS['shared'] = $files; return opendir('fakedir://shared'); } @@ -83,6 +88,8 @@ class OC_FILESTORAGE_SHARED { return $storage->is_file(self::getInternalPath($source)); } } + + // TODO fill in other components of array public function stat($path) { if ($path == "" || $path == "/") { $stat["dev"] = ""; @@ -110,7 +117,7 @@ class OC_FILESTORAGE_SHARED { public function filetype($path) { if ($path == "" || $path == "/") { - return "httpd/unix-directory"; + return "dir"; } else { $source = OC_SHARE::getSource($path); if ($source) { @@ -123,6 +130,7 @@ class OC_FILESTORAGE_SHARED { // TODO Get size of shared directory public function filesize($path) { + echo "filesize"; if ($path == "" || $path == "/") { return 10000; } else { diff --git a/lib/base.php b/lib/base.php index 199653e25e0..04f8f5c9fa4 100644 --- a/lib/base.php +++ b/lib/base.php @@ -158,8 +158,9 @@ class OC_UTIL { // } OC_FILESYSTEM::mount($rootStorage,'/'); + // TODO add this storage provider in a proper way $sharedStorage = OC_FILESYSTEM::createStorage('shared',array('datadir'=>$CONFIG_DATADIRECTORY)); - OC_FILESYSTEM::mount($sharedStorage,'MTGap/files/Test/'); + OC_FILESYSTEM::mount($sharedStorage,'MTGap/files/Share/'); $CONFIG_DATADIRECTORY = "$CONFIG_DATADIRECTORY_ROOT/$user/$root"; if( !is_dir( $CONFIG_DATADIRECTORY )){ -- cgit v1.2.3 From 607f1a2738911ace1026c6bc14aa28481a898897 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Mon, 4 Jul 2011 16:45:19 -0400 Subject: Fix conflicts with master in lib/base.php --- lib/base.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'lib') diff --git a/lib/base.php b/lib/base.php index e821d78fd8c..4250274c7c3 100644 --- a/lib/base.php +++ b/lib/base.php @@ -84,12 +84,9 @@ require_once('appconfig.php'); require_once('files.php'); require_once('filesystem.php'); require_once('filestorage.php'); -<<<<<<< HEAD require_once('apps/files_sharing/sharedstorage.php'); -======= require_once('l10n.php'); require_once('preferences.php'); ->>>>>>> master require_once('log.php'); require_once('user.php'); require_once('group.php'); -- cgit v1.2.3 From 9deab8302f4c41daed3db6f3b470480b2710c502 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Tue, 5 Jul 2011 11:56:02 -0400 Subject: Fix bugs in getSource() and implement new target path standard --- apps/files_sharing/lib_share.php | 4 +++- apps/files_sharing/sharedstorage.php | 19 +++++-------------- lib/filesystem.php | 10 ++++++++++ 3 files changed, 18 insertions(+), 15 deletions(-) (limited to 'lib') diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index b03720b7537..77b0bc4a70c 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -82,6 +82,8 @@ class OC_SHARE { * @return source path */ public static function getSource($target) { + // Remove any trailing '/' + $target = rtrim($target, "/"); $query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ? LIMIT 1"); $result = $query->execute(array($target, $_SESSION['user_id']))->fetchAll(); if (count($result) > 0) { @@ -89,7 +91,7 @@ class OC_SHARE { } else { // Check if the parent directory of this target is shared $parentDir = dirname($target); - if ($parentDir != ".") { + if ($parentDir != "" && $parentDir != "/" && $parentDir != ".") { $result = OC_SHARE::getSource($parentDir); if ($result) { return $result."/".basename($target); diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index e17685a09e7..0303cce79fb 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -43,22 +43,13 @@ class OC_FILESTORAGE_SHARED { } public function getSource($target) { - if ($target == "") { - return false; - } elseif (array_key_exists($target, $this->sourcePaths)) { + $target = OC_FILESYSTEM::getStorageMountPoint($this).$target; + if (array_key_exists($target, $this->sourcePaths)) { return $this->sourcePaths[$target]; } else { - $parentDir = dirname($target); - if ($parentDir != ".") { - $source = $this->getSource($parentDir); - return $source."/".basename($target); - } else { - $source = OC_SHARE::getSource($target); - if ($source) { - $this->sourcePaths[$target] = $source; - } - return $source; - } + $source = OC_SHARE::getSource($target); + $this->sourcePaths[$target] = $source; + return $source; } } diff --git a/lib/filesystem.php b/lib/filesystem.php index 4116cb93164..c7e2070fa0a 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -214,6 +214,16 @@ class OC_FILESYSTEM{ } return $foundMountPoint; } + + /** + * get the mountpoint of the storage object + * @param OC_FILESTORAGE storage + * @return string + */ + static public function getStorageMountPoint($storage){ + return array_search($storage, self::$storages); + } + /** * return the path to a local version of the file * we need this because we can't know if a file is stored local or not from outside the filestorage and for some purposes a local file is needed -- cgit v1.2.3 From 6b303ee64b5c1b1e338c9bbf1b895d33b140985d Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Tue, 12 Jul 2011 13:10:29 -0400 Subject: Fix bug in opendir() and remove getStorageMountPoint(), now using datadir argument instead --- apps/files_sharing/sharedstorage.php | 28 ++++++++++++---------------- lib/base.php | 2 +- lib/filesystem.php | 9 --------- 3 files changed, 13 insertions(+), 26 deletions(-) (limited to 'lib') diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 3b678178c36..b0770cbfdba 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -29,11 +29,11 @@ OC_FILESYSTEM::registerStorageType('shared','OC_FILESTORAGE_SHARED',array('datad */ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { + private $datadir; private $sourcePaths = array(); - // TODO uh... I don't know what to do here - public function __construct($parameters) { - + public function __construct($arguments) { + $this->datadir = $arguments['datadir']; } public function getInternalPath($path) { @@ -43,7 +43,7 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { } public function getSource($target) { - $target = OC_FILESYSTEM::getStorageMountPoint($this).$target; + $target = $this->datadir.$target; if (array_key_exists($target, $this->sourcePaths)) { return $this->sourcePaths[$target]; } else { @@ -59,8 +59,7 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { } else { $source = $this->getSource($path); if ($source) { - $target = OC_FILESYSTEM::getStorageMountPoint($this).$path; - if (OC_SHARE::isWriteable($target)) { + if (OC_SHARE::isWriteable($this->datadir.$path)) { $storage = OC_FILESYSTEM::getStorage($source); return $storage->mkdir($this->getInternalPath($source)); } @@ -70,16 +69,17 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { public function rmdir($path) { // The folder will be removed from the database, but won't be deleted from the owner's filesystem - $target = OC_FILESYSTEM::getStorageMountPoint($this).$path; - OC_SHARE::unshareFromSelf($target); + OC_SHARE::unshareFromSelf($this->datadir.$path); } + // TODO Make sure new target is still in the current directory public function opendir($path) { if ($path == "" || $path == "/") { global $FAKEDIRS; $sharedItems = OC_SHARE::getItemsSharedWith(); foreach ($sharedItems as $item) { - $files[] = $item['target']; + // TODO Implement a better fix + $files[] = substr($item['target'], strpos($item['target'], "Share") + 5); } $FAKEDIRS['shared'] = $files; return opendir('fakedir://shared'); @@ -242,8 +242,7 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { if ($path == "" || $path == "/") { return true; } else { - $target = OC_FILESYSTEM::getStorageMountPoint($this).$path; - return OC_SHARE::isWriteable($target); + return OC_SHARE::isWriteable($this->datadir.$path); } } @@ -346,14 +345,11 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { public function unlink($path) { // The file will be removed from the database, but won't be deleted from the owner's filesystem - $target = OC_FILESYSTEM::getStorageMountPoint($this).$path; - OC_SHARE::unshareFromSelf($target); + OC_SHARE::unshareFromSelf($this->datadir.$path); } public function rename($path1, $path2) { - $oldTarget = OC_FILESYSTEM::getStorageMountPoint($this).$path1; - $newTarget = OC_FILESYSTEM::getStorageMountPoint($this).$path2; - OC_SHARE::setTarget($oldTarget, $newTarget); + OC_SHARE::setTarget($this->datadir.$path1, $this->datadir.$path2); } public function copy($path1, $path2) { diff --git a/lib/base.php b/lib/base.php index 4250274c7c3..d369b392a4f 100644 --- a/lib/base.php +++ b/lib/base.php @@ -166,7 +166,7 @@ class OC_UTIL { OC_FILESYSTEM::mount($rootStorage,'/'); // TODO add this storage provider in a proper way - $sharedStorage = OC_FILESYSTEM::createStorage('shared',array('datadir'=>$CONFIG_DATADIRECTORY)); + $sharedStorage = OC_FILESYSTEM::createStorage('shared',array('datadir'=>'/MTGap/files/Share/')); OC_FILESYSTEM::mount($sharedStorage,'MTGap/files/Share/'); $CONFIG_DATADIRECTORY = "$CONFIG_DATADIRECTORY_ROOT/$user/$root"; diff --git a/lib/filesystem.php b/lib/filesystem.php index c7e2070fa0a..1f96e139ab3 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -215,15 +215,6 @@ class OC_FILESYSTEM{ return $foundMountPoint; } - /** - * get the mountpoint of the storage object - * @param OC_FILESTORAGE storage - * @return string - */ - static public function getStorageMountPoint($storage){ - return array_search($storage, self::$storages); - } - /** * return the path to a local version of the file * we need this because we can't know if a file is stored local or not from outside the filestorage and for some purposes a local file is needed -- cgit v1.2.3 From 5896e4875550a30d09c3fd54dc1daaec7c68165d Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 13 Jul 2011 13:30:22 -0400 Subject: Add missing argument for fromTmpFile() inside of rename() --- 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 3bb0239e9f1..2c26667bbee 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -384,7 +384,7 @@ class OC_FILESYSTEM{ } }elseif($storage1=self::getStorage($path1) and $storage2=self::getStorage($path2)){ $tmpFile=$storage1->toTmpFile(self::getInternalPath($path1)); - $result=$storage2->fromTmpFile(self::getInternalPath($path2)); + $result=$storage2->fromTmpFile($tmpFile,self::getInternalPath($path2)); $storage1->unlink(self::getInternalPath($path1)); } OC_HOOK::emit( 'OC_FILESYSTEM', 'post_rename', array( 'oldpath' => $path1, 'newpath'=>$path2)); -- cgit v1.2.3 From 1cfa911ce38a22788fae73e0770156263fdc03e5 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 20 Jul 2011 14:42:48 -0400 Subject: Update database.xml to current database fields, remove hard coded MTGap when mounting shared storage provider --- apps/files_sharing/appinfo/.database.xml.kate-swp | Bin 0 -> 34 bytes apps/files_sharing/appinfo/database.xml | 24 ++++++++-------------- lib/base.php | 4 ++-- 3 files changed, 11 insertions(+), 17 deletions(-) create mode 100644 apps/files_sharing/appinfo/.database.xml.kate-swp (limited to 'lib') diff --git a/apps/files_sharing/appinfo/.database.xml.kate-swp b/apps/files_sharing/appinfo/.database.xml.kate-swp new file mode 100644 index 00000000000..f2127b00c76 Binary files /dev/null and b/apps/files_sharing/appinfo/.database.xml.kate-swp differ diff --git a/apps/files_sharing/appinfo/database.xml b/apps/files_sharing/appinfo/database.xml index bb80484bd63..3378b6b09e5 100644 --- a/apps/files_sharing/appinfo/database.xml +++ b/apps/files_sharing/appinfo/database.xml @@ -8,40 +8,34 @@ *dbprefix*sharing - item + uid_owner text true - 128 + 64 - source + uid_shared_with text true - 128 + 64 - target + source text true 128 - uid_owner + target text true - 64 + 128 - uid_shared_with - text - true - 64 - - permissions - text + integer true - 3 + 1 diff --git a/lib/base.php b/lib/base.php index d369b392a4f..9218861ed5b 100644 --- a/lib/base.php +++ b/lib/base.php @@ -166,8 +166,8 @@ class OC_UTIL { OC_FILESYSTEM::mount($rootStorage,'/'); // TODO add this storage provider in a proper way - $sharedStorage = OC_FILESYSTEM::createStorage('shared',array('datadir'=>'/MTGap/files/Share/')); - OC_FILESYSTEM::mount($sharedStorage,'MTGap/files/Share/'); + $sharedStorage = OC_FILESYSTEM::createStorage('shared',array('datadir'=>'/'.$_SESSION['user_id'].'/files/Share/')); + OC_FILESYSTEM::mount($sharedStorage,'/'.$_SESSION['user_id'].'/files/Share/'); $CONFIG_DATADIRECTORY = "$CONFIG_DATADIRECTORY_ROOT/$user/$root"; if( !is_dir( $CONFIG_DATADIRECTORY )){ -- cgit v1.2.3 From 6af4c465b8810926561406d38c1ba6bba69edf83 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 20 Jul 2011 16:52:01 -0400 Subject: Change all occurences of ['user_id'] to OC_USER::getUser() --- apps/files_sharing/lib_share.php | 40 ++++++++++++++++++------------------ apps/files_sharing/sharedstorage.php | 4 ++-- lib/base.php | 4 ++-- 3 files changed, 24 insertions(+), 24 deletions(-) (limited to 'lib') diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index ae730a21a5e..0cb2dea72c7 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -36,8 +36,8 @@ class OC_SHARE { */ public function __construct($source, $uid_shared_with, $permissions, $public = false) { if ($source && OC_FILESYSTEM::file_exists($source) && OC_FILESYSTEM::is_readable($source)) { - $source = "/".$_SESSION['user_id']."/files".$source; - $uid_owner = $_SESSION['user_id']; + $source = "/".OC_USER::getUser()."/files".$source; + $uid_owner = OC_USER::getUser(); if ($public) { // TODO create token for public file $token = sha1("$uid_owner-$item"); @@ -83,7 +83,7 @@ class OC_SHARE { $source = $folders['source'].substr($oldTarget, strlen($folders['target'])); $item = self::getItem($folders['target']); $query = OC_DB::prepare("INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)"); - $query->execute(array($item[0]['uid_owner'], $_SESSION['user_id'], $source, $newTarget, $item[0]['is_writeable'])); + $query->execute(array($item[0]['uid_owner'], OC_USER::getUser(), $source, $newTarget, $item[0]['is_writeable'])); } /** @@ -93,7 +93,7 @@ class OC_SHARE { */ public static function getItem($target) { $query = OC_DB::prepare("SELECT uid_owner, source, is_writeable FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ? LIMIT 1"); - return $query->execute(array($target, $_SESSION['user_id']))->fetchAll(); + return $query->execute(array($target, OC_USER::getUser()))->fetchAll(); } /** @@ -102,7 +102,7 @@ class OC_SHARE { */ public static function getMySharedItems() { $query = OC_DB::prepare("SELECT uid_shared_with, source, is_writeable FROM *PREFIX*sharing WHERE uid_owner = ?"); - return $query->execute(array($_SESSION['user_id']))->fetchAll(); + return $query->execute(array(OC_USER::getUser()))->fetchAll(); } /** @@ -121,7 +121,7 @@ class OC_SHARE { // Remove any duplicate '/' $targetFolder = preg_replace('{(/)\1+}', "/", $targetFolder); $query = OC_DB::prepare("SELECT uid_owner, source, target FROM *PREFIX*sharing WHERE target COLLATE latin1_bin LIKE ? AND uid_shared_with = ?"); - return $query->execute(array($targetFolder."%", $_SESSION['user_id']))->fetchAll(); + return $query->execute(array($targetFolder."%", OC_USER::getUser()))->fetchAll(); } /** @@ -139,7 +139,7 @@ class OC_SHARE { while ($target != "" && $target != "/" && $target != "." && $target != $userDirectory) { // Check if the parent directory of this target location is shared $target = dirname($target); - $result = $query->execute(array($target, $_SESSION['user_id']))->fetchAll(); + $result = $query->execute(array($target, OC_USER::getUser()))->fetchAll(); if (count($result) > 0) { break; } @@ -162,7 +162,7 @@ class OC_SHARE { $target = rtrim($target, "/"); $target = preg_replace('{(/)\1+}', "/", $target); $query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ? LIMIT 1"); - $result = $query->execute(array($target, $_SESSION['user_id']))->fetchAll(); + $result = $query->execute(array($target, OC_USER::getUser()))->fetchAll(); if (count($result) > 0) { return $result[0]['source']; } else { @@ -182,13 +182,13 @@ class OC_SHARE { */ public static function isWriteable($target) { $query = OC_DB::prepare("SELECT is_writeable FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ? LIMIT 1"); - $result = $query->execute(array($target, $_SESSION['user_id']))->fetchAll(); + $result = $query->execute(array($target, OC_USER::getUser()))->fetchAll(); if (count($result) > 0) { return $result[0]['is_writeable']; } else { // Check if the folder is writeable $folders = OC_SHARE::getParentFolders($target); - $result = $query->execute(array($folders['target'], $_SESSION['user_id']))->fetchAll(); + $result = $query->execute(array($folders['target'], OC_USER::getUser()))->fetchAll(); if (count($result) > 0) { return $result[0]['is_writeable']; } else { @@ -204,7 +204,7 @@ class OC_SHARE { */ public static function setSource($oldSource, $newSource) { $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET source = REPLACE(source, ?, ?) WHERE uid_owner = ?"); - $query->execute(array($oldSource, $newSource, $_SESSION['user_id'])); + $query->execute(array($oldSource, $newSource, OC_USER::getUser())); } /** @@ -217,7 +217,7 @@ class OC_SHARE { */ public static function setTarget($oldTarget, $newTarget) { $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET target = REPLACE(target, ?, ?) WHERE uid_shared_with = ?"); - $query->execute(array($oldTarget, $newTarget, $_SESSION['user_id'])); + $query->execute(array($oldTarget, $newTarget, OC_USER::getUser())); } /** @@ -232,7 +232,7 @@ class OC_SHARE { public static function setIsWriteable($source, $uid_shared_with, $is_writeable) { $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET is_writeable = ? WHERE source COLLATE latin1_bin LIKE ? AND uid_shared_with = ? AND uid_owner = ?"); foreach ($uid_shared_with as $uid) { - $query->execute(array($is_writeable, $source."%", $uid_shared_with, $_SESSION['user_id'])); + $query->execute(array($is_writeable, $source."%", $uid_shared_with, OC_USER::getUser())); } } @@ -247,7 +247,7 @@ class OC_SHARE { public static function unshare($source, $uid_shared_with) { $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE source COLLATE latin1_bin LIKE ? AND uid_shared_with = ? AND uid_owner = ?"); foreach ($uid_shared_with as $uid) { - $query->execute(array($source."%", $uid, $_SESSION['user_id'])); + $query->execute(array($source."%", $uid, OC_USER::getUser())); } } @@ -260,7 +260,7 @@ class OC_SHARE { */ public static function unshareFromMySelf($target) { $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE target COLLATE latin1_bin LIKE ? AND uid_shared_with = ?"); - $query->execute(array($target."%", $_SESSION['user_id'])); + $query->execute(array($target."%", OC_USER::getUser())); } /** @@ -268,9 +268,9 @@ class OC_SHARE { * @param $arguments Array of arguments passed from OC_HOOK */ public static function deleteItem($arguments) { - $source = "/".$_SESSION['user_id']."/files".$arguments['path']; + $source = "/".OC_USER::getUser()."/files".$arguments['path']; $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE source COLLATE latin1_bin LIKE ? AND uid_owner = ?"); - $query->execute(array($source."%", $_SESSION['user_id'])); + $query->execute(array($source."%", OC_USER::getUser())); } /** @@ -278,10 +278,10 @@ class OC_SHARE { * @param $arguments Array of arguments passed from OC_HOOK */ public static function renameItem($arguments) { - $oldSource = "/".$_SESSION['user_id']."/files".$arguments['oldpath']; - $newSource = "/".$_SESSION['user_id']."/files".$arguments['newpath']; + $oldSource = "/".OC_USER::getUser()."/files".$arguments['oldpath']; + $newSource = "/".OC_USER::getUser()."/files".$arguments['newpath']; $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET source = REPLACE(source, ?, ?) WHERE uid_owner = ?"); - $query->execute(array($oldSource, $newSource, $_SESSION['user_id'])); + $query->execute(array($oldSource, $newSource, OC_USER::getUser())); } } diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index b27d91de966..5fc2cc67b74 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -203,7 +203,7 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { public function getFolderSize($path) { if ($path == "" || $path == "/") { - $dbpath = $_SESSION['user_id']."/files/Share/"; + $dbpath = OC_USER::getUser()."/files/Share/"; } else { $source = $this->getSource($path); $dbpath = $this->getInternalPath($source); @@ -239,7 +239,7 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { } if ($size > 0) { if ($path == "" || $path == "/") { - $dbpath = $_SESSION['user_id']."/files/Share/"; + $dbpath = OC_USER::getUser()."/files/Share/"; } else { $source = $this->getSource($path); $dbpath = $this->getInternalPath($source); diff --git a/lib/base.php b/lib/base.php index 9218861ed5b..de0df40fc3f 100644 --- a/lib/base.php +++ b/lib/base.php @@ -166,8 +166,8 @@ class OC_UTIL { OC_FILESYSTEM::mount($rootStorage,'/'); // TODO add this storage provider in a proper way - $sharedStorage = OC_FILESYSTEM::createStorage('shared',array('datadir'=>'/'.$_SESSION['user_id'].'/files/Share/')); - OC_FILESYSTEM::mount($sharedStorage,'/'.$_SESSION['user_id'].'/files/Share/'); + $sharedStorage = OC_FILESYSTEM::createStorage('shared',array('datadir'=>'/'.OC_USER::getUser().'/files/Share/')); + OC_FILESYSTEM::mount($sharedStorage,'/'.OC_USER::getUser().'/files/Share/'); $CONFIG_DATADIRECTORY = "$CONFIG_DATADIRECTORY_ROOT/$user/$root"; if( !is_dir( $CONFIG_DATADIRECTORY )){ -- cgit v1.2.3 From ddfc9fc001904232236baee7bf9a5a934354ac95 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Mon, 1 Aug 2011 10:58:15 -0400 Subject: Move registering shared storage out of base --- apps/files_sharing/appinfo/app.php | 2 ++ lib/base.php | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index e7e19869d2a..4ff0bc510ca 100644 --- a/apps/files_sharing/appinfo/app.php +++ b/apps/files_sharing/appinfo/app.php @@ -1,7 +1,9 @@ "string")); OC_Util::addScript("files_sharing", "share"); OC_App::addNavigationSubEntry("files_index", array( "id" => "files_sharing_list", diff --git a/lib/base.php b/lib/base.php index 5a5381a890e..b2cbde5679c 100644 --- a/lib/base.php +++ b/lib/base.php @@ -107,8 +107,6 @@ if(!$error and !$RUNTIME_NOAPPS ){ // Was in required file ... put it here OC_Filesystem::registerStorageType('local','OC_Filestorage_Local',array('datadir'=>'string')); -require_once('apps/files_sharing/sharedstorage.php'); -OC_Filesystem::registerStorageType('shared','OC_Filestorage_Shared',array('datadir'=>'string')); // Set up file system unless forbidden if(!$error and !$RUNTIME_NOSETUPFS ){ -- cgit v1.2.3 From ffe9da91af72e7f7953f41968f536d15390edffe Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Fri, 12 Aug 2011 20:51:01 -0400 Subject: Add missing parameter to usersInGroup() --- lib/group.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/group.php b/lib/group.php index 65a23989a27..fbff41e30e9 100644 --- a/lib/group.php +++ b/lib/group.php @@ -249,6 +249,6 @@ class OC_Group { * @returns array with user ids */ public static function usersInGroup($gid){ - return self::$_backend->usersInGroup(); + return self::$_backend->usersInGroup($gid); } } -- cgit v1.2.3 From 5fbed936bffa1dc06e5356a89f079fe27aa624b2 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Mon, 15 Aug 2011 20:33:02 -0400 Subject: Automatic creation of 'Shared' directory, bug fixes for an empty 'Shared' directory --- apps/files_sharing/lib_share.php | 2 +- apps/files_sharing/sharedstorage.php | 42 ++++++++++++++++++++---------------- lib/util.php | 4 ++-- 3 files changed, 27 insertions(+), 21 deletions(-) (limited to 'lib') diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index b87775dd8c5..a42fed3e763 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -59,7 +59,7 @@ class OC_Share { throw new Exception("This item is already shared with ".$uid); } // Check if the target already exists for the user, if it does append a number to the name - $target = "/".$uid."/files/Share/".basename($source); + $target = "/".$uid."/files/Shared/".basename($source); if (self::getSource($target)) { if ($pos = strrpos($target, ".")) { $name = substr($target, 0, $pos); diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 11b141373c4..55254ccd662 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -32,6 +32,9 @@ class OC_Filestorage_Shared extends OC_Filestorage { public function __construct($arguments) { $this->datadir = $arguments['datadir']; + if (!OC_Filesystem::is_dir($this->datadir)) { + OC_Filesystem::mkdir($this->datadir); + } } public function getInternalPath($path) { @@ -309,14 +312,15 @@ class OC_Filestorage_Shared extends OC_Filestorage { public function filectime($path) { if ($path == "" || $path == "/") { $ctime = 0; - $dir = $this->opendir($path); - while (($filename = readdir($dir)) != false) { - $tempctime = $this->filectime($filename); - if ($tempctime < $ctime) { - $ctime = $tempctime; + if ($dh = $this->opendir($path)) { + while (($filename = readdir($dh)) !== false) { + $tempctime = $this->filectime($filename); + if ($tempctime < $ctime) { + $ctime = $tempctime; + } } + return $ctime; } - return $ctime; } else { $source = $this->getSource($path); if ($source) { @@ -329,14 +333,15 @@ class OC_Filestorage_Shared extends OC_Filestorage { public function filemtime($path) { if ($path == "" || $path == "/") { $mtime = 0; - $dir = $this->opendir($path); - while (($filename = readdir($dir)) != false) { - $tempmtime = $this->filemtime($filename); - if ($tempmtime > $mtime) { - $mtime = $tempmtime; + if ($dh = $this->opendir($path)) { + while (($filename = readdir($dh)) !== false) { + $tempmtime = $this->filemtime($filename); + if ($tempmtime > $mtime) { + $mtime = $tempmtime; + } } + return $mtime; } - return $mtime; } else { $source = $this->getSource($path); if ($source) { @@ -349,14 +354,15 @@ class OC_Filestorage_Shared extends OC_Filestorage { public function fileatime($path) { if ($path == "" || $path == "/") { $atime = 0; - $dir = $this->opendir($path); - while (($filename = readdir($dir)) != false) { - $tempatime = $this->fileatime($filename); - if ($tempatime > $atime) { - $atime = $tempatime; + if ($dh = $this->opendir($path)) { + while (($filename = readdir($dh)) !== false) { + $tempatime = $this->fileatime($filename); + if ($tempatime > $atime) { + $atime = $tempatime; + } } + return $atime; } - return $atime; } else { $source = $this->getSource($path); if ($source) { diff --git a/lib/util.php b/lib/util.php index 53c4283be11..4b49d1319b9 100644 --- a/lib/util.php +++ b/lib/util.php @@ -54,8 +54,8 @@ class OC_Util { OC_Filesystem::mount($rootStorage,'/'); // TODO add this storage provider in a proper way - $sharedStorage = OC_Filesystem::createStorage('shared',array('datadir'=>'/'.OC_User::getUser().'/files/Share/')); - OC_Filesystem::mount($sharedStorage,'/'.OC_User::getUser().'/files/Share/'); + $sharedStorage = OC_Filesystem::createStorage('shared',array('datadir'=>'/'.OC_User::getUser().'/files/Shared/')); + OC_Filesystem::mount($sharedStorage,'/'.OC_User::getUser().'/files/Shared/'); $CONFIG_DATADIRECTORY = "$CONFIG_DATADIRECTORY_ROOT/$user/$root"; if( !is_dir( $CONFIG_DATADIRECTORY )){ -- cgit v1.2.3 From e4c987129963a95e3f9468a4780fa25ce6abf2fd Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Mon, 15 Aug 2011 20:45:07 -0400 Subject: This should actually make the 'Shared' directory automatically everytime --- apps/files_sharing/sharedstorage.php | 1 + lib/util.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 55254ccd662..271819782b7 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -35,6 +35,7 @@ class OC_Filestorage_Shared extends OC_Filestorage { if (!OC_Filesystem::is_dir($this->datadir)) { OC_Filesystem::mkdir($this->datadir); } + $this->datadir .= "/"; } public function getInternalPath($path) { diff --git a/lib/util.php b/lib/util.php index 4b49d1319b9..f4ca879a9bc 100644 --- a/lib/util.php +++ b/lib/util.php @@ -54,7 +54,7 @@ class OC_Util { OC_Filesystem::mount($rootStorage,'/'); // TODO add this storage provider in a proper way - $sharedStorage = OC_Filesystem::createStorage('shared',array('datadir'=>'/'.OC_User::getUser().'/files/Shared/')); + $sharedStorage = OC_Filesystem::createStorage('shared',array('datadir'=>'/'.OC_User::getUser().'/files/Shared')); OC_Filesystem::mount($sharedStorage,'/'.OC_User::getUser().'/files/Shared/'); $CONFIG_DATADIRECTORY = "$CONFIG_DATADIRECTORY_ROOT/$user/$root"; -- cgit v1.2.3