Beispiel #1
0
	public function testFakeDir() {
		$items = array('foo', 'bar');
		\OC\Files\Stream\Dir::register('test', $items);
		$dh = opendir('fakedir://test');
		$result = array();
		while ($file = readdir($dh)) {
			$result[] = $file;
			$this->assertContains($file, $items);
		}
		$this->assertEquals(count($items), count($result));
	}
 public function opendir($path)
 {
     \OCP\Util::writeLog('groupoffice', 'opendir: ' . $path, \OCP\Util::DEBUG);
     if ($path == '' || $path == '/') {
         $files = array();
         $files[] = 'ownFolder';
         $shares = \GO\Files\Model\Folder::model()->getTopLevelShares(\GO\Base\Db\FindParams::newInstance()->limit(100));
         foreach ($shares as $folder) {
             $files[] = $folder->name;
         }
         \OC\Files\Stream\Dir::register('groupoffice' . $path, $files);
         return opendir('fakedir://groupoffice' . $path);
     } else {
         return opendir($this->groupoffice_data . $this->get_real_path($path));
     }
 }
Beispiel #3
0
 public function opendir($path)
 {
     $files = array('.', '..');
     $physicalPath = $this->buildPath($path);
     $logicalPath = $this->mapper->physicalToLogic($physicalPath);
     $dh = opendir($physicalPath);
     while ($file = readdir($dh)) {
         if ($file === '.' or $file === '..') {
             continue;
         }
         $logicalFilePath = $this->mapper->physicalToLogic($physicalPath . '/' . $file);
         $file = $this->mapper->stripRootFolder($logicalFilePath, $logicalPath);
         $file = $this->stripLeading($file);
         $files[] = $file;
     }
     \OC\Files\Stream\Dir::register('local-win32' . $path, $files);
     return opendir('fakedir://local-win32' . $path);
 }
Beispiel #4
0
 public function opendir($path)
 {
     if (substr($path, -1) !== '/') {
         $path .= '/';
     }
     $path = $this->stripPath($path);
     $files = $this->archive->getFolder($path);
     $content = array();
     foreach ($files as $file) {
         if (substr($file, -1) == '/') {
             $file = substr($file, 0, -1);
         }
         if ($file and strpos($file, '/') === false) {
             $content[] = $file;
         }
     }
     $id = md5($this->path . $path);
     \OC\Files\Stream\Dir::register($id, $content);
     return opendir('fakedir://' . $id);
 }
Beispiel #5
0
 /**
  * {@inheritdoc}
  */
 public function opendir($path)
 {
     try {
         $list = $this->getConnection()->nlist($this->absPath($path));
         if ($list === false) {
             return false;
         }
         $id = md5('sftp:' . $path);
         $dirStream = array();
         foreach ($list as $file) {
             if ($file != '.' && $file != '..') {
                 $dirStream[] = $file;
             }
         }
         \OC\Files\Stream\Dir::register($id, $dirStream);
         return opendir('fakedir://' . $id);
     } catch (\Exception $e) {
         return false;
     }
 }
 public function opendir($path)
 {
     $path = $this->normalizePath($path);
     try {
         $files = array();
         $folderContents = $this->getCache()->getFolderContents($path);
         foreach ($folderContents as $file) {
             $files[] = $file['name'];
         }
         \OC\Files\Stream\Dir::register('objectstore' . $path . '/', $files);
         return opendir('fakedir://objectstore' . $path . '/');
     } catch (Exception $e) {
         \OCP\Util::writeLog('objectstore', $e->getMessage(), \OCP\Util::ERROR);
         return false;
     }
 }
Beispiel #7
0
 public function opendir($path)
 {
     $path = $this->normalizePath($path);
     if ($path === '.') {
         $path = '';
     } else {
         $path .= '/';
     }
     $path = str_replace('%23', '#', $path);
     // the prefix is sent as a query param, so revert the encoding of #
     try {
         $files = array();
         /** @var OpenCloud\Common\Collection $objects */
         $objects = $this->container->objectList(array('prefix' => $path, 'delimiter' => '/'));
         /** @var OpenCloud\ObjectStore\Resource\DataObject $object */
         foreach ($objects as $object) {
             $file = basename($object->getName());
             if ($file !== basename($path)) {
                 $files[] = $file;
             }
         }
         \OC\Files\Stream\Dir::register('swift' . $path, $files);
         return opendir('fakedir://swift' . $path);
     } catch (\Exception $e) {
         \OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
         return false;
     }
 }
Beispiel #8
0
 public function opendir($path)
 {
     $this->init();
     $path = $this->cleanPath($path);
     try {
         $response = $this->client->propfind($this->encodePath($path), array(), 1);
         $id = md5('webdav' . $this->root . $path);
         $content = array();
         $files = array_keys($response);
         array_shift($files);
         //the first entry is the current directory
         foreach ($files as $file) {
             $file = urldecode(basename($file));
             $content[] = $file;
         }
         \OC\Files\Stream\Dir::register($id, $content);
         return opendir('fakedir://' . $id);
     } catch (\Exception $e) {
         return false;
     }
 }
Beispiel #9
0
 /** {@inheritdoc} */
 public function opendir($path)
 {
     $this->init();
     $path = $this->cleanPath($path);
     try {
         $response = $this->client->propfind($this->encodePath($path), array(), 1);
         $id = md5('webdav' . $this->root . $path);
         $content = array();
         $files = array_keys($response);
         array_shift($files);
         //the first entry is the current directory
         if (!$this->statCache->hasKey($path)) {
             $this->statCache->set($path, true);
         }
         foreach ($files as $file) {
             $file = urldecode($file);
             // do not store the real entry, we might not have all properties
             if (!$this->statCache->hasKey($path)) {
                 $this->statCache->set($file, true);
             }
             $file = basename($file);
             $content[] = $file;
         }
         Dir::register($id, $content);
         return opendir('fakedir://' . $id);
     } catch (ClientHttpException $e) {
         if ($e->getHttpStatus() === 404) {
             $this->statCache->clear($path . '/');
             $this->statCache->set($path, false);
             return false;
         }
         $this->convertException($e);
     } catch (\Exception $e) {
         $this->convertException($e);
     }
     return false;
 }
Beispiel #10
0
 public function opendir($path)
 {
     if ($path == '' || $path == '/') {
         $files = \OCP\Share::getItemsSharedWith('file', \OC_Share_Backend_Folder::FORMAT_OPENDIR);
         \OC\Files\Stream\Dir::register('shared', $files);
         return opendir('fakedir://shared');
     } else {
         if ($source = $this->getSourcePath($path)) {
             list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
             return $storage->opendir($internalPath);
         }
     }
     return false;
 }
Beispiel #11
0
 public function opendir($path)
 {
     $path = $this->normalizePath($path);
     if ($this->isRoot($path)) {
         $path = '';
     } else {
         $path .= '/';
     }
     try {
         $files = array();
         $result = $this->getConnection()->getIterator('ListObjects', array('Bucket' => $this->bucket, 'Delimiter' => '/', 'Prefix' => $path), array('return_prefixes' => true));
         foreach ($result as $object) {
             if (isset($object['Key']) && $object['Key'] === $path) {
                 // it's the directory itself, skip
                 continue;
             }
             $file = basename(isset($object['Key']) ? $object['Key'] : $object['Prefix']);
             $files[] = $file;
         }
         \OC\Files\Stream\Dir::register('amazons3' . $path, $files);
         return opendir('fakedir://amazons3' . $path);
     } catch (S3Exception $e) {
         \OCP\Util::logException('files_external', $e);
         return false;
     }
 }
Beispiel #12
0
 public function opendir($path)
 {
     if ($path == '' || $path == '/') {
         $next = self::BASE_URI . '/default/private/full/folder%3Aroot/contents';
     } else {
         $entry = $this->getResource($path);
         if ($entry) {
             $next = $entry->getElementsByTagName('content')->item(0)->getAttribute('src');
         } else {
             return false;
         }
     }
     $files = array();
     while ($next) {
         $dom = $this->getFeed($next, 'GET');
         $links = $dom->getElementsByTagName('link');
         foreach ($links as $link) {
             if ($link->getAttribute('rel') == 'next') {
                 $next = $link->getAttribute('src');
                 break;
             } else {
                 $next = false;
             }
         }
         $entries = $dom->getElementsByTagName('entry');
         foreach ($entries as $entry) {
             $name = $entry->getElementsByTagName('title')->item(0)->nodeValue;
             // Google Docs resources don't always include extensions in title
             if (!strpos($name, '.')) {
                 $extension = $this->getExtension($entry);
                 if ($extension != '') {
                     $name .= '.' . $extension;
                 }
             }
             $files[] = basename($name);
             // Cache entry for future use
             $this->entries[$name] = $entry;
         }
     }
     \OC\Files\Stream\Dir::register('google' . $path, $files);
     return opendir('fakedir://google' . $path);
 }
Beispiel #13
0
 public function opendir($path)
 {
     $path = $this->normalizePath($path);
     if ($path === '.') {
         $path = '';
     } else {
         $path .= '/';
     }
     try {
         $files = array();
         $objects = $this->container->ObjectList(array('prefix' => $path, 'delimiter' => '/'));
         while ($object = $objects->Next()) {
             $file = basename($object->Name());
             if ($file !== basename($path)) {
                 $files[] = $file;
             }
         }
         \OC\Files\Stream\Dir::register('swift' . $path, $files);
         return opendir('fakedir://swift' . $path);
     } catch (Exception $e) {
         \OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
         return false;
     }
 }
Beispiel #14
0
 public function opendir($path)
 {
     $this->init();
     $path = $this->cleanPath($path);
     try {
         $response = $this->client->propfind($this->encodePath($path), array(), 1);
         $id = md5('webdav' . $this->root . $path);
         $content = array();
         $files = array_keys($response);
         array_shift($files);
         //the first entry is the current directory
         foreach ($files as $file) {
             $file = urldecode(basename($file));
             $content[] = $file;
         }
         \OC\Files\Stream\Dir::register($id, $content);
         return opendir('fakedir://' . $id);
     } catch (Exception\NotFound $e) {
         return false;
     } catch (\Exception $e) {
         // TODO: log for now, but in the future need to wrap/rethrow exception
         \OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
         return false;
     }
 }
Beispiel #15
0
 public function opendir($path)
 {
     $path = $this->normalizePath($path);
     if ($path === '.') {
         $path = '';
     } else {
         if ($path) {
             $path .= '/';
         }
     }
     try {
         $files = array();
         $result = $this->connection->getIterator('ListObjects', array('Bucket' => $this->bucket, 'Delimiter' => '/', 'Prefix' => $path), array('return_prefixes' => true));
         foreach ($result as $object) {
             $file = basename(isset($object['Key']) ? $object['Key'] : $object['Prefix']);
             if ($file != basename($path)) {
                 $files[] = $file;
             }
         }
         \OC\Files\Stream\Dir::register('amazons3' . $path, $files);
         return opendir('fakedir://amazons3' . $path);
     } catch (S3Exception $e) {
         \OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
         return false;
     }
 }
Beispiel #16
0
 public function opendir($path)
 {
     $contents = $this->getMetaData($path, true);
     if ($contents !== false) {
         $files = array();
         foreach ($contents as $file) {
             $files[] = basename($file['path']);
         }
         \OC\Files\Stream\Dir::register('dropbox' . $path, $files);
         return opendir('fakedir://dropbox' . $path);
     }
     return false;
 }
Beispiel #17
0
 public function opendir($path)
 {
     // Remove leading and trailing slashes
     $path = trim($path, '/');
     $folder = $this->getDriveFile($path);
     if ($folder) {
         $files = array();
         $duplicates = array();
         $pageToken = true;
         while ($pageToken) {
             $params = array();
             if ($pageToken !== true) {
                 $params['pageToken'] = $pageToken;
             }
             $params['q'] = "'" . $folder->getId() . "' in parents and trashed = false";
             $children = $this->service->files->listFiles($params);
             foreach ($children->getItems() as $child) {
                 $name = $child->getTitle();
                 // Check if this is a Google Doc i.e. no extension in name
                 if ($child->getFileExtension() === '' && $child->getMimeType() !== self::FOLDER) {
                     $name .= '.' . $this->getGoogleDocExtension($child->getMimeType());
                 }
                 if ($path === '') {
                     $filepath = $name;
                 } else {
                     $filepath = $path . '/' . $name;
                 }
                 // Google Drive allows files with the same name, ownCloud doesn't
                 // Prevent opendir() from returning any duplicate files
                 $key = array_search($name, $files);
                 if ($key !== false || isset($duplicates[$filepath])) {
                     if (!isset($duplicates[$filepath])) {
                         $duplicates[$filepath] = true;
                         $this->setDriveFile($filepath, false);
                         unset($files[$key]);
                         $this->onDuplicateFileDetected($filepath);
                     }
                 } else {
                     // Cache the Google_DriveFile for future use
                     $this->setDriveFile($filepath, $child);
                     $files[] = $name;
                 }
             }
             $pageToken = $children->getNextPageToken();
         }
         \OC\Files\Stream\Dir::register('google' . $path, $files);
         return opendir('fakedir://google' . $path);
     } else {
         return false;
     }
 }
Beispiel #18
0
 public function opendir($path)
 {
     $this->init();
     $container = $this->getContainer($path);
     $files = $this->getObjects($container);
     $i = array_search(self::SUBCONTAINER_FILE, $files);
     if ($i !== false) {
         unset($files[$i]);
     }
     $subContainers = $this->getSubContainers($container);
     $files = array_merge($files, $subContainers);
     $id = $this->getContainerName($path);
     \OC\Files\Stream\Dir::register($id, $files);
     return opendir('fakedir://' . $id);
 }
Beispiel #19
0
 public function opendir($path)
 {
     if ($path == '' || $path == '/') {
         // Use the '/' delimiter to only fetch objects inside the folder
         $opt = array('delimiter' => '/');
     } else {
         if (substr($path, -1) != '/') {
             $path .= '/';
         }
         $opt = array('delimiter' => '/', 'prefix' => $path);
     }
     $response = $this->s3->list_objects($this->bucket, $opt);
     if ($response->isOK()) {
         $files = array();
         foreach ($response->body->Contents as $object) {
             // The folder being opened also shows up in the list of objects, don't add it to the files
             if ($object->Key != $path) {
                 $files[] = basename($object->Key);
             }
         }
         // Sub folders show up as CommonPrefixes
         foreach ($response->body->CommonPrefixes as $object) {
             $files[] = basename($object->Prefix);
         }
         \OC\Files\Stream\Dir::register('amazons3' . $path, $files);
         return opendir('fakedir://amazons3' . $path);
     }
     return false;
 }