Beispiel #1
0
 function setUp()
 {
     parent::setUp();
     \OC_User::setDisplayName(self::TEST_FILES_SHARING_API_USER1, 'User One');
     \OC_User::setDisplayName(self::TEST_FILES_SHARING_API_USER2, 'User Two');
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     $this->user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
     // prepare user1's dir structure
     $this->view->mkdir('container');
     $this->view->mkdir('container/shareddir');
     $this->view->mkdir('container/shareddir/subdir');
     $this->view->mkdir('container/shareddir/emptydir');
     $textData = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
     $this->view->file_put_contents('container/not shared.txt', $textData);
     $this->view->file_put_contents('container/shared single file.txt', $textData);
     $this->view->file_put_contents('container/shareddir/bar.txt', $textData);
     $this->view->file_put_contents('container/shareddir/subdir/another.txt', $textData);
     $this->view->file_put_contents('container/shareddir/subdir/another too.txt', $textData);
     $this->view->file_put_contents('container/shareddir/subdir/not a text file.xml', '<xml></xml>');
     list($this->ownerStorage, $internalPath) = $this->view->resolvePath('');
     $this->ownerCache = $this->ownerStorage->getCache();
     $this->ownerStorage->getScanner()->scan('');
     // share "shareddir" with user2
     $fileinfo = $this->view->getFileInfo('container/shareddir');
     \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
     $fileinfo = $this->view->getFileInfo('container/shared single file.txt');
     \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
     // login as user2
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     // retrieve the shared storage
     $secondView = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2);
     list($this->sharedStorage, $internalPath) = $secondView->resolvePath('files/shareddir');
     $this->sharedCache = $this->sharedStorage->getCache();
 }
Beispiel #2
0
 /**
  * Retrieves the contents of a trash bin directory.
  *
  * @param string $dir path to the directory inside the trashbin
  * or empty to retrieve the root of the trashbin
  * @param string $user
  * @param string $sortAttribute attribute to sort on or empty to disable sorting
  * @param bool $sortDescending true for descending sort, false otherwise
  * @return \OCP\Files\FileInfo[]
  */
 public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDescending = false)
 {
     $result = array();
     $timestamp = null;
     $view = new \OC\Files\View('/' . $user . '/files_trashbin/files');
     if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) {
         throw new \Exception('Directory does not exists');
     }
     $dirContent = $view->opendir($dir);
     if ($dirContent === false) {
         return $result;
     }
     list($storage, $internalPath) = $view->resolvePath($dir);
     $absoluteDir = $view->getAbsolutePath($dir);
     if (is_resource($dirContent)) {
         $originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($user);
         while (($entryName = readdir($dirContent)) !== false) {
             if (!\OC\Files\Filesystem::isIgnoredDir($entryName)) {
                 $id = $entryName;
                 if ($dir === '' || $dir === '/') {
                     $pathparts = pathinfo($entryName);
                     $timestamp = substr($pathparts['extension'], 1);
                     $id = $pathparts['filename'];
                 } else {
                     if ($timestamp === null) {
                         // for subfolders we need to calculate the timestamp only once
                         $parts = explode('/', ltrim($dir, '/'));
                         $timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1);
                     }
                 }
                 $originalPath = '';
                 if (isset($originalLocations[$id][$timestamp])) {
                     $originalPath = $originalLocations[$id][$timestamp];
                     if (substr($originalPath, -1) === '/') {
                         $originalPath = substr($originalPath, 0, -1);
                     }
                 }
                 $i = array('name' => $id, 'mtime' => $timestamp, 'mimetype' => \OC_Helper::getFileNameMimeType($id), 'type' => $view->is_dir($dir . '/' . $entryName) ? 'dir' : 'file', 'directory' => $dir === '/' ? '' : $dir);
                 if ($originalPath) {
                     $i['extraData'] = $originalPath . '/' . $id;
                 }
                 $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i);
             }
         }
         closedir($dirContent);
     }
     if ($sortAttribute !== '') {
         return \OCA\Files\Helper::sortFiles($result, $sortAttribute, $sortDescending);
     }
     return $result;
 }
Beispiel #3
0
 protected function setUp()
 {
     parent::setUp();
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     // prepare user1's dir structure
     $this->view->mkdir('container');
     $this->view->mkdir('container/shareddir');
     $this->view->mkdir('container/shareddir/subdir');
     list($this->ownerStorage, $internalPath) = $this->view->resolvePath('');
     $this->ownerCache = $this->ownerStorage->getCache();
     $this->ownerStorage->getScanner()->scan('');
     // share "shareddir" with user2
     $this->_share = $this->share(\OCP\Share::SHARE_TYPE_USER, 'container/shareddir', self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_ALL);
     // login as user2
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     // retrieve the shared storage
     $secondView = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2);
     list($this->sharedStorage, $internalPath) = $secondView->resolvePath('files/shareddir');
     $this->sharedCache = $this->sharedStorage->getCache();
 }
Beispiel #4
0
 /**
  * Update the cache for changes to $path
  *
  * @param string $path
  * @param array $cachedData
  */
 public function update($path, $cachedData)
 {
     parent::update($path, $cachedData);
     // since parent::update() has already updated the size of the subdirs,
     // only apply the update to the owner's parent dirs
     // find last parent before reaching the shared storage root,
     // which is the actual shared dir from the owner
     $sepPos = strpos($path, '/');
     if ($sepPos > 0) {
         $baseDir = substr($path, 0, $sepPos);
     } else {
         $baseDir = $path;
     }
     // find the path relative to the data dir
     $file = $this->storage->getFile($baseDir);
     $view = new \OC\Files\View('/' . $file['fileOwner']);
     // find the owner's storage and path
     /** @var \OC\Files\Storage\Storage $storage */
     list($storage, $internalPath) = $view->resolvePath($file['path']);
     // update the parent dirs' sizes in the owner's cache
     $storage->getCache()->correctFolderSize(dirname($internalPath));
 }
Beispiel #5
0
 function setUp()
 {
     parent::setUp();
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     // prepare user1's dir structure
     $textData = "dummy file data\n";
     $this->view->mkdir('container');
     $this->view->mkdir('container/shareddir');
     $this->view->mkdir('container/shareddir/subdir');
     list($this->ownerStorage, $internalPath) = $this->view->resolvePath('');
     $this->ownerCache = $this->ownerStorage->getCache();
     $this->ownerStorage->getScanner()->scan('');
     // share "shareddir" with user2
     $fileinfo = $this->view->getFileInfo('container/shareddir');
     \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
     // login as user2
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     // retrieve the shared storage
     $secondView = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2);
     list($this->sharedStorage, $internalPath) = $secondView->resolvePath('files/shareddir');
     $this->sharedCache = $this->sharedStorage->getCache();
 }
Beispiel #6
0
 /**
  * @dataProvider resolvePathTestProvider
  */
 public function testResolvePath($expected, $pathToTest)
 {
     $storage1 = $this->getTestStorage();
     \OC\Files\Filesystem::mount($storage1, array(), '/');
     $view = new \OC\Files\View('');
     $result = $view->resolvePath($pathToTest);
     $this->assertEquals($expected, $result[1]);
     $exists = $view->file_exists($pathToTest);
     $this->assertTrue($exists);
     $exists = $view->file_exists($result[1]);
     $this->assertTrue($exists);
 }
Beispiel #7
0
<?php

require_once __DIR__ . '/../../lib/base.php';
if (OC::$CLI) {
    if (count($argv) === 2) {
        $file = $argv[1];
        list(, $user) = explode('/', $file);
        OCP\JSON::checkUserExists($user);
        OC_Util::setupFS($user);
        $view = new \OC\Files\View('');
        /**
         * @var \OC\Files\Storage\Storage $storage
         */
        list($storage, $internalPath) = $view->resolvePath($file);
        $watcher = $storage->getWatcher($internalPath);
        $watcher->checkUpdate($internalPath);
    } else {
        echo "Usage: php triggerupdate.php /path/to/file\n";
    }
} else {
    echo "This script can be run from the command line only\n";
}
Beispiel #8
0
 public function testMoveFromStorage()
 {
     $folderInfo = $this->view->getFileInfo($this->folder);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     // share 2 different files with 2 different users
     \OCP\Share::shareItem('folder', $folderInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
     $this->assertTrue($view->file_exists($this->folder));
     /**
      * @var \OCP\Files\Storage $sharedStorage
      */
     list($sharedStorage, ) = $view->resolvePath($this->folder);
     $this->assertTrue($sharedStorage->instanceOfStorage('OCA\\Files_Sharing\\ISharedStorage'));
     $sourceStorage = new \OC\Files\Storage\Temporary(array());
     $sourceStorage->file_put_contents('foo.txt', 'asd');
     $sharedStorage->moveFromStorage($sourceStorage, 'foo.txt', 'bar.txt');
     $this->assertTrue($sharedStorage->file_exists('bar.txt'));
     $this->assertEquals('asd', $sharedStorage->file_get_contents('bar.txt'));
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     $this->view->unlink($this->folder);
 }
Beispiel #9
0
 protected function setUp()
 {
     parent::setUp();
     $this->shareManager = \OC::$server->getShareManager();
     \OC_User::setDisplayName(self::TEST_FILES_SHARING_API_USER1, 'User One');
     \OC_User::setDisplayName(self::TEST_FILES_SHARING_API_USER2, 'User Two');
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     $this->user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
     // prepare user1's dir structure
     $this->view->mkdir('container');
     $this->view->mkdir('container/shareddir');
     $this->view->mkdir('container/shareddir/subdir');
     $this->view->mkdir('container/shareddir/emptydir');
     $textData = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
     $this->view->file_put_contents('container/not shared.txt', $textData);
     $this->view->file_put_contents('container/shared single file.txt', $textData);
     $this->view->file_put_contents('container/shareddir/bar.txt', $textData);
     $this->view->file_put_contents('container/shareddir/subdir/another.txt', $textData);
     $this->view->file_put_contents('container/shareddir/subdir/another too.txt', $textData);
     $this->view->file_put_contents('container/shareddir/subdir/not a text file.xml', '<xml></xml>');
     list($this->ownerStorage, ) = $this->view->resolvePath('');
     $this->ownerCache = $this->ownerStorage->getCache();
     $this->ownerStorage->getScanner()->scan('');
     // share "shareddir" with user2
     $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
     $node = $rootFolder->get('container/shareddir');
     $share = $this->shareManager->newShare();
     $share->setNode($node)->setShareType(\OCP\Share::SHARE_TYPE_USER)->setSharedWith(self::TEST_FILES_SHARING_API_USER2)->setSharedBy(self::TEST_FILES_SHARING_API_USER1)->setPermissions(\OCP\Constants::PERMISSION_ALL);
     $this->shareManager->createShare($share);
     $node = $rootFolder->get('container/shared single file.txt');
     $share = $this->shareManager->newShare();
     $share->setNode($node)->setShareType(\OCP\Share::SHARE_TYPE_USER)->setSharedWith(self::TEST_FILES_SHARING_API_USER2)->setSharedBy(self::TEST_FILES_SHARING_API_USER1)->setPermissions(\OCP\Constants::PERMISSION_ALL & ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE));
     $this->shareManager->createShare($share);
     // login as user2
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     // retrieve the shared storage
     $secondView = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2);
     list($this->sharedStorage, ) = $secondView->resolvePath('files/shareddir');
     $this->sharedCache = $this->sharedStorage->getCache();
 }
Beispiel #10
0
 /**
  * find all versions which belong to the file we want to restore
  *
  * @param string $filename name of the file which should be restored
  * @param int $timestamp timestamp when the file was deleted
  * @return array
  */
 private static function getVersionsFromTrash($filename, $timestamp)
 {
     $view = new \OC\Files\View('/' . \OCP\User::getUser() . '/files_trashbin/versions');
     $versions = array();
     //force rescan of versions, local storage may not have updated the cache
     /** @var \OC\Files\Storage\Storage $storage */
     list($storage, ) = $view->resolvePath('/');
     $storage->getScanner()->scan('files_trashbin');
     if ($timestamp) {
         // fetch for old versions
         $matches = $view->searchRaw($filename . '.v%.d' . $timestamp);
         $offset = -strlen($timestamp) - 2;
     } else {
         $matches = $view->searchRaw($filename . '.v%');
     }
     if (is_array($matches)) {
         foreach ($matches as $ma) {
             if ($timestamp) {
                 $parts = explode('.v', substr($ma['path'], 0, $offset));
                 $versions[] = end($parts);
             } else {
                 $parts = explode('.v', $ma);
                 $versions[] = end($parts);
             }
         }
     }
     return $versions;
 }
 public function testMoveFromStorage()
 {
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     $share = $this->share(\OCP\Share::SHARE_TYPE_USER, $this->folder, self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_ALL);
     self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
     $view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
     $this->assertTrue($view->file_exists($this->folder));
     /**
      * @var \OCP\Files\Storage $sharedStorage
      */
     list($sharedStorage, ) = $view->resolvePath($this->folder);
     $this->assertTrue($sharedStorage->instanceOfStorage('OCA\\Files_Sharing\\ISharedStorage'));
     $sourceStorage = new \OC\Files\Storage\Temporary(array());
     $sourceStorage->file_put_contents('foo.txt', 'asd');
     $sharedStorage->moveFromStorage($sourceStorage, 'foo.txt', 'bar.txt');
     $this->assertTrue($sharedStorage->file_exists('bar.txt'));
     $this->assertEquals('asd', $sharedStorage->file_get_contents('bar.txt'));
     self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
     $this->view->unlink($this->folder);
     $this->shareManager->deleteShare($share);
 }
Beispiel #12
0
 /**
  * Update the mtime and ETag of all parent folders
  *
  * @param string $path
  * @param string $time
  */
 public static function correctFolder($path, $time)
 {
     if ($path !== '' && $path !== '/') {
         list($owner, $realPath) = self::getUidAndFilename(dirname($path));
         /**
          * @var \OC\Files\Storage\Storage $storage
          * @var string $internalPath
          */
         $view = new \OC\Files\View('/' . $owner);
         list($storage, $internalPath) = $view->resolvePath($realPath);
         $cache = $storage->getCache();
         $id = $cache->getId($internalPath);
         while ($id !== -1) {
             $cache->update($id, array('mtime' => $time, 'etag' => $storage->getETag($internalPath)));
             if ($realPath !== '') {
                 $realPath = dirname($realPath);
                 if ($realPath === DIRECTORY_SEPARATOR) {
                     $realPath = "";
                 }
                 // check storage for parent in case we change the storage in this step
                 list($storage, $internalPath) = $view->resolvePath($realPath);
                 $cache = $storage->getCache();
                 $id = $cache->getId($internalPath);
             } else {
                 $id = -1;
             }
         }
     }
 }