Example #1
0
 /**
  * get the filesystem info
  *
  * @param string $path
  * @param boolean|string $includeMountPoints true to add mountpoint sizes,
  * 'ext' to add only ext storage mount point sizes. Defaults to true.
  * defaults to true
  * @return \OC\Files\FileInfo|false
  */
 public function getFileInfo($path, $includeMountPoints = true)
 {
     $this->assertPathLength($path);
     $data = array();
     if (!Filesystem::isValidPath($path)) {
         return $data;
     }
     if (Cache\Scanner::isPartialFile($path)) {
         return $this->getPartFileInfo($path);
     }
     $path = Filesystem::normalizePath($this->fakeRoot . '/' . $path);
     $mount = Filesystem::getMountManager()->find($path);
     $storage = $mount->getStorage();
     $internalPath = $mount->getInternalPath($path);
     $data = null;
     if ($storage) {
         $cache = $storage->getCache($internalPath);
         $data = $cache->get($internalPath);
         $watcher = $storage->getWatcher($internalPath);
         // if the file is not in the cache or needs to be updated, trigger the scanner and reload the data
         if (!$data) {
             if (!$storage->file_exists($internalPath)) {
                 return false;
             }
             $scanner = $storage->getScanner($internalPath);
             $scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW);
             $data = $cache->get($internalPath);
         } else {
             if (!Cache\Scanner::isPartialFile($internalPath) && $watcher->checkUpdate($internalPath, $data)) {
                 $this->updater->propagate($path);
                 $data = $cache->get($internalPath);
             }
         }
         if ($data and isset($data['fileid'])) {
             // upgrades from oc6 or lower might not have the permissions set in the file cache
             if ($data['permissions'] === 0) {
                 $data['permissions'] = $storage->getPermissions($data['path']);
                 $cache->update($data['fileid'], array('permissions' => $data['permissions']));
             }
             if ($includeMountPoints and $data['mimetype'] === 'httpd/unix-directory') {
                 //add the sizes of other mount points to the folder
                 $extOnly = $includeMountPoints === 'ext';
                 $mountPoints = Filesystem::getMountPoints($path);
                 foreach ($mountPoints as $mountPoint) {
                     $subStorage = Filesystem::getStorage($mountPoint);
                     if ($subStorage) {
                         // exclude shared storage ?
                         if ($extOnly && $subStorage instanceof \OC\Files\Storage\Shared) {
                             continue;
                         }
                         $subCache = $subStorage->getCache('');
                         $rootEntry = $subCache->get('');
                         $data['size'] += isset($rootEntry['size']) ? $rootEntry['size'] : 0;
                     }
                 }
             }
         }
     }
     if (!$data) {
         return false;
     }
     if ($mount instanceof MoveableMount && $internalPath === '') {
         $data['permissions'] |= \OCP\Constants::PERMISSION_DELETE;
     }
     return new FileInfo($path, $storage, $internalPath, $data, $mount);
 }
Example #2
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;
    }
Example #3
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;
 }
Example #4
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;
    }
Example #5
0
        $users = json_decode($_GET['users']);
    }
} 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();
            }
        }
    }