Skip to content
Snippets Groups Projects
Commit 010920ad authored by Michael Gapczynski's avatar Michael Gapczynski
Browse files

Add support for files inside of shared folders having different names than the source file

parent 73bab467
Branches
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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;
}
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment