summaryrefslogtreecommitdiffstats
path: root/lib/files
diff options
context:
space:
mode:
Diffstat (limited to 'lib/files')
-rw-r--r--lib/files/cache/backgroundwatcher.php10
-rw-r--r--lib/files/cache/cache.php168
-rw-r--r--lib/files/cache/legacy.php17
-rw-r--r--lib/files/cache/permissions.php52
-rw-r--r--lib/files/cache/scanner.php34
-rw-r--r--lib/files/cache/storage.php13
-rw-r--r--lib/files/cache/upgrade.php4
-rw-r--r--lib/files/cache/watcher.php2
-rw-r--r--lib/files/filesystem.php51
-rw-r--r--lib/files/mapper.php58
-rw-r--r--lib/files/storage/common.php18
-rw-r--r--lib/files/view.php72
12 files changed, 308 insertions, 191 deletions
diff --git a/lib/files/cache/backgroundwatcher.php b/lib/files/cache/backgroundwatcher.php
index 8933101577d..923804f48d0 100644
--- a/lib/files/cache/backgroundwatcher.php
+++ b/lib/files/cache/backgroundwatcher.php
@@ -18,8 +18,8 @@ class BackgroundWatcher {
if (!is_null(self::$folderMimetype)) {
return self::$folderMimetype;
}
- $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*mimetypes` WHERE `mimetype` = ?');
- $result = $query->execute(array('httpd/unix-directory'));
+ $sql = 'SELECT `id` FROM `*PREFIX*mimetypes` WHERE `mimetype` = ?';
+ $result = \OC_DB::executeAudited($sql, array('httpd/unix-directory'));
$row = $result->fetchRow();
return $row['id'];
}
@@ -59,11 +59,11 @@ class BackgroundWatcher {
*/
static private function getNextFileId($previous, $folder) {
if ($folder) {
- $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `fileid` > ? AND mimetype = ' . self::getFolderMimetype() . ' ORDER BY `fileid` ASC', 1);
+ $stmt = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `fileid` > ? AND `mimetype` = ? ORDER BY `fileid` ASC', 1);
} else {
- $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `fileid` > ? AND mimetype != ' . self::getFolderMimetype() . ' ORDER BY `fileid` ASC', 1);
+ $stmt = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `fileid` > ? AND `mimetype` != ? ORDER BY `fileid` ASC', 1);
}
- $result = $query->execute(array($previous));
+ $result = \OC_DB::executeAudited($stmt, array($previous,self::getFolderMimetype()));
if ($row = $result->fetchRow()) {
return $row['fileid'];
} else {
diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php
index 8f5c9643bef..3818fdbd840 100644
--- a/lib/files/cache/cache.php
+++ b/lib/files/cache/cache.php
@@ -65,13 +65,11 @@ class Cache {
*/
public function getMimetypeId($mime) {
if (!isset($this->mimetypeIds[$mime])) {
- $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*mimetypes` WHERE `mimetype` = ?');
- $result = $query->execute(array($mime));
+ $result = \OC_DB::executeAudited('SELECT `id` FROM `*PREFIX*mimetypes` WHERE `mimetype` = ?', array($mime));
if ($row = $result->fetchRow()) {
$this->mimetypeIds[$mime] = $row['id'];
} else {
- $query = \OC_DB::prepare('INSERT INTO `*PREFIX*mimetypes`(`mimetype`) VALUES(?)');
- $query->execute(array($mime));
+ $result = \OC_DB::executeAudited('INSERT INTO `*PREFIX*mimetypes`(`mimetype`) VALUES(?)', array($mime));
$this->mimetypeIds[$mime] = \OC_DB::insertid('*PREFIX*mimetypes');
}
$this->mimetypes[$this->mimetypeIds[$mime]] = $mime;
@@ -81,8 +79,8 @@ class Cache {
public function getMimetype($id) {
if (!isset($this->mimetypes[$id])) {
- $query = \OC_DB::prepare('SELECT `mimetype` FROM `*PREFIX*mimetypes` WHERE `id` = ?');
- $result = $query->execute(array($id));
+ $sql = 'SELECT `mimetype` FROM `*PREFIX*mimetypes` WHERE `id` = ?';
+ $result = \OC_DB::executeAudited($sql, array($id));
if ($row = $result->fetchRow()) {
$this->mimetypes[$id] = $row['mimetype'];
} else {
@@ -96,22 +94,31 @@ class Cache {
* get the stored metadata of a file or folder
*
* @param string/int $file
- * @return array
+ * @return array | false
*/
public function get($file) {
if (is_string($file) or $file == '') {
+ // normalize file
+ $file = $this->normalize($file);
+
$where = 'WHERE `storage` = ? AND `path_hash` = ?';
$params = array($this->getNumericStorageId(), md5($file));
} else { //file id
$where = 'WHERE `fileid` = ?';
$params = array($file);
}
- $query = \OC_DB::prepare(
- 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `etag`
- FROM `*PREFIX*filecache` ' . $where);
- $result = $query->execute($params);
+ $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`,
+ `storage_mtime`, `encrypted`, `unencrypted_size`, `etag`
+ FROM `*PREFIX*filecache` ' . $where;
+ $result = \OC_DB::executeAudited($sql, $params);
$data = $result->fetchRow();
+ //FIXME hide this HACK in the next database layer, or just use doctrine and get rid of MDB2 and PDO
+ //PDO returns false, MDB2 returns null, oracle always uses MDB2, so convert null to false
+ if ($data === null) {
+ $data = false;
+ }
+
//merge partial data
if (!$data and is_string($file)) {
if (isset($this->partial[$file])) {
@@ -123,9 +130,13 @@ class Cache {
$data['size'] = (int)$data['size'];
$data['mtime'] = (int)$data['mtime'];
$data['encrypted'] = (bool)$data['encrypted'];
+ $data['unencrypted_size'] = (int)$data['unencrypted_size'];
$data['storage'] = $this->storageId;
$data['mimetype'] = $this->getMimetype($data['mimetype']);
$data['mimepart'] = $this->getMimetype($data['mimepart']);
+ if ($data['storage_mtime'] == 0) {
+ $data['storage_mtime'] = $data['mtime'];
+ }
}
return $data;
@@ -140,14 +151,17 @@ class Cache {
public function getFolderContents($folder) {
$fileId = $this->getId($folder);
if ($fileId > -1) {
- $query = \OC_DB::prepare(
- 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `etag`
- FROM `*PREFIX*filecache` WHERE parent = ? ORDER BY `name` ASC');
- $result = $query->execute(array($fileId));
+ $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`,
+ `storage_mtime`, `encrypted`, `unencrypted_size`, `etag`
+ FROM `*PREFIX*filecache` WHERE `parent` = ? ORDER BY `name` ASC';
+ $result = \OC_DB::executeAudited($sql,array($fileId));
$files = $result->fetchAll();
foreach ($files as &$file) {
$file['mimetype'] = $this->getMimetype($file['mimetype']);
$file['mimepart'] = $this->getMimetype($file['mimepart']);
+ if ($file['storage_mtime'] == 0) {
+ $file['storage_mtime'] = $file['mtime'];
+ }
}
return $files;
} else {
@@ -168,6 +182,9 @@ class Cache {
$this->update($id, $data);
return $id;
} else {
+ // normalize file
+ $file = $this->normalize($file);
+
if (isset($this->partial[$file])) { //add any saved partial data
$data = array_merge($this->partial[$file], $data);
unset($this->partial[$file]);
@@ -191,12 +208,9 @@ class Cache {
$params[] = $this->getNumericStorageId();
$valuesPlaceholder = array_fill(0, count($queryParts), '?');
- $query = \OC_DB::prepare('INSERT INTO `*PREFIX*filecache`(' . implode(', ', $queryParts) . ')'
- . ' VALUES(' . implode(', ', $valuesPlaceholder) . ')');
- $result = $query->execute($params);
- if (\OC_DB::isError($result)) {
- \OCP\Util::writeLog('cache', 'Insert to cache failed: ' . $result, \OCP\Util::ERROR);
- }
+ $sql = 'INSERT INTO `*PREFIX*filecache` (' . implode(', ', $queryParts) . ')'
+ . ' VALUES (' . implode(', ', $valuesPlaceholder) . ')';
+ \OC_DB::executeAudited($sql, $params);
return (int)\OC_DB::insertid('*PREFIX*filecache');
}
@@ -209,12 +223,22 @@ class Cache {
* @param array $data
*/
public function update($id, array $data) {
+
+ if(isset($data['path'])) {
+ // normalize path
+ $data['path'] = $this->normalize($data['path']);
+ }
+
+ if(isset($data['name'])) {
+ // normalize path
+ $data['name'] = $this->normalize($data['name']);
+ }
+
list($queryParts, $params) = $this->buildParts($data);
$params[] = $id;
- $query = \OC_DB::prepare('UPDATE `*PREFIX*filecache` SET ' . implode(' = ?, ', $queryParts) . '=?'
- . ' WHERE fileid = ?');
- $query->execute($params);
+ $sql = 'UPDATE `*PREFIX*filecache` SET ' . implode(' = ?, ', $queryParts) . '=? WHERE `fileid` = ?';
+ \OC_DB::executeAudited($sql, $params);
}
/**
@@ -224,7 +248,7 @@ class Cache {
* @return array
*/
function buildParts(array $data) {
- $fields = array('path', 'parent', 'name', 'mimetype', 'size', 'mtime', 'encrypted', 'etag');
+ $fields = array('path', 'parent', 'name', 'mimetype', 'size', 'mtime', 'storage_mtime', 'encrypted', 'unencrypted_size', 'etag');
$params = array();
$queryParts = array();
foreach ($data as $name => $value) {
@@ -236,6 +260,11 @@ class Cache {
$params[] = $this->getMimetypeId(substr($value, 0, strpos($value, '/')));
$queryParts[] = '`mimepart`';
$value = $this->getMimetypeId($value);
+ } elseif ($name === 'storage_mtime') {
+ if (!isset($data['mtime'])) {
+ $params[] = $value;
+ $queryParts[] = '`mtime`';
+ }
}
$params[] = $value;
$queryParts[] = '`' . $name . '`';
@@ -251,11 +280,13 @@ class Cache {
* @return int
*/
public function getId($file) {
- $pathHash = md5($file);
+ // normalize file
+ $file = $this->normalize($file);
- $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?');
- $result = $query->execute(array($this->getNumericStorageId(), $pathHash));
+ $pathHash = md5($file);
+ $sql = 'SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?';
+ $result = \OC_DB::executeAudited($sql, array($this->getNumericStorageId(), $pathHash));
if ($row = $result->fetchRow()) {
return $row['fileid'];
} else {
@@ -304,8 +335,9 @@ class Cache {
$this->remove($child['path']);
}
}
- $query = \OC_DB::prepare('DELETE FROM `*PREFIX*filecache` WHERE `fileid` = ?');
- $query->execute(array($entry['fileid']));
+
+ $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `fileid` = ?';
+ \OC_DB::executeAudited($sql, array($entry['fileid']));
$permissionsCache = new Permissions($this->storageId);
$permissionsCache->remove($entry['fileid']);
@@ -318,38 +350,41 @@ class Cache {
* @param string $target
*/
public function move($source, $target) {
+ // normalize source and target
+ $source = $this->normalize($source);
+ $target = $this->normalize($target);
+
$sourceData = $this->get($source);
$sourceId = $sourceData['fileid'];
$newParentId = $this->getParentId($target);
if ($sourceData['mimetype'] === 'httpd/unix-directory') {
//find all child entries
- $query = \OC_DB::prepare('SELECT `path`, `fileid` FROM `*PREFIX*filecache` WHERE `path` LIKE ?');
- $result = $query->execute(array($source . '/%'));
+ $sql = 'SELECT `path`, `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path` LIKE ?';
+ $result = \OC_DB::executeAudited($sql, array($this->getNumericStorageId(), $source . '/%'));
$childEntries = $result->fetchAll();
$sourceLength = strlen($source);
$query = \OC_DB::prepare('UPDATE `*PREFIX*filecache` SET `path` = ?, `path_hash` = ? WHERE `fileid` = ?');
foreach ($childEntries as $child) {
$targetPath = $target . substr($child['path'], $sourceLength);
- $query->execute(array($targetPath, md5($targetPath), $child['fileid']));
+ \OC_DB::executeAudited($query, array($targetPath, md5($targetPath), $child['fileid']));
}
}
- $query = \OC_DB::prepare('UPDATE `*PREFIX*filecache` SET `path` = ?, `path_hash` = ?, `name` = ?, `parent` =?'
- . ' WHERE `fileid` = ?');
- $query->execute(array($target, md5($target), basename($target), $newParentId, $sourceId));
+ $sql = 'UPDATE `*PREFIX*filecache` SET `path` = ?, `path_hash` = ?, `name` = ?, `parent` =? WHERE `fileid` = ?';
+ \OC_DB::executeAudited($sql, array($target, md5($target), basename($target), $newParentId, $sourceId));
}
/**
* remove all entries for files that are stored on the storage from the cache
*/
public function clear() {
- $query = \OC_DB::prepare('DELETE FROM `*PREFIX*filecache` WHERE storage = ?');
- $query->execute(array($this->getNumericStorageId()));
+ $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `storage` = ?';
+ \OC_DB::executeAudited($sql, array($this->getNumericStorageId()));
- $query = \OC_DB::prepare('DELETE FROM `*PREFIX*storages` WHERE id = ?');
- $query->execute(array($this->storageId));
+ $sql = 'DELETE FROM `*PREFIX*storages` WHERE `id` = ?';
+ \OC_DB::executeAudited($sql, array($this->storageId));
}
/**
@@ -358,9 +393,12 @@ class Cache {
* @return int, Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE
*/
public function getStatus($file) {
+ // normalize file
+ $file = $this->normalize($file);
+
$pathHash = md5($file);
- $query = \OC_DB::prepare('SELECT `size` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?');
- $result = $query->execute(array($this->getNumericStorageId(), $pathHash));
+ $sql = 'SELECT `size` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?';
+ $result = \OC_DB::executeAudited($sql, array($this->getNumericStorageId(), $pathHash));
if ($row = $result->fetchRow()) {
if ((int)$row['size'] === -1) {
return self::SHALLOW;
@@ -383,11 +421,13 @@ class Cache {
* @return array of file data
*/
public function search($pattern) {
- $query = \OC_DB::prepare('
- SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `etag`
- FROM `*PREFIX*filecache` WHERE `name` LIKE ? AND `storage` = ?'
- );
- $result = $query->execute(array($pattern, $this->getNumericStorageId()));
+
+ // normalize pattern
+ $pattern = $this->normalize($pattern);
+
+ $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `unencrypted_size`, `etag`
+ FROM `*PREFIX*filecache` WHERE `name` LIKE ? AND `storage` = ?';
+ $result = \OC_DB::executeAudited($sql, array($pattern, $this->getNumericStorageId()));
$files = array();
while ($row = $result->fetchRow()) {
$row['mimetype'] = $this->getMimetype($row['mimetype']);
@@ -409,12 +449,10 @@ class Cache {
} else {
$where = '`mimepart` = ?';
}
- $query = \OC_DB::prepare('
- SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `etag`
- FROM `*PREFIX*filecache` WHERE ' . $where . ' AND `storage` = ?'
- );
+ $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `unencrypted_size`, `etag`
+ FROM `*PREFIX*filecache` WHERE ' . $where . ' AND `storage` = ?';
$mimetype = $this->getMimetypeId($mimetype);
- $result = $query->execute(array($mimetype, $this->getNumericStorageId()));
+ $result = \OC_DB::executeAudited($sql, array($mimetype, $this->getNumericStorageId()));
$files = array();
while ($row = $result->fetchRow()) {
$row['mimetype'] = $this->getMimetype($row['mimetype']);
@@ -451,8 +489,8 @@ class Cache {
if ($id === -1) {
return 0;
}
- $query = \OC_DB::prepare('SELECT `size` FROM `*PREFIX*filecache` WHERE `parent` = ? AND `storage` = ?');
- $result = $query->execute(array($id, $this->getNumericStorageId()));
+ $sql = 'SELECT `size` FROM `*PREFIX*filecache` WHERE `parent` = ? AND `storage` = ?';
+ $result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId()));
$totalSize = 0;
$hasChilds = 0;
while ($row = $result->fetchRow()) {
@@ -478,8 +516,8 @@ class Cache {
* @return int[]
*/
public function getAll() {
- $query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ?');
- $result = $query->execute(array($this->getNumericStorageId()));
+ $sql = 'SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ?';
+ $result = \OC_DB::executeAudited($sql, array($this->getNumericStorageId()));
$ids = array();
while ($row = $result->fetchRow()) {
$ids[] = $row['fileid'];
@@ -498,8 +536,8 @@ class Cache {
*/
public function getIncomplete() {
$query = \OC_DB::prepare('SELECT `path` FROM `*PREFIX*filecache`'
- . ' WHERE `storage` = ? AND `size` = -1 ORDER BY `fileid` DESC LIMIT 1');
- $result = $query->execute(array($this->getNumericStorageId()));
+ . ' WHERE `storage` = ? AND `size` = -1 ORDER BY `fileid` DESC',1);
+ $result = \OC_DB::executeAudited($query, array($this->getNumericStorageId()));
if ($row = $result->fetchRow()) {
return $row['path'];
} else {
@@ -514,8 +552,8 @@ class Cache {
* @return array, first element holding the storage id, second the path
*/
static public function getById($id) {
- $query = \OC_DB::prepare('SELECT `storage`, `path` FROM `*PREFIX*filecache` WHERE `fileid` = ?');
- $result = $query->execute(array($id));
+ $sql = 'SELECT `storage`, `path` FROM `*PREFIX*filecache` WHERE `fileid` = ?';
+ $result = \OC_DB::executeAudited($sql, array($id));
if ($row = $result->fetchRow()) {
$numericId = $row['storage'];
$path = $row['path'];
@@ -529,4 +567,14 @@ class Cache {
return null;
}
}
+
+ /**
+ * normalize the given path
+ * @param $path
+ * @return string
+ */
+ public function normalize($path) {
+
+ return \OC_Util::normalizeUnicode($path);
+ }
}
diff --git a/lib/files/cache/legacy.php b/lib/files/cache/legacy.php
index b8e2548639b..8eed1f67a5d 100644
--- a/lib/files/cache/legacy.php
+++ b/lib/files/cache/legacy.php
@@ -26,8 +26,8 @@ class Legacy {
* @return int
*/
function getCount() {
- $query = \OC_DB::prepare('SELECT COUNT(`id`) AS `count` FROM `*PREFIX*fscache` WHERE `user` = ?');
- $result = $query->execute(array($this->user));
+ $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 {
@@ -45,7 +45,7 @@ class Legacy {
return $this->cacheHasItems;
}
try {
- $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*fscache` WHERE `user` = ? LIMIT 1');
+ $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*fscache` WHERE `user` = ?',1);
} catch (\Exception $e) {
$this->cacheHasItems = false;
return false;
@@ -74,11 +74,11 @@ class Legacy {
*/
function get($path) {
if (is_numeric($path)) {
- $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*fscache` WHERE `id` = ?');
+ $sql = 'SELECT * FROM `*PREFIX*fscache` WHERE `id` = ?';
} else {
- $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*fscache` WHERE `path` = ?');
+ $sql = 'SELECT * FROM `*PREFIX*fscache` WHERE `path` = ?';
}
- $result = $query->execute(array($path));
+ $result = \OC_DB::executeAudited($sql, array($path));
$data = $result->fetchRow();
$data['etag'] = $this->getEtag($data['path'], $data['user']);
return $data;
@@ -111,7 +111,7 @@ class Legacy {
if(is_null($query)){
$query = \OC_DB::prepare('SELECT `propertyvalue` FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = \'{DAV:}getetag\'');
}
- $result = $query->execute(array($user, '/' . $relativePath));
+ $result = \OC_DB::executeAudited($query,array($user, '/' . $relativePath));
if ($row = $result->fetchRow()) {
return trim($row['propertyvalue'], '"');
} else {
@@ -126,8 +126,7 @@ class Legacy {
* @return array
*/
function getChildren($id) {
- $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*fscache` WHERE `parent` = ?');
- $result = $query->execute(array($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']);
diff --git a/lib/files/cache/permissions.php b/lib/files/cache/permissions.php
index faa5ff5eacc..2e2bdb20b78 100644
--- a/lib/files/cache/permissions.php
+++ b/lib/files/cache/permissions.php
@@ -33,8 +33,8 @@ class Permissions {
* @return int (-1 if file no permissions set)
*/
public function get($fileId, $user) {
- $query = \OC_DB::prepare('SELECT `permissions` FROM `*PREFIX*permissions` WHERE `user` = ? AND `fileid` = ?');
- $result = $query->execute(array($user, $fileId));
+ $sql = 'SELECT `permissions` FROM `*PREFIX*permissions` WHERE `user` = ? AND `fileid` = ?';
+ $result = \OC_DB::executeAudited($sql, array($user, $fileId));
if ($row = $result->fetchRow()) {
return $row['permissions'];
} else {
@@ -51,13 +51,11 @@ class Permissions {
*/
public function set($fileId, $user, $permissions) {
if (self::get($fileId, $user) !== -1) {
- $query = \OC_DB::prepare('UPDATE `*PREFIX*permissions` SET `permissions` = ?'
- . ' WHERE `user` = ? AND `fileid` = ?');
+ $sql = 'UPDATE `*PREFIX*permissions` SET `permissions` = ? WHERE `user` = ? AND `fileid` = ?';
} else {
- $query = \OC_DB::prepare('INSERT INTO `*PREFIX*permissions`(`permissions`, `user`, `fileid`)'
- . ' VALUES(?, ?,? )');
+ $sql = 'INSERT INTO `*PREFIX*permissions`(`permissions`, `user`, `fileid`) VALUES(?, ?,? )';
}
- $query->execute(array($permissions, $user, $fileId));
+ \OC_DB::executeAudited($sql, array($permissions, $user, $fileId));
}
/**
@@ -75,9 +73,30 @@ class Permissions {
$params[] = $user;
$inPart = implode(', ', array_fill(0, count($fileIds), '?'));
- $query = \OC_DB::prepare('SELECT `fileid`, `permissions` FROM `*PREFIX*permissions`'
- . ' WHERE `fileid` IN (' . $inPart . ') AND `user` = ?');
- $result = $query->execute($params);
+ $sql = 'SELECT `fileid`, `permissions` FROM `*PREFIX*permissions`'
+ . ' WHERE `fileid` IN (' . $inPart . ') AND `user` = ?';
+ $result = \OC_DB::executeAudited($sql, $params);
+ $filePermissions = array();
+ while ($row = $result->fetchRow()) {
+ $filePermissions[$row['fileid']] = $row['permissions'];
+ }
+ return $filePermissions;
+ }
+
+ /**
+ * get the permissions for all files in a folder
+ *
+ * @param int $parentId
+ * @param string $user
+ * @return int[]
+ */
+ public function getDirectoryPermissions($parentId, $user) {
+ $sql = 'SELECT `*PREFIX*permissions`.`fileid`, `permissions`
+ FROM `*PREFIX*permissions`
+ INNER JOIN `*PREFIX*filecache` ON `*PREFIX*permissions`.`fileid` = `*PREFIX*filecache`.`fileid`
+ WHERE `*PREFIX*filecache`.`parent` = ? AND `*PREFIX*permissions`.`user` = ?';
+
+ $result = \OC_DB::executeAudited($sql, array($parentId, $user));
$filePermissions = array();
while ($row = $result->fetchRow()) {
$filePermissions[$row['fileid']] = $row['permissions'];
@@ -93,18 +112,17 @@ class Permissions {
*/
public function remove($fileId, $user = null) {
if (is_null($user)) {
- $query = \OC_DB::prepare('DELETE FROM `*PREFIX*permissions` WHERE `fileid` = ?');
- $query->execute(array($fileId));
+ \OC_DB::executeAudited('DELETE FROM `*PREFIX*permissions` WHERE `fileid` = ?', array($fileId));
} else {
- $query = \OC_DB::prepare('DELETE FROM `*PREFIX*permissions` WHERE `fileid` = ? AND `user` = ?');
- $query->execute(array($fileId, $user));
+ $sql = 'DELETE FROM `*PREFIX*permissions` WHERE `fileid` = ? AND `user` = ?';
+ \OC_DB::executeAudited($sql, array($fileId, $user));
}
}
public function removeMultiple($fileIds, $user) {
$query = \OC_DB::prepare('DELETE FROM `*PREFIX*permissions` WHERE `fileid` = ? AND `user` = ?');
foreach ($fileIds as $fileId) {
- $query->execute(array($fileId, $user));
+ \OC_DB::executeAudited($query, array($fileId, $user));
}
}
@@ -114,8 +132,8 @@ class Permissions {
* @param int $fileId
*/
public function getUsers($fileId) {
- $query = \OC_DB::prepare('SELECT `user` FROM `*PREFIX*permissions` WHERE `fileid` = ?');
- $result = $query->execute(array($fileId));
+ $sql = 'SELECT `user` FROM `*PREFIX*permissions` WHERE `fileid` = ?';
+ $result = \OC_DB::executeAudited($sql, array($fileId));
$users = array();
while ($row = $result->fetchRow()) {
$users[] = $row['user'];
diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php
index 661bc486330..8f9a7921956 100644
--- a/lib/files/cache/scanner.php
+++ b/lib/files/cache/scanner.php
@@ -51,6 +51,7 @@ class Scanner {
$data['size'] = $this->storage->filesize($path);
}
$data['etag'] = $this->storage->getETag($path);
+ $data['storage_mtime'] = $data['mtime'];
return $data;
}
@@ -77,18 +78,21 @@ class Scanner {
$this->scanFile($parent);
}
}
- if($cacheData = $this->cache->get($file)) {
+ $newData = $data;
+ if ($cacheData = $this->cache->get($file)) {
+ if ($checkExisting && $data['size'] === -1) {
+ $data['size'] = $cacheData['size'];
+ }
if ($data['mtime'] === $cacheData['mtime'] &&
$data['size'] === $cacheData['size']) {
$data['etag'] = $cacheData['etag'];
}
+ // Only update metadata that has changed
+ $newData = array_diff($data, $cacheData);
}
- if ($checkExisting and $cacheData) {
- if ($data['size'] === -1) {
- $data['size'] = $cacheData['size'];
- }
+ if (!empty($newData)) {
+ $this->cache->put($file, $newData);
}
- $this->cache->put($file, $data);
}
return $data;
}
@@ -115,7 +119,7 @@ class Scanner {
\OC_DB::beginTransaction();
while ($file = readdir($dh)) {
$child = ($path) ? $path . '/' . $file : $file;
- if (!$this->isIgnoredDir($file)) {
+ if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
$data = $this->scanFile($child, $recursive === self::SCAN_SHALLOW);
if ($data) {
if ($data['size'] === -1) {
@@ -150,18 +154,6 @@ class Scanner {
}
/**
- * @brief check if the directory should be ignored when scanning
- * NOTE: the special directories . and .. would cause never ending recursion
- * @param String $dir
- * @return boolean
- */
- private function isIgnoredDir($dir) {
- if ($dir === '.' || $dir === '..') {
- return true;
- }
- return false;
- }
- /**
* @brief check if the file should be ignored when scanning
* NOTE: files with a '.part' extension are ignored as well!
* prevents unfinished put requests to be scanned
@@ -179,9 +171,11 @@ class Scanner {
* walk over any folders that are not fully scanned yet and scan them
*/
public function backgroundScan() {
- while (($path = $this->cache->getIncomplete()) !== false) {
+ $lastPath = null;
+ while (($path = $this->cache->getIncomplete()) !== false && $path !== $lastPath) {
$this->scan($path);
$this->cache->correctFolderSize($path);
+ $lastPath = $path;
}
}
}
diff --git a/lib/files/cache/storage.php b/lib/files/cache/storage.php
index 72de376798c..8a9e47ca36d 100644
--- a/lib/files/cache/storage.php
+++ b/lib/files/cache/storage.php
@@ -32,13 +32,13 @@ class Storage {
$this->storageId = md5($this->storageId);
}
- $query = \OC_DB::prepare('SELECT `numeric_id` FROM `*PREFIX*storages` WHERE `id` = ?');
- $result = $query->execute(array($this->storageId));
+ $sql = 'SELECT `numeric_id` FROM `*PREFIX*storages` WHERE `id` = ?';
+ $result = \OC_DB::executeAudited($sql, array($this->storageId));
if ($row = $result->fetchRow()) {
$this->numericId = $row['numeric_id'];
} else {
- $query = \OC_DB::prepare('INSERT INTO `*PREFIX*storages`(`id`) VALUES(?)');
- $query->execute(array($this->storageId));
+ $sql = 'INSERT INTO `*PREFIX*storages` (`id`) VALUES(?)';
+ \OC_DB::executeAudited($sql, array($this->storageId));
$this->numericId = \OC_DB::insertid('*PREFIX*storages');
}
}
@@ -48,8 +48,9 @@ class Storage {
}
public static function getStorageId($numericId) {
- $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*storages` WHERE `numeric_id` = ?');
- $result = $query->execute(array($numericId));
+
+ $sql = 'SELECT `id` FROM `*PREFIX*storages` WHERE `numeric_id` = ?';
+ $result = \OC_DB::executeAudited($sql, array($numericId));
if ($row = $result->fetchRow()) {
return $row['id'];
} else {
diff --git a/lib/files/cache/upgrade.php b/lib/files/cache/upgrade.php
index ca044ba81de..cfb9a117311 100644
--- a/lib/files/cache/upgrade.php
+++ b/lib/files/cache/upgrade.php
@@ -78,7 +78,7 @@ class Upgrade {
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
}
if (!$this->inCache($data['storage'], $data['path_hash'], $data['id'])) {
- $insertQuery->execute(array($data['id'], $data['storage'],
+ \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']));
}
@@ -97,7 +97,7 @@ class Upgrade {
if(is_null($query)) {
$query = \OC_DB::prepare('SELECT `fileid` FROM `*PREFIX*filecache` WHERE (`storage` = ? AND `path_hash` = ?) OR `fileid` = ?');
}
- $result = $query->execute(array($storage, $pathHash, $id));
+ $result = \OC_DB::executeAudited($query, array($storage, $pathHash, $id));
return (bool)$result->fetchRow();
}
diff --git a/lib/files/cache/watcher.php b/lib/files/cache/watcher.php
index 31059ec7f56..8bfd4602f3a 100644
--- a/lib/files/cache/watcher.php
+++ b/lib/files/cache/watcher.php
@@ -43,7 +43,7 @@ class Watcher {
*/
public function checkUpdate($path) {
$cachedEntry = $this->cache->get($path);
- if ($this->storage->hasUpdated($path, $cachedEntry['mtime'])) {
+ if ($this->storage->hasUpdated($path, $cachedEntry['storage_mtime'])) {
if ($this->storage->is_dir($path)) {
$this->scanner->scan($path, Scanner::SCAN_SHALLOW);
} else {
diff --git a/lib/files/filesystem.php b/lib/files/filesystem.php
index d60d430d77c..d3fddf8c421 100644
--- a/lib/files/filesystem.php
+++ b/lib/files/filesystem.php
@@ -152,6 +152,9 @@ class Filesystem {
* @return string
*/
static public function getMountPoint($path) {
+ if (!self::$mounts) {
+ \OC_Util::setupFS();
+ }
$mount = self::$mounts->find($path);
if ($mount) {
return $mount->getMountPoint();
@@ -167,6 +170,9 @@ class Filesystem {
* @return string[]
*/
static public function getMountPoints($path) {
+ if (!self::$mounts) {
+ \OC_Util::setupFS();
+ }
$result = array();
$mounts = self::$mounts->findIn($path);
foreach ($mounts as $mount) {
@@ -182,6 +188,9 @@ class Filesystem {
* @return \OC\Files\Storage\Storage
*/
public static function getStorage($mountPoint) {
+ if (!self::$mounts) {
+ \OC_Util::setupFS();
+ }
$mount = self::$mounts->find($mountPoint);
return $mount->getStorage();
}
@@ -191,6 +200,9 @@ class Filesystem {
* @return Mount\Mount[]
*/
public static function getMountByStorageId($id) {
+ if (!self::$mounts) {
+ \OC_Util::setupFS();
+ }
return self::$mounts->findByStorageId($id);
}
@@ -199,6 +211,9 @@ class Filesystem {
* @return Mount\Mount[]
*/
public static function getMountByNumericId($id) {
+ if (!self::$mounts) {
+ \OC_Util::setupFS();
+ }
return self::$mounts->findByNumericId($id);
}
@@ -209,6 +224,9 @@ class Filesystem {
* @return array consisting of the storage and the internal path
*/
static public function resolvePath($path) {
+ if (!self::$mounts) {
+ \OC_Util::setupFS();
+ }
$mount = self::$mounts->find($path);
if ($mount) {
return array($mount->getStorage(), $mount->getInternalPath($path));
@@ -223,7 +241,7 @@ class Filesystem {
}
self::$defaultInstance = new View($root);
- if(!self::$mounts) {
+ if (!self::$mounts) {
self::$mounts = new Mount\Manager();
}
@@ -235,8 +253,10 @@ class Filesystem {
return true;
}
- static public function initMounts(){
- self::$mounts = new Mount\Manager();
+ static public function initMounts() {
+ if (!self::$mounts) {
+ self::$mounts = new Mount\Manager();
+ }
}
/**
@@ -357,7 +377,9 @@ class Filesystem {
* clear all mounts and storage backends
*/
public static function clearMounts() {
- self::$mounts->clear();
+ if (self::$mounts) {
+ self::$mounts->clear();
+ }
}
/**
@@ -368,6 +390,9 @@ class Filesystem {
* @param string $mountpoint
*/
static public function mount($class, $arguments, $mountpoint) {
+ if (!self::$mounts) {
+ \OC_Util::setupFS();
+ }
$mount = new Mount\Mount($class, $mountpoint, $arguments);
self::$mounts->addMount($mount);
}
@@ -454,6 +479,19 @@ class Filesystem {
}
/**
+ * @brief check if the directory should be ignored when scanning
+ * NOTE: the special directories . and .. would cause never ending recursion
+ * @param String $dir
+ * @return boolean
+ */
+ static public function isIgnoredDir($dir) {
+ if ($dir === '.' || $dir === '..') {
+ return true;
+ }
+ return false;
+ }
+
+ /**
* following functions are equivalent to their php builtin equivalents for arguments/return values.
*/
static public function mkdir($path) {
@@ -616,9 +654,8 @@ class Filesystem {
$path = substr($path, 0, -1);
}
//normalize unicode if possible
- if (class_exists('Normalizer')) {
- $path = \Normalizer::normalize($path);
- }
+ $path = \OC_Util::normalizeUnicode($path);
+
return $path;
}
diff --git a/lib/files/mapper.php b/lib/files/mapper.php
index 15f5f0628b5..47abd4e52fe 100644
--- a/lib/files/mapper.php
+++ b/lib/files/mapper.php
@@ -53,11 +53,9 @@ class Mapper
}
if ($isLogicPath) {
- $query = \OC_DB::prepare('DELETE FROM `*PREFIX*file_map` WHERE `logic_path` LIKE ?');
- $query->execute(array($path));
+ \OC_DB::executeAudited('DELETE FROM `*PREFIX*file_map` WHERE `logic_path` LIKE ?', array($path));
} else {
- $query = \OC_DB::prepare('DELETE FROM `*PREFIX*file_map` WHERE `physic_path` LIKE ?');
- $query->execute(array($path));
+ \OC_DB::executeAudited('DELETE FROM `*PREFIX*file_map` WHERE `physic_path` LIKE ?', array($path));
}
}
@@ -73,8 +71,8 @@ class Mapper
$physicPath1 = $this->logicToPhysical($path1, true);
$physicPath2 = $this->logicToPhysical($path2, true);
- $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*file_map` WHERE `logic_path` LIKE ?');
- $result = $query->execute(array($path1.'%'));
+ $sql = 'SELECT * FROM `*PREFIX*file_map` WHERE `logic_path` LIKE ?';
+ $result = \OC_DB::executeAudited($sql, array($path1.'%'));
$updateQuery = \OC_DB::prepare('UPDATE `*PREFIX*file_map`'
.' SET `logic_path` = ?'
.' , `logic_path_hash` = ?'
@@ -88,7 +86,8 @@ class Mapper
$newPhysic = $physicPath2.$this->stripRootFolder($currentPhysic, $physicPath1);
if ($path1 !== $currentLogic) {
try {
- $updateQuery->execute(array($newLogic, md5($newLogic), $newPhysic, md5($newPhysic), $currentLogic));
+ \OC_DB::executeAudited($updateQuery, array($newLogic, md5($newLogic), $newPhysic, md5($newPhysic),
+ $currentLogic));
} catch (\Exception $e) {
error_log('Mapper::Copy failed '.$currentLogic.' -> '.$newLogic.'\n'.$e);
throw $e;
@@ -123,8 +122,8 @@ class Mapper
private function resolveLogicPath($logicPath) {
$logicPath = $this->stripLast($logicPath);
- $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*file_map` WHERE `logic_path_hash` = ?');
- $result = $query->execute(array(md5($logicPath)));
+ $sql = 'SELECT * FROM `*PREFIX*file_map` WHERE `logic_path_hash` = ?';
+ $result = \OC_DB::executeAudited($sql, array(md5($logicPath)));
$result = $result->fetchRow();
if ($result === false) {
return null;
@@ -135,8 +134,8 @@ class Mapper
private function resolvePhysicalPath($physicalPath) {
$physicalPath = $this->stripLast($physicalPath);
- $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*file_map` WHERE `physic_path_hash` = ?');
- $result = $query->execute(array(md5($physicalPath)));
+ $sql = \OC_DB::prepare('SELECT * FROM `*PREFIX*file_map` WHERE `physic_path_hash` = ?');
+ $result = \OC_DB::executeAudited($sql, array(md5($physicalPath)));
$result = $result->fetchRow();
return $result['logic_path'];
@@ -163,8 +162,9 @@ class Mapper
}
private function insert($logicPath, $physicalPath) {
- $query = \OC_DB::prepare('INSERT INTO `*PREFIX*file_map`(`logic_path`, `physic_path`, `logic_path_hash`, `physic_path_hash`) VALUES(?, ?, ?, ?)');
- $query->execute(array($logicPath, $physicalPath, md5($logicPath), md5($physicalPath)));
+ $sql = 'INSERT INTO `*PREFIX*file_map` (`logic_path`, `physic_path`, `logic_path_hash`, `physic_path_hash`)
+ VALUES (?, ?, ?, ?)';
+ \OC_DB::executeAudited($sql, array($logicPath, $physicalPath, md5($logicPath), md5($physicalPath)));
}
public function slugifyPath($path, $index=null) {
@@ -172,14 +172,9 @@ class Mapper
$pathElements = explode('/', $path);
$sluggedElements = array();
-
- // rip off the extension ext from last element
+
$last= end($pathElements);
- $parts = pathinfo($last);
- $filename = $parts['filename'];
- array_pop($pathElements);
- array_push($pathElements, $filename);
-
+
foreach ($pathElements as $pathElement) {
// remove empty elements
if (empty($pathElement)) {
@@ -192,13 +187,15 @@ class Mapper
// apply index to file name
if ($index !== null) {
$last= array_pop($sluggedElements);
- array_push($sluggedElements, $last.'-'.$index);
- }
+
+ // if filename contains periods - add index number before last period
+ if (preg_match('~\.[^\.]+$~i',$last,$extension)){
+ array_push($sluggedElements, substr($last,0,-(strlen($extension[0]))).'-'.$index.$extension[0]);
+ } else {
+ // if filename doesn't contain periods add index ofter the last char
+ array_push($sluggedElements, $last.'-'.$index);
+ }
- // add back the extension
- if (isset($parts['extension'])) {
- $last= array_pop($sluggedElements);
- array_push($sluggedElements, $last.'.'.$parts['extension']);
}
$sluggedPath = $this->unchangedPhysicalRoot.implode('/', $sluggedElements);
@@ -213,8 +210,8 @@ class Mapper
*/
private function slugify($text)
{
- // replace non letter or digits by -
- $text = preg_replace('~[^\\pL\d]+~u', '-', $text);
+ // replace non letter or digits or dots by -
+ $text = preg_replace('~[^\\pL\d\.]+~u', '-', $text);
// trim
$text = trim($text, '-');
@@ -228,7 +225,10 @@ class Mapper
$text = strtolower($text);
// remove unwanted characters
- $text = preg_replace('~[^-\w]+~', '', $text);
+ $text = preg_replace('~[^-\w\.]+~', '', $text);
+
+ // trim ending dots (for security reasons and win compatibility)
+ $text = preg_replace('~\.+$~', '', $text);
if (empty($text)) {
return uniqid();
diff --git a/lib/files/storage/common.php b/lib/files/storage/common.php
index e87fe3b5239..3da13ac4df0 100644
--- a/lib/files/storage/common.php
+++ b/lib/files/storage/common.php
@@ -138,27 +138,21 @@ abstract class Common implements \OC\Files\Storage\Storage {
*/
public function deleteAll($directory, $empty = false) {
$directory = trim($directory, '/');
-
- if (!$this->file_exists(\OCP\USER::getUser() . '/' . $directory)
- || !$this->is_dir(\OCP\USER::getUser() . '/' . $directory)
- ) {
- return false;
- } elseif (!$this->isReadable(\OCP\USER::getUser() . '/' . $directory)) {
+ if (!$this->is_dir($directory) || !$this->isReadable($directory)) {
return false;
} else {
- $directoryHandle = $this->opendir(\OCP\USER::getUser() . '/' . $directory);
+ $directoryHandle = $this->opendir($directory);
while ($contents = readdir($directoryHandle)) {
- if ($contents != '.' && $contents != '..') {
- $path = $directory . "/" . $contents;
+ if (!\OC\Files\Filesystem::isIgnoredDir($contents)) {
+ $path = $directory . '/' . $contents;
if ($this->is_dir($path)) {
$this->deleteAll($path);
} else {
- $this->unlink(\OCP\USER::getUser() . '/' . $path); // TODO: make unlink use same system path as is_dir
+ $this->unlink($path);
}
}
}
- //$this->closedir( $directoryHandle ); // TODO: implement closedir in OC_FSV
- if ($empty == false) {
+ if ($empty === false) {
if (!$this->rmdir($directory)) {
return false;
}
diff --git a/lib/files/view.php b/lib/files/view.php
index f35e1e3dc16..e2fc8d965b8 100644
--- a/lib/files/view.php
+++ b/lib/files/view.php
@@ -251,8 +251,11 @@ class View {
if (!$this->file_exists($path)) {
$hooks[] = 'write';
}
-
- return $this->basicOperation('touch', $path, $hooks, $mtime);
+ $result = $this->basicOperation('touch', $path, $hooks, $mtime);
+ if (!$result) { //if native touch fails, we emulate it by changing the mtime in the cache
+ $this->putFileInfo($path, array('mtime' => $mtime));
+ }
+ return true;
}
public function file_get_contents($path) {
@@ -264,7 +267,7 @@ class View {
$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
if (\OC_FileProxy::runPreProxies('file_put_contents', $absolutePath, $data)
and Filesystem::isValidPath($path)
- and ! Filesystem::isFileBlacklisted($path)
+ and !Filesystem::isFileBlacklisted($path)
) {
$path = $this->getRelativePath($absolutePath);
$exists = $this->file_exists($path);
@@ -297,7 +300,7 @@ class View {
list ($count, $result) = \OC_Helper::streamCopy($data, $target);
fclose($target);
fclose($data);
- if ($this->fakeRoot == Filesystem::getRoot() && !Cache\Scanner::isPartialFile($path)) {
+ if ($this->fakeRoot == Filesystem::getRoot() && !Cache\Scanner::isPartialFile($path) && $result !== false) {
if (!$exists) {
\OC_Hook::emit(
Filesystem::CLASSNAME,
@@ -341,7 +344,7 @@ class View {
\OC_FileProxy::runPreProxies('rename', $absolutePath1, $absolutePath2)
and Filesystem::isValidPath($path2)
and Filesystem::isValidPath($path1)
- and ! Filesystem::isFileBlacklisted($path2)
+ and !Filesystem::isFileBlacklisted($path2)
) {
$path1 = $this->getRelativePath($absolutePath1);
$path2 = $this->getRelativePath($absolutePath2);
@@ -368,17 +371,28 @@ class View {
list(, $internalPath2) = Filesystem::resolvePath($absolutePath2 . $postFix2);
if ($storage) {
$result = $storage->rename($internalPath1, $internalPath2);
+ \OC_FileProxy::runPostProxies('rename', $absolutePath1, $absolutePath2);
} else {
$result = false;
}
} else {
- $source = $this->fopen($path1 . $postFix1, 'r');
- $target = $this->fopen($path2 . $postFix2, 'w');
- list($count, $result) = \OC_Helper::streamCopy($source, $target);
- list($storage1, $internalPath1) = Filesystem::resolvePath($absolutePath1 . $postFix1);
- $storage1->unlink($internalPath1);
+ if ($this->is_dir($path1)) {
+ $result = $this->copy($path1, $path2);
+ if ($result === true) {
+ list($storage1, $internalPath1) = Filesystem::resolvePath($absolutePath1 . $postFix1);
+ $result = $storage1->deleteAll($internalPath1);
+ }
+ } else {
+ $source = $this->fopen($path1 . $postFix1, 'r');
+ $target = $this->fopen($path2 . $postFix2, 'w');
+ list($count, $result) = \OC_Helper::streamCopy($source, $target);
+ if ($result !== false) {
+ list($storage1, $internalPath1) = Filesystem::resolvePath($absolutePath1 . $postFix1);
+ $storage1->unlink($internalPath1);
+ }
+ }
}
- if ($this->fakeRoot == Filesystem::getRoot() && !Cache\Scanner::isPartialFile($path1)) {
+ if ($this->fakeRoot == Filesystem::getRoot() && !Cache\Scanner::isPartialFile($path1) && $result !== false) {
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_post_rename,
@@ -406,7 +420,7 @@ class View {
\OC_FileProxy::runPreProxies('copy', $absolutePath1, $absolutePath2)
and Filesystem::isValidPath($path2)
and Filesystem::isValidPath($path1)
- and ! Filesystem::isFileBlacklisted($path2)
+ and !Filesystem::isFileBlacklisted($path2)
) {
$path1 = $this->getRelativePath($absolutePath1);
$path2 = $this->getRelativePath($absolutePath2);
@@ -459,11 +473,20 @@ class View {
$result = false;
}
} else {
- $source = $this->fopen($path1 . $postFix1, 'r');
- $target = $this->fopen($path2 . $postFix2, 'w');
- list($count, $result) = \OC_Helper::streamCopy($source, $target);
+ if ($this->is_dir($path1) && ($dh = $this->opendir($path1))) {
+ $result = $this->mkdir($path2);
+ while ($file = readdir($dh)) {
+ if (!Filesystem::isIgnoredDir($file)) {
+ $result = $this->copy($path1 . '/' . $file, $path2 . '/' . $file);
+ }
+ }
+ } else {
+ $source = $this->fopen($path1 . $postFix1, 'r');
+ $target = $this->fopen($path2 . $postFix2, 'w');
+ list($count, $result) = \OC_Helper::streamCopy($source, $target);
+ }
}
- if ($this->fakeRoot == Filesystem::getRoot()) {
+ if ($this->fakeRoot == Filesystem::getRoot() && $result !== false) {
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_post_copy,
@@ -611,7 +634,7 @@ class View {
$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
if (\OC_FileProxy::runPreProxies($operation, $absolutePath, $extraParam)
and Filesystem::isValidPath($path)
- and ! Filesystem::isFileBlacklisted($path)
+ and !Filesystem::isFileBlacklisted($path)
) {
$path = $this->getRelativePath($absolutePath);
if ($path == null) {
@@ -627,7 +650,7 @@ class View {
$result = $storage->$operation($internalPath);
}
$result = \OC_FileProxy::runPostProxies($operation, $this->getAbsolutePath($path), $result);
- if (Filesystem::$loaded and $this->fakeRoot == Filesystem::getRoot()) {
+ if (Filesystem::$loaded and $this->fakeRoot == Filesystem::getRoot() && $result !== false) {
if ($operation != 'fopen') { //no post hooks for fopen, the file stream is still open
$this->runHooks($hooks, $path, true);
}
@@ -738,6 +761,9 @@ class View {
$data['permissions'] = $permissions;
}
}
+
+ $data = \OC_FileProxy::runPostProxies('getFileInfo', $path, $data);
+
return $data;
}
@@ -773,18 +799,18 @@ class View {
}
$files = $cache->getFolderContents($internalPath); //TODO: mimetype_filter
+ $permissions = $permissionsCache->getDirectoryPermissions($cache->getId($internalPath), $user);
$ids = array();
foreach ($files as $i => $file) {
$files[$i]['type'] = $file['mimetype'] === 'httpd/unix-directory' ? 'dir' : 'file';
$ids[] = $file['fileid'];
- $permissions = $permissionsCache->get($file['fileid'], $user);
- if ($permissions === -1) {
- $permissions = $storage->getPermissions($file['path']);
- $permissionsCache->set($file['fileid'], $user, $permissions);
+ if (!isset($permissions[$file['fileid']])) {
+ $permissions[$file['fileid']] = $storage->getPermissions($file['path']);
+ $permissionsCache->set($file['fileid'], $user, $permissions[$file['fileid']]);
}
- $files[$i]['permissions'] = $permissions;
+ $files[$i]['permissions'] = $permissions[$file['fileid']];
}
//add a folder for any mountpoint in this directory and add the sizes of other mountpoints to the folders