Fix bugs in opendir() and add extra checks to ensure functionality in all cases
This commit is contained in:
parent
8ad4a44171
commit
dbcb35655e
|
@ -72,14 +72,16 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE {
|
||||||
OC_SHARE::unshareFromMySelf($this->datadir.$path);
|
OC_SHARE::unshareFromMySelf($this->datadir.$path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Make sure new target is still in the current directory
|
|
||||||
public function opendir($path) {
|
public function opendir($path) {
|
||||||
if ($path == "" || $path == "/") {
|
if ($path == "" || $path == "/") {
|
||||||
global $FAKEDIRS;
|
global $FAKEDIRS;
|
||||||
$sharedItems = OC_SHARE::getItemsInFolder($this->datadir.$path);
|
$path = $this->datadir.$path;
|
||||||
|
$sharedItems = OC_SHARE::getItemsInFolder($path);
|
||||||
foreach ($sharedItems as $item) {
|
foreach ($sharedItems as $item) {
|
||||||
// TODO Implement a better fix
|
// If item is in the root of the shared storage provider add it to the fakedirs
|
||||||
$files[] = substr($item['target'], strpos($item['target'], "Share") + 5);
|
if (dirname($item['target'])."/" == $path) {
|
||||||
|
$files[] = basename($item['target']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$FAKEDIRS['shared'] = $files;
|
$FAKEDIRS['shared'] = $files;
|
||||||
return opendir('fakedir://shared');
|
return opendir('fakedir://shared');
|
||||||
|
@ -88,19 +90,31 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE {
|
||||||
if ($source) {
|
if ($source) {
|
||||||
$storage = OC_FILESYSTEM::getStorage($source);
|
$storage = OC_FILESYSTEM::getStorage($source);
|
||||||
$dh = $storage->opendir($this->getInternalPath($source));
|
$dh = $storage->opendir($this->getInternalPath($source));
|
||||||
$modifiedItems = OC_SHARE::getItemsInFolder($this->datadir.$path);
|
// Remove any duplicate or trailing '/'
|
||||||
|
$path = rtrim($this->datadir.$path, "/");
|
||||||
|
$path = preg_replace('{(/)\1+}', "/", $path);
|
||||||
|
$modifiedItems = OC_SHARE::getItemsInFolder($path);
|
||||||
if ($modifiedItems && $dh) {
|
if ($modifiedItems && $dh) {
|
||||||
global $FAKEDIRS;
|
global $FAKEDIRS;
|
||||||
$sources = array();
|
$sources = array();
|
||||||
$targets = array();
|
$targets = array();
|
||||||
foreach ($modifiedItems as $item) {
|
foreach ($modifiedItems as $item) {
|
||||||
|
// If item is in current directory, add it to the arrays
|
||||||
|
if (dirname($item['target']) == $path) {
|
||||||
$sources[] = basename($item['source']);
|
$sources[] = basename($item['source']);
|
||||||
$targets[] = basename($item['target']);
|
$targets[] = basename($item['target']);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// Don't waste time if there aren't any modified items in the current directory
|
||||||
|
if (empty($sources)) {
|
||||||
|
return $dh;
|
||||||
|
} else {
|
||||||
while (($filename = readdir($dh)) !== false) {
|
while (($filename = readdir($dh)) !== false) {
|
||||||
if ($filename != "." && $filename != "..") {
|
if ($filename != "." && $filename != "..") {
|
||||||
|
// If the file isn't in the sources array it isn't modified and can be added as is
|
||||||
if (!in_array($filename, $sources)) {
|
if (!in_array($filename, $sources)) {
|
||||||
$files[] = $filename;
|
$files[] = $filename;
|
||||||
|
// The file has a different name than the source and is added to the fakedirs
|
||||||
} else {
|
} else {
|
||||||
$files[] = $targets[array_search($filename, $sources)];
|
$files[] = $targets[array_search($filename, $sources)];
|
||||||
}
|
}
|
||||||
|
@ -108,6 +122,7 @@ class OC_FILESTORAGE_SHARED extends OC_FILESTORAGE {
|
||||||
}
|
}
|
||||||
$FAKEDIRS['shared'] = $files;
|
$FAKEDIRS['shared'] = $files;
|
||||||
return opendir('fakedir://shared');
|
return opendir('fakedir://shared');
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return $dh;
|
return $dh;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue