Beispiel #1
0
 /**
  * get the mountpoint of the storage object for a path
  * ( note: because a storage is not always mounted inside the fakeroot, the
  * returned mountpoint is relative to the absolute root of the filesystem
  * and does not take the chroot into account )
  *
  * @param string $path
  * @return string
  */
 public function getMountPoint($path)
 {
     return Filesystem::getMountPoint($this->getAbsolutePath($path));
 }
Beispiel #2
0
    /**
     * get the list of all unindexed files for the user
     *
     * @return array
     */
    public static function getUnindexed()
    {
        $files = array();
        $absoluteRoot = Filesystem::getView()->getAbsolutePath('/');
        $mounts = Filesystem::getMountPoints($absoluteRoot);
        $mount = Filesystem::getMountPoint($absoluteRoot);
        if (!in_array($mount, $mounts)) {
            $mounts[] = $mount;
        }
        $query = \OC_DB::prepare('
			SELECT `*PREFIX*filecache`.`fileid`
			FROM `*PREFIX*filecache`
			LEFT JOIN `*PREFIX*lucene_status`
			ON `*PREFIX*filecache`.`fileid` = `*PREFIX*lucene_status`.`fileid`
			WHERE `storage` = ?
			AND `status` IS NULL OR `status` = ?
		');
        foreach ($mounts as $mount) {
            if (is_string($mount)) {
                $storage = Filesystem::getStorage($mount);
            } else {
                if ($mount instanceof \OC\Files\Mount\Mount) {
                    $storage = $mount->getStorage();
                } else {
                    $storage = null;
                    Util::writeLog('search_lucene', 'expected string or instance of \\OC\\Files\\Mount\\Mount got ' . json_encode($mount), Util::DEBUG);
                }
            }
            //only index local files for now
            if ($storage instanceof \OC\Files\Storage\Local) {
                $cache = $storage->getCache();
                $numericId = $cache->getNumericStorageId();
                $result = $query->execute(array($numericId, 'N'));
                if (\OC_DB::isError($result)) {
                    Util::writeLog('search_lucene', 'failed to find unindexed files: ' . \OC_DB::getErrorMessage($result), Util::WARN);
                    return false;
                }
                while ($row = $result->fetchRow()) {
                    $files[] = $row['fileid'];
                }
            }
        }
        return $files;
    }
Beispiel #3
0
    /**
     * get the list of all unindexed files for the user
     *
     * @return array
     */
    public function getUnindexed()
    {
        $files = array();
        //TODO use server api for mounts & root
        $absoluteRoot = Filesystem::getView()->getAbsolutePath('/');
        $mounts = Filesystem::getMountPoints($absoluteRoot);
        $mount = Filesystem::getMountPoint($absoluteRoot);
        if (!in_array($mount, $mounts)) {
            $mounts[] = $mount;
        }
        $query = $this->db->prepareQuery('
			SELECT `*PREFIX*filecache`.`fileid`
			FROM `*PREFIX*filecache`
			LEFT JOIN `' . $this->tableName . '`
			ON `*PREFIX*filecache`.`fileid` = `' . $this->tableName . '`.`fileid`
			WHERE `storage` = ?
			AND ( `status` IS NULL OR `status` = ? )
			AND `path` LIKE \'files/%\'
		');
        foreach ($mounts as $mount) {
            if (is_string($mount)) {
                $storage = Filesystem::getStorage($mount);
            } else {
                if ($mount instanceof Mount) {
                    $storage = $mount->getStorage();
                } else {
                    $storage = null;
                    $this->logger->debug('expected string or instance of \\OC\\Files\\Mount\\Mount got ' . json_encode($mount));
                }
            }
            //only index local files for now
            if ($storage->isLocal()) {
                $cache = $storage->getCache();
                $numericId = $cache->getNumericStorageId();
                $result = $query->execute(array($numericId, Status::STATUS_NEW));
                while ($row = $result->fetchRow()) {
                    $files[] = $row['fileid'];
                }
            }
        }
        return $files;
    }
 public function testRegisterMountProviderAfterSetup()
 {
     \OC\Files\Filesystem::initMountPoints(self::TEST_FILESYSTEM_USER2);
     $this->assertEquals('/', \OC\Files\Filesystem::getMountPoint('/foo/bar'));
     $mount = new MountPoint(new Temporary([]), '/foo/bar');
     $mountProvider = new DummyMountProvider([self::TEST_FILESYSTEM_USER2 => [$mount]]);
     \OC::$server->getMountProviderCollection()->registerProvider($mountProvider);
     $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::getMountPoint('/foo/bar'));
 }
Beispiel #5
0
 /**
  * @param string $query
  * @param string $method
  * @return FileInfo[]
  */
 private function searchCommon($query, $method)
 {
     $files = array();
     $rootLength = strlen($this->fakeRoot);
     $mountPoint = Filesystem::getMountPoint($this->fakeRoot);
     $storage = Filesystem::getStorage($mountPoint);
     if ($storage) {
         $cache = $storage->getCache('');
         $results = $cache->{$method}($query);
         foreach ($results as $result) {
             if (substr($mountPoint . $result['path'], 0, $rootLength + 1) === $this->fakeRoot . '/') {
                 $internalPath = $result['path'];
                 $path = $mountPoint . $result['path'];
                 $result['path'] = substr($mountPoint . $result['path'], $rootLength);
                 $files[] = new FileInfo($path, $storage, $internalPath, $result);
             }
         }
         $mountPoints = Filesystem::getMountPoints($this->fakeRoot);
         foreach ($mountPoints as $mountPoint) {
             $storage = Filesystem::getStorage($mountPoint);
             if ($storage) {
                 $cache = $storage->getCache('');
                 $relativeMountPoint = substr($mountPoint, $rootLength);
                 $results = $cache->{$method}($query);
                 if ($results) {
                     foreach ($results as $result) {
                         $internalPath = $result['path'];
                         $result['path'] = rtrim($relativeMountPoint . $result['path'], '/');
                         $path = rtrim($mountPoint . $internalPath, '/');
                         $files[] = new FileInfo($path, $storage, $internalPath, $result);
                     }
                 }
             }
         }
     }
     return $files;
 }
 /**
  * Test that an external cache is mounted into
  * the user's home
  */
 public function testMountExternalCacheDir()
 {
     $userId = $this->getUniqueID('user_');
     $oldCachePath = \OC_Config::getValue('cache_path', '');
     // set cache path to temp dir
     $cachePath = \OC_Helper::tmpFolder() . '/extcache';
     \OC_Config::setValue('cache_path', $cachePath);
     \OC_User::createUser($userId, $userId);
     \OC\Files\Filesystem::initMountPoints($userId);
     $this->assertEquals('/' . $userId . '/cache/', \OC\Files\Filesystem::getMountPoint('/' . $userId . '/cache'));
     list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath('/' . $userId . '/cache');
     $this->assertTrue($storage->instanceOfStorage('\\OC\\Files\\Storage\\Local'));
     $this->assertEquals('', $internalPath);
     \OC_User::deleteUser($userId);
     \OC_Config::setValue('cache_path', $oldCachePath);
 }
 /**
  * get the mountpoint of the storage object for a path
  * ( note: because a storage is not always mounted inside the fakeroot, the
  * returned mountpoint is relative to the absolute root of the filesystem
  * and doesn't take the chroot into account )
  *
  * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  * @param string $path
  * @return string
  */
 public static function getMountPoint($path)
 {
     return \OC\Files\Filesystem::getMountPoint($path);
 }
Beispiel #8
0
    }
} else {
    $users = array(OC_User::getUser());
}
$eventSource = new OC_EventSource();
ScanListener::$eventSource = $eventSource;
ScanListener::$view = \OC\Files\Filesystem::getView();
OC_Hook::connect('\\OC\\Files\\Cache\\Scanner', 'scan_folder', 'ScanListener', 'folder');
OC_Hook::connect('\\OC\\Files\\Cache\\Scanner', 'scan_file', 'ScanListener', 'file');
foreach ($users as $user) {
    $eventSource->send('user', $user);
    OC_Util::tearDownFS();
    OC_Util::setupFS($user);
    $absolutePath = \OC\Files\Filesystem::getView()->getAbsolutePath($dir);
    $mountPoints = \OC\Files\Filesystem::getMountPoints($absolutePath);
    $mountPoints[] = \OC\Files\Filesystem::getMountPoint($absolutePath);
    $mountPoints = array_reverse($mountPoints);
    //start with the mount point of $dir
    foreach ($mountPoints as $mountPoint) {
        $storage = \OC\Files\Filesystem::getStorage($mountPoint);
        if ($storage) {
            ScanListener::$mountPoints[$storage->getId()] = $mountPoint;
            $scanner = $storage->getScanner();
            if ($force) {
                $scanner->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG);
            } else {
                $scanner->backgroundScan();
            }
        }
    }
}