summaryrefslogtreecommitdiffstats
path: root/lib/private/files
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/files')
-rw-r--r--lib/private/files/cache/legacy.php139
-rw-r--r--lib/private/files/cache/upgrade.php235
-rw-r--r--lib/private/files/filesystem.php70
-rw-r--r--lib/private/files/storage/wrapper/quota.php9
4 files changed, 8 insertions, 445 deletions
diff --git a/lib/private/files/cache/legacy.php b/lib/private/files/cache/legacy.php
deleted file mode 100644
index 4d5f58741e9..00000000000
--- a/lib/private/files/cache/legacy.php
+++ /dev/null
@@ -1,139 +0,0 @@
-<?php
-/**
- * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-
-namespace OC\Files\Cache;
-
-/**
- * Provide read only support for the old filecache
- */
-class Legacy {
- private $user;
-
- private $cacheHasItems = null;
-
- /**
- * @param string $user
- */
- public function __construct($user) {
- $this->user = $user;
- }
-
- /**
- * get the numbers of items in the legacy cache
- *
- * @return int
- */
- function getCount() {
- $sql = 'SELECT COUNT(`id`) AS `count` FROM `*PREFIX*fscache` WHERE `user` = ?';
- $result = \OC_DB::executeAudited($sql, array($this->user));
- if ($row = $result->fetchRow()) {
- return $row['count'];
- } else {
- return 0;
- }
- }
-
- /**
- * check if a legacy cache is present and holds items
- *
- * @return bool
- */
- function hasItems() {
- if (!is_null($this->cacheHasItems)) {
- return $this->cacheHasItems;
- }
- try {
- $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*fscache` WHERE `user` = ?',1);
- } catch (\Exception $e) {
- $this->cacheHasItems = false;
- return false;
- }
- try {
- $result = $query->execute(array($this->user));
- } catch (\Exception $e) {
- $this->cacheHasItems = false;
- return false;
- }
-
- if ($result === false || property_exists($result, 'error_message_prefix')) {
- $this->cacheHasItems = false;
- return false;
- }
-
- $this->cacheHasItems = (bool)$result->fetchRow();
- return $this->cacheHasItems;
- }
-
- /**
- * get an item from the legacy cache
- *
- * @param string $path
- * @return array
- */
- function get($path) {
- if (is_numeric($path)) {
- $sql = 'SELECT * FROM `*PREFIX*fscache` WHERE `id` = ?';
- } else {
- $sql = 'SELECT * FROM `*PREFIX*fscache` WHERE `path` = ?';
- }
- $result = \OC_DB::executeAudited($sql, array($path));
- $data = $result->fetchRow();
- $data['etag'] = $this->getEtag($data['path'], $data['user']);
- return $data;
- }
-
- /**
- * Get the ETag for the given path
- *
- * @param type $path
- * @return string
- */
- function getEtag($path, $user = null) {
- static $query = null;
-
- $pathDetails = explode('/', $path, 4);
- if((!$user) && !isset($pathDetails[1])) {
- //no user!? Too odd, return empty string.
- return '';
- } else if(!$user) {
- //guess user from path, if no user passed.
- $user = $pathDetails[1];
- }
-
- if(!isset($pathDetails[3]) || is_null($pathDetails[3])) {
- $relativePath = '';
- } else {
- $relativePath = $pathDetails[3];
- }
-
- if(is_null($query)){
- $query = \OC_DB::prepare('SELECT `propertyvalue` FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = \'{DAV:}getetag\'');
- }
- $result = \OC_DB::executeAudited($query,array($user, '/' . $relativePath));
- if ($row = $result->fetchRow()) {
- return trim($row['propertyvalue'], '"');
- } else {
- return '';
- }
- }
-
- /**
- * get all child items of an item from the legacy cache
- *
- * @param int $id
- * @return array
- */
- function getChildren($id) {
- $result = \OC_DB::executeAudited('SELECT * FROM `*PREFIX*fscache` WHERE `parent` = ?', array($id));
- $data = $result->fetchAll();
- foreach ($data as $i => $item) {
- $data[$i]['etag'] = $this->getEtag($item['path'], $item['user']);
- }
- return $data;
- }
-}
diff --git a/lib/private/files/cache/upgrade.php b/lib/private/files/cache/upgrade.php
deleted file mode 100644
index e3a46896cbf..00000000000
--- a/lib/private/files/cache/upgrade.php
+++ /dev/null
@@ -1,235 +0,0 @@
-<?php
-/**
- * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-
-namespace OC\Files\Cache;
-
-class Upgrade {
- /**
- * @var Legacy $legacy
- */
- private $legacy;
-
- private $numericIds = array();
-
- private $mimeTypeIds = array();
-
- /**
- * @param Legacy $legacy
- */
- public function __construct($legacy) {
- $this->legacy = $legacy;
- }
-
- /**
- * Preform a upgrade a path and it's childs
- *
- * @param string $path
- * @param bool $mode
- */
- function upgradePath($path, $mode = Scanner::SCAN_RECURSIVE) {
- if (!$this->legacy->hasItems()) {
- return;
- }
- \OC_Hook::emit('\OC\Files\Cache\Upgrade', 'migrate_path', $path);
- if ($row = $this->legacy->get($path)) {
- $data = $this->getNewData($row);
- if ($data) {
- $this->insert($data);
- $this->upgradeChilds($data['id'], $mode);
- }
- }
- }
-
- /**
- * upgrade all child elements of an item
- *
- * @param int $id
- * @param bool $mode
- */
- function upgradeChilds($id, $mode = Scanner::SCAN_RECURSIVE) {
- $children = $this->legacy->getChildren($id);
- foreach ($children as $child) {
- $childData = $this->getNewData($child);
- \OC_Hook::emit('\OC\Files\Cache\Upgrade', 'migrate_path', $child['path']);
- if ($childData) {
- $this->insert($childData);
- if ($mode == Scanner::SCAN_RECURSIVE) {
- $this->upgradeChilds($child['id']);
- }
- }
- }
- }
-
- /**
- * insert data into the new cache
- *
- * @param array $data the data for the new cache
- */
- function insert($data) {
- static $insertQuery = null;
- if(is_null($insertQuery)) {
- $insertQuery = \OC_DB::prepare('INSERT INTO `*PREFIX*filecache`
- ( `fileid`, `storage`, `path`, `path_hash`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `etag` )
- VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
- }
- if (!$this->inCache($data['storage'], $data['path_hash'], $data['id'])) {
- \OC_DB::executeAudited($insertQuery, array($data['id'], $data['storage'],
- $data['path'], $data['path_hash'], $data['parent'], $data['name'],
- $data['mimetype'], $data['mimepart'], $data['size'], $data['mtime'], $data['encrypted'], $data['etag']));
- }
- }
-
- /**
- * check if an item is already in the new cache
- *
- * @param string $storage
- * @param string $pathHash
- * @param string $id
- * @return bool
- */
- function inCache($storage, $pathHash, $id) {
- static $query = null;
- if(is_null($query)) {
- $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE (`storage` = ? AND `path_hash` = ?) OR `fileid` = ?');
- }
- $result = \OC_DB::executeAudited($query, array($storage, $pathHash, $id));
- return (bool)$result->fetchRow();
- }
-
- /**
- * get the new data array from the old one
- *
- * @param array $data the data from the old cache
- * Example data array
- * Array
- * (
- * [id] => 418
- * [path] => /tina/files/picture.jpg //relative to datadir
- * [path_hash] => 66d4547e372888deed80b24fec9b192b
- * [parent] => 234
- * [name] => picture.jpg
- * [user] => tina
- * [size] => 1265283
- * [ctime] => 1363909709
- * [mtime] => 1363909709
- * [mimetype] => image/jpeg
- * [mimepart] => image
- * [encrypted] => 0
- * [versioned] => 0
- * [writable] => 1
- * )
- *
- * @return array
- */
- function getNewData($data) {
- //Make sure there is a path, otherwise we can do nothing.
- if(!isset($data['path'])) {
- return false;
- }
- $newData = $data;
- /**
- * @var \OC\Files\Storage\Storage $storage
- * @var string $internalPath;
- */
- list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($data['path']);
- if ($storage) {
- $newData['etag'] = $data['etag'];
- $newData['path_hash'] = md5($internalPath);
- $newData['path'] = $internalPath;
- $newData['storage'] = $this->getNumericId($storage);
- $newData['parent'] = ($internalPath === '') ? -1 : $data['parent'];
- $newData['permissions'] = ($data['writable']) ? \OCP\PERMISSION_ALL : \OCP\PERMISSION_READ;
- $newData['storage_object'] = $storage;
- $newData['mimetype'] = $this->getMimetypeId($newData['mimetype'], $storage);
- $newData['mimepart'] = $this->getMimetypeId($newData['mimepart'], $storage);
- return $newData;
- } else {
- \OC_Log::write('core', 'Unable to migrate data from old cache for '.$data['path'].' because the storage was not found', \OC_Log::ERROR);
- return false;
- }
- }
-
- /**
- * get the numeric storage id
- *
- * @param \OC\Files\Storage\Storage $storage
- * @return int
- */
- function getNumericId($storage) {
- $storageId = $storage->getId();
- if (!isset($this->numericIds[$storageId])) {
- $cache = $storage->getCache();
- $this->numericIds[$storageId] = $cache->getNumericStorageId();
- }
- return $this->numericIds[$storageId];
- }
-
- /**
- * get the numeric id for a mimetype
- *
- * @param string $mimetype
- * @param \OC\Files\Storage\Storage $storage
- * @return int
- */
- function getMimetypeId($mimetype, $storage) {
- if (!isset($this->mimeTypeIds[$mimetype])) {
- $cache = new Cache($storage);
- $this->mimeTypeIds[$mimetype] = $cache->getMimetypeId($mimetype);
- }
- return $this->mimeTypeIds[$mimetype];
- }
-
- /**
- * check if a cache upgrade is required for $user
- *
- * @param string $user
- * @return bool
- */
- static function needUpgrade($user) {
- $cacheVersion = (int)\OCP\Config::getUserValue($user, 'files', 'cache_version', 4);
- if ($cacheVersion < 5) {
- $legacy = new \OC\Files\Cache\Legacy($user);
- if ($legacy->hasItems()) {
- return true;
- }
- self::upgradeDone($user);
- }
-
- return false;
- }
-
- /**
- * mark the filecache as upgrade
- *
- * @param string $user
- */
- static function upgradeDone($user) {
- \OCP\Config::setUserValue($user, 'files', 'cache_version', 5);
- }
-
- /**
- * Does a "silent" upgrade, i.e. without an Event-Source as triggered
- * on User-Login via Ajax. This method is called within the regular
- * ownCloud upgrade.
- *
- * @param string $user a User ID
- */
- public static function doSilentUpgrade($user) {
- if(!self::needUpgrade($user)) {
- return;
- }
- $legacy = new \OC\Files\Cache\Legacy($user);
- if ($legacy->hasItems()) {
- \OC_DB::beginTransaction();
- $upgrade = new \OC\Files\Cache\Upgrade($legacy);
- $upgrade->upgradePath('/' . $user . '/files');
- \OC_DB::commit();
- }
- \OC\Files\Cache\Upgrade::upgradeDone($user);
- }
-}
diff --git a/lib/private/files/filesystem.php b/lib/private/files/filesystem.php
index 6478854eae8..c31e0c38180 100644
--- a/lib/private/files/filesystem.php
+++ b/lib/private/files/filesystem.php
@@ -320,82 +320,12 @@ class Filesystem {
else {
self::mount('\OC\Files\Storage\Local', array('datadir' => $root), $user);
}
- $datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data");
- $mount_file = \OC_Config::getValue("mount_file", $datadir . "/mount.json");
-
- //move config file to it's new position
- if (is_file(\OC::$SERVERROOT . '/config/mount.json')) {
- rename(\OC::$SERVERROOT . '/config/mount.json', $mount_file);
- }
- // Load system mount points
- if (is_file(\OC::$SERVERROOT . '/config/mount.php') or is_file($mount_file)) {
- if (is_file($mount_file)) {
- $mountConfig = json_decode(file_get_contents($mount_file), true);
- } elseif (is_file(\OC::$SERVERROOT . '/config/mount.php')) {
- $mountConfig = $parser->parsePHP(file_get_contents(\OC::$SERVERROOT . '/config/mount.php'));
- }
- if (isset($mountConfig['global'])) {
- foreach ($mountConfig['global'] as $mountPoint => $options) {
- self::mount($options['class'], $options['options'], $mountPoint);
- }
- }
- if (isset($mountConfig['group'])) {
- foreach ($mountConfig['group'] as $group => $mounts) {
- if (\OC_Group::inGroup($user, $group)) {
- foreach ($mounts as $mountPoint => $options) {
- $mountPoint = self::setUserVars($user, $mountPoint);
- foreach ($options as &$option) {
- $option = self::setUserVars($user, $option);
- }
- self::mount($options['class'], $options['options'], $mountPoint);
- }
- }
- }
- }
- if (isset($mountConfig['user'])) {
- foreach ($mountConfig['user'] as $mountUser => $mounts) {
- if ($mountUser === 'all' or strtolower($mountUser) === strtolower($user)) {
- foreach ($mounts as $mountPoint => $options) {
- $mountPoint = self::setUserVars($user, $mountPoint);
- foreach ($options as &$option) {
- $option = self::setUserVars($user, $option);
- }
- self::mount($options['class'], $options['options'], $mountPoint);
- }
- }
- }
- }
- }
- // Load personal mount points
- if (is_file($root . '/mount.php') or is_file($root . '/mount.json')) {
- if (is_file($root . '/mount.json')) {
- $mountConfig = json_decode(file_get_contents($root . '/mount.json'), true);
- } elseif (is_file($root . '/mount.php')) {
- $mountConfig = $parser->parsePHP(file_get_contents($root . '/mount.php'));
- }
- if (isset($mountConfig['user'][$user])) {
- foreach ($mountConfig['user'][$user] as $mountPoint => $options) {
- self::mount($options['class'], $options['options'], $mountPoint);
- }
- }
- }
// Chance to mount for other storages
\OC_Hook::emit('OC_Filesystem', 'post_initMountPoints', array('user' => $user, 'user_dir' => $root));
}
/**
- * fill in the correct values for $user
- *
- * @param string $user
- * @param string $input
- * @return string
- */
- private static function setUserVars($user, $input) {
- return str_replace('$user', $user, $input);
- }
-
- /**
* get the default filesystem view
*
* @return View
diff --git a/lib/private/files/storage/wrapper/quota.php b/lib/private/files/storage/wrapper/quota.php
index 32ceba8b196..a878b2c5cf6 100644
--- a/lib/private/files/storage/wrapper/quota.php
+++ b/lib/private/files/storage/wrapper/quota.php
@@ -69,7 +69,14 @@ class Quota extends Wrapper {
return \OC\Files\SPACE_NOT_COMPUTED;
} else {
$free = $this->storage->free_space($path);
- return min($free, (max($this->quota - $used, 0)));
+ $quotaFree = max($this->quota - $used, 0);
+ // if free space is known
+ if ($free >= 0) {
+ $free = min($free, $quotaFree);
+ } else {
+ $free = $quotaFree;
+ }
+ return $free;
}
}
}