summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/private/files/fileinfo.php189
-rw-r--r--lib/private/files/view.php42
-rw-r--r--lib/public/files/fileinfo.php138
-rw-r--r--lib/public/util.php2
4 files changed, 352 insertions, 19 deletions
diff --git a/lib/private/files/fileinfo.php b/lib/private/files/fileinfo.php
new file mode 100644
index 00000000000..7edea13df96
--- /dev/null
+++ b/lib/private/files/fileinfo.php
@@ -0,0 +1,189 @@
+<?php
+/**
+ * Copyright (c) 2014 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;
+
+class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess, \JsonSerializable {
+ /**
+ * @var array $data
+ */
+ private $data;
+
+ /**
+ * @var string $path
+ */
+ private $path;
+
+ /**
+ * @var \OC\Files\Storage\Storage $storage
+ */
+ private $storage;
+
+ /**
+ * @var string $internalPath
+ */
+ private $internalPath;
+
+ public function __construct($path, $storage, $internalPath, $data) {
+ $this->path = $path;
+ $this->storage = $storage;
+ $this->internalPath = $internalPath;
+ $this->data = $data;
+ }
+
+ public function offsetSet($offset, $value) {
+ $this->data[$offset] = $value;
+ }
+
+ public function offsetExists($offset) {
+ return isset($this->data[$offset]);
+ }
+
+ public function offsetUnset($offset) {
+ unset($this->data[$offset]);
+ }
+
+ public function offsetGet($offset) {
+ return $this->data[$offset];
+ }
+
+ public function jsonSerialize() {
+ return $this->data;
+ }
+
+ /**
+ * @return string
+ */
+ public function getPath() {
+ return $this->path;
+ }
+
+ /**
+ * @return \OCP\Files\Storage
+ */
+ public function getStorage() {
+ return $this->storage;
+ }
+
+ /**
+ * @return string
+ */
+ public function getInternalPath() {
+ return $this->internalPath;
+ }
+
+ /**
+ * @return int
+ */
+ public function getId() {
+ return $this->data['fileid'];
+ }
+
+ /**
+ * @return string
+ */
+ public function getMimetype() {
+ return $this->data['mimetype'];
+ }
+
+ /**
+ * @return string
+ */
+ public function getMimePart() {
+ return $this->data['mimepart'];
+ }
+
+ /**
+ * @return string
+ */
+ public function getName() {
+ return $this->data['name'];
+ }
+
+ /**
+ * @return string
+ */
+ public function getEtag() {
+ return $this->data['etag'];
+ }
+
+ /**
+ * @return int
+ */
+ public function getSize() {
+ return $this->data['size'];
+ }
+
+ /**
+ * @return int
+ */
+ public function getMTime() {
+ return $this->data['mtime'];
+ }
+
+ /**
+ * @return bool
+ */
+ public function isEncrypted() {
+ return $this->data['encrypted'];
+ }
+
+ /**
+ * @return int
+ */
+ public function getPermissions() {
+ return $this->data['permissions'];
+ }
+
+ /**
+ * @return \OCP\Files\FileInfo::TYPE_FILE | \OCP\Files\FileInfo::TYPE_FOLDER
+ */
+ public function getType() {
+ return $this->data['type'];
+ }
+
+ public function getData(){
+ return $this->data;
+ }
+
+ /**
+ * @param int $permissions
+ * @return bool
+ */
+ protected function checkPermissions($permissions) {
+ return ($this->getPermissions() & $permissions) === $permissions;
+ }
+
+ /**
+ * @return bool
+ */
+ public function isReadable() {
+ return $this->checkPermissions(\OCP\PERMISSION_READ);
+ }
+
+ /**
+ * @return bool
+ */
+ public function isUpdateable() {
+ return $this->checkPermissions(\OCP\PERMISSION_UPDATE);
+ }
+
+ /**
+ * @return bool
+ */
+ public function isDeletable() {
+ return $this->checkPermissions(\OCP\PERMISSION_DELETE);
+ }
+
+ /**
+ * @return bool
+ */
+ public function isShareable() {
+ return $this->checkPermissions(\OCP\PERMISSION_SHARE);
+ }
+}
diff --git a/lib/private/files/view.php b/lib/private/files/view.php
index d97544b865e..6fc534757b2 100644
--- a/lib/private/files/view.php
+++ b/lib/private/files/view.php
@@ -781,14 +781,7 @@ class View {
* @param string $path
* @param boolean $includeMountPoints whether to add mountpoint sizes,
* defaults to true
- * @return array
- *
- * returns an associative array with the following keys:
- * - size
- * - mtime
- * - mimetype
- * - encrypted
- * - versioned
+ * @return \OC\Files\FileInfo | false
*/
public function getFileInfo($path, $includeMountPoints = true) {
$data = array();
@@ -841,10 +834,13 @@ class View {
$data['permissions'] = $permissions;
}
}
+ if (!$data) {
+ return false;
+ }
$data = \OC_FileProxy::runPostProxies('getFileInfo', $path, $data);
- return $data;
+ return new FileInfo($path, $storage, $internalPath, $data);
}
/**
@@ -852,7 +848,7 @@ class View {
*
* @param string $directory path under datadirectory
* @param string $mimetype_filter limit returned content to this mimetype or mimepart
- * @return array
+ * @return FileInfo[]
*/
public function getDirectoryContent($directory, $mimetype_filter = '') {
$result = array();
@@ -878,7 +874,11 @@ class View {
$watcher->checkUpdate($internalPath);
}
- $files = $cache->getFolderContents($internalPath); //TODO: mimetype_filter
+ $files = array();
+ $contents = $cache->getFolderContents($internalPath); //TODO: mimetype_filter
+ foreach ($contents as $content) {
+ $files[] = new FileInfo($path . '/' . $content['name'], $storage, $content['path'], $content);
+ }
$permissions = $permissionsCache->getDirectoryPermissions($cache->getId($internalPath), $user);
$ids = array();
@@ -936,7 +936,7 @@ class View {
break;
}
}
- $files[] = $rootEntry;
+ $files[] = new FileInfo($path . '/' . $rootEntry['name'], $subStorage, '', $rootEntry);
}
}
}
@@ -958,6 +958,7 @@ class View {
$result = $files;
}
}
+
return $result;
}
@@ -965,12 +966,15 @@ class View {
* change file metadata
*
* @param string $path
- * @param array $data
+ * @param array | \OCP\Files\FileInfo $data
* @return int
*
* returns the fileid of the updated file
*/
public function putFileInfo($path, $data) {
+ if ($data instanceof FileInfo) {
+ $data = $data->getData();
+ }
$path = Filesystem::normalizePath($this->fakeRoot . '/' . $path);
/**
* @var \OC\Files\Storage\Storage $storage
@@ -995,7 +999,7 @@ class View {
* search for files with the name matching $query
*
* @param string $query
- * @return array
+ * @return FileInfo[]
*/
public function search($query) {
return $this->searchCommon('%' . $query . '%', 'search');
@@ -1005,7 +1009,7 @@ class View {
* search for files by mimetype
*
* @param string $mimetype
- * @return array
+ * @return FileInfo[]
*/
public function searchByMime($mimetype) {
return $this->searchCommon($mimetype, 'searchByMime');
@@ -1014,7 +1018,7 @@ class View {
/**
* @param string $query
* @param string $method
- * @return array
+ * @return FileInfo[]
*/
private function searchCommon($query, $method) {
$files = array();
@@ -1028,8 +1032,9 @@ class View {
$results = $cache->$method($query);
foreach ($results as $result) {
if (substr($mountPoint . $result['path'], 0, $rootLength + 1) === $this->fakeRoot . '/') {
+ $internalPath = $result['path'];
$result['path'] = substr($mountPoint . $result['path'], $rootLength);
- $files[] = $result;
+ $files[] = new FileInfo($mountPoint . $result['path'], $storage, $internalPath, $result);
}
}
@@ -1043,8 +1048,9 @@ class View {
$results = $cache->$method($query);
if ($results) {
foreach ($results as $result) {
+ $internalPath = $result['path'];
$result['path'] = $relativeMountPoint . $result['path'];
- $files[] = $result;
+ $files[] = new FileInfo($mountPoint . $result['path'], $storage, $internalPath, $result);
}
}
}
diff --git a/lib/public/files/fileinfo.php b/lib/public/files/fileinfo.php
new file mode 100644
index 00000000000..68ce45d3fa1
--- /dev/null
+++ b/lib/public/files/fileinfo.php
@@ -0,0 +1,138 @@
+<?php
+/**
+ * Copyright (c) 2014 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 OCP\Files;
+
+interface FileInfo {
+ const TYPE_FILE = 'file';
+ const TYPE_FOLDER = 'folder';
+
+ /**
+ * Get the Etag of the file or folder
+ *
+ * @return string
+ */
+ public function getEtag();
+
+ /**
+ * Get the size in bytes for the file or folder
+ *
+ * @return int
+ */
+ public function getSize();
+
+ /**
+ * Get the last modified date as timestamp for the file or folder
+ *
+ * @return int
+ */
+ public function getMtime();
+
+ /**
+ * Get the name of the file or folder
+ *
+ * @return string
+ */
+ public function getName();
+
+ /**
+ * Get the path relative to the storage
+ *
+ * @return string
+ */
+ public function getInternalPath();
+
+ /**
+ * Get the absolute path
+ *
+ * @return string
+ */
+ public function getPath();
+
+ /**
+ * Get the full mimetype of the file or folder i.e. 'image/png'
+ *
+ * @return string
+ */
+ public function getMimetype();
+
+ /**
+ * Get the first part of the mimetype of the file or folder i.e. 'image'
+ *
+ * @return string
+ */
+ public function getMimePart();
+
+ /**
+ * Get the storage the file or folder is storage on
+ *
+ * @return \OCP\Files\Storage
+ */
+ public function getStorage();
+
+ /**
+ * Get the file id of the file or folder
+ *
+ * @return int
+ */
+ public function getId();
+
+ /**
+ * Check whether the file is encrypted
+ *
+ * @return bool
+ */
+ public function isEncrypted();
+
+ /**
+ * Get the permissions of the file or folder as bitmasked combination of the following constants
+ * \OCP\PERMISSION_CREATE
+ * \OCP\PERMISSION_READ
+ * \OCP\PERMISSION_UPDATE
+ * \OCP\PERMISSION_DELETE
+ * \OCP\PERMISSION_SHARE
+ * \OCP\PERMISSION_ALL
+ *
+ * @return int
+ */
+ public function getPermissions();
+
+ /**
+ * Check whether this is a file or a folder
+ *
+ * @return \OCP\Files\FileInfo::TYPE_FILE | \OCP\Files\FileInfo::TYPE_FOLDER
+ */
+ public function getType();
+
+ /**
+ * Check if the file or folder is readable
+ *
+ * @return bool
+ */
+ public function isReadable();
+
+ /**
+ * Check if a file is writable
+ *
+ * @return bool
+ */
+ public function isUpdateable();
+
+ /**
+ * Check if a file or folder can be deleted
+ *
+ * @return bool
+ */
+ public function isDeletable();
+
+ /**
+ * Check if a file or folder can be shared
+ *
+ * @return bool
+ */
+ public function isShareable();
+}
diff --git a/lib/public/util.php b/lib/public/util.php
index 4611e5e2650..570283e2a8a 100644
--- a/lib/public/util.php
+++ b/lib/public/util.php
@@ -121,7 +121,7 @@ class Util {
/**
* get l10n object
* @param string $application
- * @return OC_L10N
+ * @return \OC_L10N
*/
public static function getL10N( $application ) {
return \OC_L10N::get( $application );