mirror of
https://github.com/nextcloud/server.git
synced 2025-03-13 16:03:55 +00:00
Add a FileInfo class which holds all info of a file and return that from getFileInfo, getDirectoryContent and search
This commit is contained in:
parent
85e00ad35a
commit
617acbd6f9
4 changed files with 257 additions and 18 deletions
lib
149
lib/private/files/fileinfo.php
Normal file
149
lib/private/files/fileinfo.php
Normal file
|
@ -0,0 +1,149 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013 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 {
|
||||
/**
|
||||
* @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'];
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
|
@ -838,10 +831,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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -849,7 +845,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();
|
||||
|
@ -875,7 +871,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();
|
||||
|
@ -933,7 +933,7 @@ class View {
|
|||
break;
|
||||
}
|
||||
}
|
||||
$files[] = $rootEntry;
|
||||
$files[] = new FileInfo($path . '/' . $rootEntry['name'], $subStorage, '', $rootEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -955,6 +955,7 @@ class View {
|
|||
$result = $files;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
@ -992,7 +993,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');
|
||||
|
@ -1002,7 +1003,7 @@ class View {
|
|||
* search for files by mimetype
|
||||
*
|
||||
* @param string $mimetype
|
||||
* @return array
|
||||
* @return FileInfo[]
|
||||
*/
|
||||
public function searchByMime($mimetype) {
|
||||
return $this->searchCommon($mimetype, 'searchByMime');
|
||||
|
@ -1011,7 +1012,7 @@ class View {
|
|||
/**
|
||||
* @param string $query
|
||||
* @param string $method
|
||||
* @return array
|
||||
* @return FileInfo[]
|
||||
*/
|
||||
private function searchCommon($query, $method) {
|
||||
$files = array();
|
||||
|
@ -1025,8 +1026,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1040,8 +1042,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
87
lib/public/files/fileinfo.php
Normal file
87
lib/public/files/fileinfo.php
Normal file
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: robin
|
||||
* Date: 1/13/14
|
||||
* Time: 1:45 PM
|
||||
*/
|
||||
namespace OCP\Files;
|
||||
|
||||
interface FileInfo extends \ArrayAccess, \JsonSerializable {
|
||||
const TYPE_FILE = 'file';
|
||||
const TYPE_FOLDER = 'folder';
|
||||
|
||||
public function offsetSet($offset, $value);
|
||||
|
||||
public function offsetGet($offset);
|
||||
|
||||
public function offsetUnset($offset);
|
||||
|
||||
public function offsetExists($offset);
|
||||
|
||||
public function jsonSerialize();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getEtag();
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getSize();
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getMtime();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getInternalPath();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPath();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMimetype();
|
||||
|
||||
/**
|
||||
* @return \OCP\Files\Storage
|
||||
*/
|
||||
public function getStorage();
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMimePart();
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isEncrypted();
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getPermissions();
|
||||
|
||||
/**
|
||||
* @return \OCP\Files\FileInfo::TYPE_FILE | \OCP\Files\FileInfo::TYPE_FOLDER
|
||||
*/
|
||||
public function getType();
|
||||
}
|
|
@ -117,7 +117,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 );
|
||||
|
|
Loading…
Reference in a new issue