From 5fbed936bffa1dc06e5356a89f079fe27aa624b2 Mon Sep 17 00:00:00 2001 From: Michael Gapczynski <GapczynskiM@gmail.com> Date: Mon, 15 Aug 2011 20:33:02 -0400 Subject: [PATCH] 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(-) diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index b87775dd8c..a42fed3e76 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 11b141373c..55254ccd66 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 53c4283be1..4b49d1319b 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 )){ -- GitLab