/** * get the filesystem info from the cache * @param string path * @param string root (optional) * @return array * * returns an associative array with the following keys: * - size * - mtime * - ctime * - mimetype * - encrypted * - versioned */ public static function get($path, $root = false) { if (OC_FileCache_Update::hasUpdated($path, $root)) { if ($root === false) { //filesystem hooks are only valid for the default root OC_Hook::emit('OC_Filesystem', 'post_write', array('path' => $path)); } else { OC_FileCache_Update::update($path, $root); } } return OC_FileCache_Cached::get($path, $root); }
/** * get the free space in the users home folder * @return int */ private function getFreeSpace() { $rootInfo = OC_FileCache_Cached::get(''); // TODO Remove after merge of share_api if (OC_FileCache::inCache('/Shared')) { $sharedInfo = OC_FileCache_Cached::get('/Shared'); } else { $sharedInfo = null; } $usedSpace = isset($rootInfo['size']) ? $rootInfo['size'] : 0; $usedSpace = isset($sharedInfo['size']) ? $usedSpace - $sharedInfo['size'] : $usedSpace; $totalSpace = $this->getQuota(); if ($totalSpace == 0) { return 0; } return $totalSpace - $usedSpace; }
<?php // Load other apps for file previews OC_App::loadApps(); // Compatibility with shared-by-link items from ownCloud 4.0 // requires old Sharing table ! // support will be removed in OC 5.0,a if (isset($_GET['token'])) { unset($_GET['file']); $qry = \OC_DB::prepare('SELECT `source` FROM `*PREFIX*sharing` WHERE `target` = ? LIMIT 1'); $filepath = $qry->execute(array($_GET['token']))->fetchOne(); if (isset($filepath)) { $info = OC_FileCache_Cached::get($filepath, ''); if (strtolower($info['mimetype']) == 'httpd/unix-directory') { $_GET['dir'] = $filepath; } else { $_GET['file'] = $filepath; } \OCP\Util::writeLog('files_sharing', 'You have files that are shared by link originating from ownCloud 4.0. Redistribute the new links, because backwards compatibility will be removed in ownCloud 5.', \OCP\Util::WARN); } } // Enf of backward compatibility if (isset($_GET['file']) || isset($_GET['dir'])) { if (isset($_GET['dir'])) { $type = 'folder'; $path = $_GET['dir']; $baseDir = $path; $dir = $baseDir; } else { $type = 'file'; $path = $_GET['file'];
/** * update the filesystem after a rename has been detected * @param string oldPath * @param string newPath * @param string root (optional) */ public static function rename($oldPath, $newPath, $root = false) { if (!OC_FileCache::inCache($oldPath, $root)) { return; } if ($root === false) { $view = OC_Filesystem::getView(); } else { $view = new OC_FilesystemView($root); } $cached = OC_FileCache_Cached::get($oldPath, $root); $oldSize = $cached['size']; OC_FileCache::increaseSize(dirname($oldPath), -$oldSize, $root); OC_FileCache::increaseSize(dirname($newPath), $oldSize, $root); OC_FileCache::move($oldPath, $newPath); }
/** * Returns available diskspace information * * @return array */ public function getQuotaInfo() { $rootInfo = OC_FileCache_Cached::get(''); return array($rootInfo['size'], OC_Filesystem::free_space()); }
public function postFileSize($path, $size) { if (self::isEncrypted($path)) { $cached = OC_FileCache_Cached::get($path, ''); return $cached['size']; } else { return $size; } }
/** * adjust the size of the parent folders * @param string $path * @param int $sizeDiff * @param string root (optinal) */ public static function increaseSize($path, $sizeDiff, $root = false) { if ($sizeDiff == 0) { return; } $item = OC_FileCache_Cached::get($path); //stop walking up the filetree if we hit a non-folder if ($item['mimetype'] !== 'httpd/unix-directory') { return; } $id = $item['id']; while ($id != -1) { //walk up the filetree increasing the size of all parent folders $query = OC_DB::prepare('UPDATE `*PREFIX*fscache` SET `size`=`size`+? WHERE `id`=?'); $query->execute(array($sizeDiff, $id)); if ($path == '' or $path == '/') { return; } $path = dirname($path); $parent = OC_FileCache_Cached::get($path); $id = $parent['id']; //stop walking up the filetree if we hit a non-folder if ($parent['mimetype'] !== 'httpd/unix-directory') { return; } } }