diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php index 72a8a39e57..7fab7e2cce 100644 --- a/apps/files_sharing/lib_share.php +++ b/apps/files_sharing/lib_share.php @@ -173,6 +173,18 @@ class OC_SHARE { return false; } } + + /** + * Get the files within a shared folder that have their own entry for the purpose of name, location, or permissions that differ from the folder itself + * @param $sourceFolder The source folder of the files to look for + * @return array An array of the files if any + */ + public static function getSharedFilesIn($sourceFolder) { + // Append '/' in order to filter out the folder itself + $sourceFolder = $sourceFolder."/"; + $query = OC_DB::prepare("SELECT source, target FROM *PREFIX*sharing WHERE source COLLATE latin1_bin LIKE ? AND uid_shared_with = ?"); + return $query->execute(array($sourceFolder."%", $_SESSION['user_id']))->fetchAll(); + } /** * Set the target location to a new value diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index 992ccc8e59..3b678178c3 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -74,7 +74,6 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { OC_SHARE::unshareFromSelf($target); } - // TODO Change files within shared folders that are renamed public function opendir($path) { if ($path == "" || $path == "/") { global $FAKEDIRS; @@ -88,7 +87,28 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE { $source = $this->getSource($path); if ($source) { $storage = OC_FILESYSTEM::getStorage($source); - return $storage->opendir($this->getInternalPath($source)); + $dh = $storage->opendir($this->getInternalPath($source)); + $modifiedItems = OC_SHARE::getSharedFilesIn($source); + if ($modifiedItems && $dh) { + global $FAKEDIRS; + $sources = array(); + $targets = array(); + foreach ($modifiedItems as $item) { + $sources[] = basename($item['source']); + $targets[] = basename($item['target']); + } + while (($filename = readdir($dh)) !== false) { + if (!in_array($filename, $sources)) { + $files[] = $filename; + } else { + $files[] = $targets[array_search($filename, $sources)]; + } + } + $FAKEDIRS['shared'] = $files; + return opendir('fakedir://shared'); + } else { + return $dh; + } } } }