return 'object::user:' . $this->user->getUID();
}
- public function getOwner($path): string|false {
+ public function getOwner(string $path): string|false {
return $this->user->getUID();
}
$this->logger = \OCP\Server::get(LoggerInterface::class);
}
- public function mkdir($path, bool $force = false): bool {
+ public function mkdir(string $path, bool $force = false): bool {
$path = $this->normalizePath($path);
if (!$force && $this->file_exists($path)) {
$this->logger->warning("Tried to create an object store folder that already exists: $path");
}
}
- /**
- * @param string $path
- * @return string
- */
- private function normalizePath($path) {
+ private function normalizePath(string $path): string {
$path = trim($path, '/');
//FIXME why do we sometimes get a path like 'files//username'?
$path = str_replace('//', '/', $path);
* Object Stores use a NoopScanner because metadata is directly stored in
* the file cache and cannot really scan the filesystem. The storage passed in is not used anywhere.
*/
- public function getScanner($path = '', $storage = null): IScanner {
+ public function getScanner(string $path = '', ?IStorage $storage = null): IScanner {
if (!$storage) {
$storage = $this;
}
return $this->id;
}
- public function rmdir($path): bool {
+ public function rmdir(string $path): bool {
$path = $this->normalizePath($path);
$entry = $this->getCache()->get($path);
return true;
}
- public function unlink($path): bool {
+ public function unlink(string $path): bool {
$path = $this->normalizePath($path);
$entry = $this->getCache()->get($path);
return true;
}
- public function stat($path): array|false {
+ public function stat(string $path): array|false {
$path = $this->normalizePath($path);
$cacheEntry = $this->getCache()->get($path);
if ($cacheEntry instanceof CacheEntry) {
}
}
- public function getPermissions($path): int {
+ public function getPermissions(string $path): int {
$stat = $this->stat($path);
if (is_array($stat) && isset($stat['permissions'])) {
* The default implementations just appends the fileId to 'urn:oid:'. Make sure the URN is unique over all users.
* You may need a mapping table to store your URN if it cannot be generated from the fileid.
*
- * @param int $fileId the fileid
- * @return null|string the unified resource name used to identify the object
+ * @return string the unified resource name used to identify the object
*/
- public function getURN($fileId) {
- if (is_numeric($fileId)) {
- return $this->objectPrefix . $fileId;
- }
- return null;
+ public function getURN(int $fileId): string {
+ return $this->objectPrefix . $fileId;
}
- public function opendir($path) {
+ public function opendir(string $path) {
$path = $this->normalizePath($path);
try {
}
}
- public function filetype($path): string|false {
+ public function filetype(string $path): string|false {
$path = $this->normalizePath($path);
$stat = $this->stat($path);
if ($stat) {
}
}
- public function fopen($path, $mode) {
+ public function fopen(string $path, string $mode) {
$path = $this->normalizePath($path);
if (strrpos($path, '.') !== false) {
return false;
}
- public function file_exists($path): bool {
+ public function file_exists(string $path): bool {
$path = $this->normalizePath($path);
return (bool)$this->stat($path);
}
- public function rename($source, $target): bool {
+ public function rename(string $source, string $target): bool {
$source = $this->normalizePath($source);
$target = $this->normalizePath($target);
$this->remove($target);
return true;
}
- public function getMimeType($path): string|false {
+ public function getMimeType(string $path): string|false {
$path = $this->normalizePath($path);
return parent::getMimeType($path);
}
- public function touch($path, $mtime = null): bool {
+ public function touch(string $path, ?int $mtime = null): bool {
if (is_null($mtime)) {
$mtime = time();
}
return true;
}
- public function writeBack($tmpFile, $path) {
+ public function writeBack(string $tmpFile, string $path) {
$size = filesize($tmpFile);
$this->writeStream($path, fopen($tmpFile, 'r'), $size);
}
- public function hasUpdated($path, $time): bool {
+ public function hasUpdated(string $path, int $time): bool {
return false;
}
return false;
}
- public function file_put_contents($path, $data): int {
+ public function file_put_contents(string $path, mixed $data): int {
$fh = fopen('php://temp', 'w+');
fwrite($fh, $data);
rewind($fh);
public function copyFromStorage(
IStorage $sourceStorage,
- $sourceInternalPath,
- $targetInternalPath,
- $preserveMtime = false,
+ string $sourceInternalPath,
+ string $targetInternalPath,
+ bool $preserveMtime = false,
): bool {
if ($sourceStorage->instanceOfStorage(ObjectStoreStorage::class)) {
/** @var ObjectStoreStorage $sourceStorage */
return parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
}
- public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, ?ICacheEntry $sourceCacheEntry = null): bool {
+ public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath, ?ICacheEntry $sourceCacheEntry = null): bool {
$sourceCache = $sourceStorage->getCache();
if ($sourceStorage->instanceOfStorage(ObjectStoreStorage::class) && $sourceStorage->getObjectStore()->getStorageId() === $this->getObjectStore()->getStorageId()) {
$this->getCache()->moveFromCache($sourceCache, $sourceInternalPath, $targetInternalPath);
}
}
- public function copy($source, $target): bool {
+ public function copy(string $source, string $target): bool {
$source = $this->normalizePath($source);
$target = $this->normalizePath($target);
public function __construct($parameters) {
}
- /**
- * Remove a file or folder
- *
- * @param string $path
- */
- protected function remove($path): bool {
+ protected function remove(string $path): bool {
if ($this->is_dir($path)) {
return $this->rmdir($path);
} elseif ($this->is_file($path)) {
}
}
- public function is_dir($path): bool {
+ public function is_dir(string $path): bool {
return $this->filetype($path) === 'dir';
}
- public function is_file($path): bool {
+ public function is_file(string $path): bool {
return $this->filetype($path) === 'file';
}
- public function filesize($path): int|float|false {
+ public function filesize(string $path): int|float|false {
if ($this->is_dir($path)) {
return 0; //by definition
} else {
}
}
- public function isReadable($path): bool {
+ public function isReadable(string $path): bool {
// at least check whether it exists
// subclasses might want to implement this more thoroughly
return $this->file_exists($path);
}
- public function isUpdatable($path): bool {
+ public function isUpdatable(string $path): bool {
// at least check whether it exists
// subclasses might want to implement this more thoroughly
// a non-existing file/folder isn't updatable
return $this->file_exists($path);
}
- public function isCreatable($path): bool {
+ public function isCreatable(string $path): bool {
if ($this->is_dir($path) && $this->isUpdatable($path)) {
return true;
}
return false;
}
- public function isDeletable($path): bool {
+ public function isDeletable(string $path): bool {
if ($path === '' || $path === '/') {
return $this->isUpdatable($path);
}
return $this->isUpdatable($parent) && $this->isUpdatable($path);
}
- public function isSharable($path): bool {
+ public function isSharable(string $path): bool {
return $this->isReadable($path);
}
- public function getPermissions($path): int {
+ public function getPermissions(string $path): int {
$permissions = 0;
if ($this->isCreatable($path)) {
$permissions |= \OCP\Constants::PERMISSION_CREATE;
return $permissions;
}
- public function filemtime($path): int|false {
+ public function filemtime(string $path): int|false {
$stat = $this->stat($path);
if (isset($stat['mtime']) && $stat['mtime'] > 0) {
return $stat['mtime'];
}
}
- public function file_get_contents($path): string|false {
+ public function file_get_contents(string $path): string|false {
$handle = $this->fopen($path, 'r');
if (!$handle) {
return false;
return $data;
}
- public function file_put_contents($path, $data): int|float|false {
+ public function file_put_contents(string $path, mixed $data): int|float|false {
$handle = $this->fopen($path, 'w');
if (!$handle) {
return false;
return $count;
}
- public function rename($source, $target): bool {
+ public function rename(string $source, string $target): bool {
$this->remove($target);
$this->removeCachedFile($source);
return $this->copy($source, $target) and $this->remove($source);
}
- public function copy($source, $target): bool {
+ public function copy(string $source, string $target): bool {
if ($this->is_dir($source)) {
$this->remove($target);
$dir = $this->opendir($source);
}
}
- public function getMimeType($path): string|false {
+ public function getMimeType(string $path): string|false {
if ($this->is_dir($path)) {
return 'httpd/unix-directory';
} elseif ($this->file_exists($path)) {
}
}
- public function hash($type, $path, $raw = false): string|false {
+ public function hash(string $type, string $path, bool $raw = false): string|false {
$fh = $this->fopen($path, 'rb');
$ctx = hash_init($type);
hash_update_stream($ctx, $fh);
return hash_final($ctx, $raw);
}
- public function getLocalFile($path): string|false {
+ public function getLocalFile(string $path): string|false {
return $this->getCachedFile($path);
}
- private function addLocalFolder($path, $target): void {
+ private function addLocalFolder(string $path, string $target): void {
$dh = $this->opendir($path);
if (is_resource($dh)) {
while (($file = readdir($dh)) !== false) {
}
}
- protected function searchInDir($query, $dir = ''): array {
+ protected function searchInDir(string $query, string $dir = ''): array {
$files = [];
$dh = $this->opendir($dir);
if (is_resource($dh)) {
* exclusive access to the backend and will not pick up files that have been added in a way that circumvents
* Nextcloud filesystem.
*/
- public function hasUpdated($path, $time): bool {
+ public function hasUpdated(string $path, int $time): bool {
return $this->filemtime($path) > $time;
}
return $dependencies;
}
- public function getCache($path = '', $storage = null): ICache {
+ public function getCache(string $path = '', ?IStorage $storage = null): ICache {
if (!$storage) {
$storage = $this;
}
return $storage->cache;
}
- public function getScanner($path = '', $storage = null): IScanner {
+ public function getScanner(string $path = '', ?IStorage $storage = null): IScanner {
if (!$storage) {
$storage = $this;
}
return $storage->scanner;
}
- public function getWatcher($path = '', $storage = null): IWatcher {
+ public function getWatcher(string $path = '', ?IStorage $storage = null): IWatcher {
if (!$storage) {
$storage = $this;
}
return $this->watcher;
}
- public function getPropagator($storage = null): IPropagator {
+ public function getPropagator(?IStorage $storage = null): IPropagator {
if (!$storage) {
$storage = $this;
}
return $storage->propagator;
}
- public function getUpdater($storage = null): IUpdater {
+ public function getUpdater(?IStorage $storage = null): IUpdater {
if (!$storage) {
$storage = $this;
}
return $storage->updater;
}
- public function getStorageCache($storage = null): \OC\Files\Cache\Storage {
+ public function getStorageCache(?IStorage $storage = null): \OC\Files\Cache\Storage {
/** @var Cache $cache */
- $cache = $this->getCache($storage);
+ $cache = $this->getCache(storage: $storage);
return $cache->getStorageCache();
}
- public function getOwner($path): string|false {
+ public function getOwner(string $path): string|false {
if ($this->owner === null) {
$this->owner = \OC_User::getUser();
}
return $this->owner;
}
- public function getETag($path): string|false {
+ public function getETag(string $path): string|false {
return uniqid();
}
* @param string $path The path to clean
* @return string cleaned path
*/
- public function cleanPath($path): string {
+ public function cleanPath(string $path): string {
if (strlen($path) == 0 or $path[0] != '/') {
$path = '/' . $path;
}
}
}
- public function free_space($path): int|float|false {
+ public function free_space(string $path): int|float|false {
return \OCP\Files\FileInfo::SPACE_UNKNOWN;
}
/**
* Check if the storage is an instance of $class or is a wrapper for a storage that is an instance of $class
- *
- * @param string $class
*/
- public function instanceOfStorage($class): bool {
+ public function instanceOfStorage(string $class): bool {
if (ltrim($class, '\\') === 'OC\Files\Storage\Shared') {
// FIXME Temporary fix to keep existing checks working
$class = '\OCA\Files_Sharing\SharedStorage';
* A custom storage implementation can return an url for direct download of a give file.
*
* For now the returned array can hold the parameter url - in future more attributes might follow.
- *
- * @param string $path
*/
- public function getDirectDownload($path): array|false {
+ public function getDirectDownload(string $path): array|false {
return [];
}
- public function verifyPath($path, $fileName): void {
+ public function verifyPath(string $path, string $fileName): void {
$this->getFilenameValidator()
->validateFilename($fileName);
$this->mountOptions = $options;
}
- /**
- * @param string $name
- * @param mixed $default
- */
- public function getMountOption($name, $default = null): mixed {
+ public function getMountOption(string $name, mixed $default = null): mixed {
return $this->mountOptions[$name] ?? $default;
}
- /**
- * @param string $sourceInternalPath
- * @param string $targetInternalPath
- * @param bool $preserveMtime
- */
- public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false): bool {
+ public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath, bool $preserveMtime = false): bool {
if ($sourceStorage === $this) {
return $this->copy($sourceInternalPath, $targetInternalPath);
}
return $storage === $this;
}
- /**
- * @param string $sourceInternalPath
- * @param string $targetInternalPath
- */
- public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool {
+ public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool {
if ($this->isSameStorage($sourceStorage)) {
// resolve any jailed paths
while ($sourceStorage->instanceOfStorage(Jail::class)) {
return $result;
}
- public function getMetaData($path): ?array {
+ public function getMetaData(string $path): ?array {
if (Filesystem::isFileBlacklisted($path)) {
throw new ForbiddenException('Invalid path: ' . $path, false);
}
return $data;
}
- public function acquireLock($path, $type, ILockingProvider $provider): void {
+ public function acquireLock(string $path, int $type, ILockingProvider $provider): void {
$logger = $this->getLockLogger();
if ($logger) {
$typeString = ($type === ILockingProvider::LOCK_SHARED) ? 'shared' : 'exclusive';
}
}
- public function releaseLock($path, $type, ILockingProvider $provider): void {
+ public function releaseLock(string $path, int $type, ILockingProvider $provider): void {
$logger = $this->getLockLogger();
if ($logger) {
$typeString = ($type === ILockingProvider::LOCK_SHARED) ? 'shared' : 'exclusive';
}
}
- public function changeLock($path, $type, ILockingProvider $provider): void {
+ public function changeLock(string $path, int $type, ILockingProvider $provider): void {
$logger = $this->getLockLogger();
if ($logger) {
$typeString = ($type === ILockingProvider::LOCK_SHARED) ? 'shared' : 'exclusive';
return $this->getStorageCache()->getAvailability();
}
- public function setAvailability($isAvailable): void {
+ public function setAvailability(bool $isAvailable): void {
$this->getStorageCache()->setAvailability($isAvailable);
}
return $count;
}
- public function getDirectoryContent($directory): \Traversable {
+ public function getDirectoryContent(string $directory): \Traversable {
$dh = $this->opendir($directory);
if ($dh === false) {
public function getId(): string {
return 'test::' . $this->storage->getId();
}
- public function mkdir($path): bool {
+ public function mkdir(string $path): bool {
return $this->storage->mkdir($path);
}
- public function rmdir($path): bool {
+ public function rmdir(string $path): bool {
return $this->storage->rmdir($path);
}
- public function opendir($path) {
+ public function opendir(string $path) {
return $this->storage->opendir($path);
}
- public function stat($path): array|false {
+ public function stat(string $path): array|false {
return $this->storage->stat($path);
}
- public function filetype($path): string|false {
+ public function filetype(string $path): string|false {
return @$this->storage->filetype($path);
}
- public function isReadable($path): bool {
+ public function isReadable(string $path): bool {
return $this->storage->isReadable($path);
}
- public function isUpdatable($path): bool {
+ public function isUpdatable(string $path): bool {
return $this->storage->isUpdatable($path);
}
- public function file_exists($path): bool {
+ public function file_exists(string $path): bool {
return $this->storage->file_exists($path);
}
- public function unlink($path): bool {
+ public function unlink(string $path): bool {
return $this->storage->unlink($path);
}
- public function fopen($path, $mode) {
+ public function fopen(string $path, string $mode) {
return $this->storage->fopen($path, $mode);
}
- public function free_space($path): int|float|false {
+ public function free_space(string $path): int|float|false {
return $this->storage->free_space($path);
}
- public function touch($path, $mtime = null): bool {
+ public function touch(string $path, ?int $mtime = null): bool {
return $this->storage->touch($path, $mtime);
}
}
return $baseUri;
}
- public function mkdir($path): bool {
+ public function mkdir(string $path): bool {
$this->init();
$path = $this->cleanPath($path);
$result = $this->simpleResponse('MKCOL', $path, null, 201);
return $result;
}
- public function rmdir($path): bool {
+ public function rmdir(string $path): bool {
$this->init();
$path = $this->cleanPath($path);
// FIXME: some WebDAV impl return 403 when trying to DELETE
return $result;
}
- public function opendir($path) {
+ public function opendir(string $path) {
$this->init();
$path = $this->cleanPath($path);
try {
*
* @throws ClientHttpException
*/
- protected function propfind($path): array|false {
+ protected function propfind(string $path): array|false {
$path = $this->cleanPath($path);
$cachedResponse = $this->statCache->get($path);
// we either don't know it, or we know it exists but need more details
return $response;
}
- public function filetype($path): string|false {
+ public function filetype(string $path): string|false {
try {
$response = $this->propfind($path);
if ($response === false) {
return false;
}
- public function file_exists($path): bool {
+ public function file_exists(string $path): bool {
try {
$path = $this->cleanPath($path);
$cachedState = $this->statCache->get($path);
return false;
}
- public function unlink($path): bool {
+ public function unlink(string $path): bool {
$this->init();
$path = $this->cleanPath($path);
$result = $this->simpleResponse('DELETE', $path, null, 204);
return $result;
}
- public function fopen($path, $mode) {
+ public function fopen(string $path, string $mode) {
$this->init();
$path = $this->cleanPath($path);
switch ($mode) {
}
}
- /**
- * @param string $tmpFile
- */
- public function writeBack($tmpFile, $path): void {
+ public function writeBack(string $tmpFile, string $path): void {
$this->uploadFile($tmpFile, $path);
unlink($tmpFile);
}
- public function free_space($path): int|float|false {
+ public function free_space(string $path): int|float|false {
$this->init();
$path = $this->cleanPath($path);
try {
}
}
- public function touch($path, $mtime = null): bool {
+ public function touch(string $path, ?int $mtime = null): bool {
$this->init();
if (is_null($mtime)) {
$mtime = time();
return true;
}
- /**
- * @param string $path
- * @param mixed $data
- * @return int|float|false
- */
- public function file_put_contents($path, $data): int|float|false {
+ public function file_put_contents(string $path, mixed $data): int|float|false {
$path = $this->cleanPath($path);
$result = parent::file_put_contents($path, $data);
$this->statCache->remove($path);
return $result;
}
- /**
- * @param string $path
- * @param string $target
- */
- protected function uploadFile($path, $target): void {
+ protected function uploadFile(string $path, string $target): void {
$this->init();
// invalidate
$this->removeCachedFile($target);
}
- public function rename($source, $target): bool {
+ public function rename(string $source, string $target): bool {
$this->init();
$source = $this->cleanPath($source);
$target = $this->cleanPath($target);
return false;
}
- public function copy($source, $target): bool {
+ public function copy(string $source, string $target): bool {
$this->init();
$source = $this->cleanPath($source);
$target = $this->cleanPath($target);
return false;
}
- public function getMetaData($path): ?array {
+ public function getMetaData(string $path): ?array {
if (Filesystem::isFileBlacklisted($path)) {
throw new ForbiddenException('Invalid path: ' . $path, false);
}
];
}
- public function stat($path): array|false {
+ public function stat(string $path): array|false {
$meta = $this->getMetaData($path);
return $meta ?: false;
}
- public function getMimeType($path): string|false {
+ public function getMimeType(string $path): string|false {
$meta = $this->getMetaData($path);
return $meta ? $meta['mimetype'] : false;
}
- public function cleanPath($path): string {
+ public function cleanPath(string $path): string {
if ($path === '') {
return $path;
}
* @param string $path to encode
* @return string encoded path
*/
- protected function encodePath($path): string {
+ protected function encodePath(string $path): string {
// slashes need to stay
return str_replace('%2F', '/', rawurlencode($path));
}
/**
- * @param string $method
- * @param string $path
- * @param string|resource|null $body
- * @param int $expected
* @return bool
* @throws StorageInvalidException
* @throws StorageNotAvailableException
*/
- protected function simpleResponse($method, $path, $body, $expected): bool {
+ protected function simpleResponse(string $method, string $path, ?string $body, int $expected): bool {
$path = $this->cleanPath($path);
try {
$response = $this->client->request($method, $this->encodePath($path), $body);
return true;
}
- public function isUpdatable($path): bool {
+ public function isUpdatable(string $path): bool {
return (bool)($this->getPermissions($path) & Constants::PERMISSION_UPDATE);
}
- public function isCreatable($path): bool {
+ public function isCreatable(string $path): bool {
return (bool)($this->getPermissions($path) & Constants::PERMISSION_CREATE);
}
- public function isSharable($path): bool {
+ public function isSharable(string $path): bool {
return (bool)($this->getPermissions($path) & Constants::PERMISSION_SHARE);
}
- public function isDeletable($path): bool {
+ public function isDeletable(string $path): bool {
return (bool)($this->getPermissions($path) & Constants::PERMISSION_DELETE);
}
- public function getPermissions($path): int {
+ public function getPermissions(string $path): int {
$stat = $this->getMetaData($path);
return $stat ? $stat['permissions'] : 0;
}
- public function getETag($path): string|false {
+ public function getETag(string $path): string|false {
$meta = $this->getMetaData($path);
return $meta ? $meta['etag'] : false;
}
- protected function parsePermissions($permissionsString): int {
+ protected function parsePermissions(string $permissionsString): int {
$permissions = Constants::PERMISSION_READ;
if (str_contains($permissionsString, 'R')) {
$permissions |= Constants::PERMISSION_SHARE;
return $permissions;
}
- public function hasUpdated($path, $time): bool {
+ public function hasUpdated(string $path, int $time): bool {
$this->init();
$path = $this->cleanPath($path);
try {
* which might be temporary
* @throws ForbiddenException if the action is not allowed
*/
- protected function convertException(Exception $e, $path = ''): void {
+ protected function convertException(Exception $e, string $path = ''): void {
Server::get(LoggerInterface::class)->debug($e->getMessage(), ['app' => 'files_external', 'exception' => $e]);
if ($e instanceof ClientHttpException) {
if ($e->getHttpStatus() === Http::STATUS_LOCKED) {
// TODO: only log for now, but in the future need to wrap/rethrow exception
}
- public function getDirectoryContent($directory): \Traversable {
+ public function getDirectoryContent(string $directory): \Traversable {
$this->init();
$directory = $this->cleanPath($directory);
try {
return 'failedstorage';
}
- public function mkdir($path): never {
+ public function mkdir(string $path): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function rmdir($path): never {
+ public function rmdir(string $path): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function opendir($path): never {
+ public function opendir(string $path): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function is_dir($path): never {
+ public function is_dir(string $path): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function is_file($path): never {
+ public function is_file(string $path): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function stat($path): never {
+ public function stat(string $path): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function filetype($path): never {
+ public function filetype(string $path): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function filesize($path): never {
+ public function filesize(string $path): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function isCreatable($path): never {
+ public function isCreatable(string $path): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function isReadable($path): never {
+ public function isReadable(string $path): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function isUpdatable($path): never {
+ public function isUpdatable(string $path): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function isDeletable($path): never {
+ public function isDeletable(string $path): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function isSharable($path): never {
+ public function isSharable(string $path): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function getPermissions($path): never {
+ public function getPermissions(string $path): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function file_exists($path): never {
+ public function file_exists(string $path): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function filemtime($path): never {
+ public function filemtime(string $path): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function file_get_contents($path): never {
+ public function file_get_contents(string $path): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function file_put_contents($path, $data): never {
+ public function file_put_contents(string $path, mixed $data): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function unlink($path): never {
+ public function unlink(string $path): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function rename($source, $target): never {
+ public function rename(string $source, string $target): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function copy($source, $target): never {
+ public function copy(string $source, string $target): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function fopen($path, $mode): never {
+ public function fopen(string $path, string $mode): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function getMimeType($path): never {
+ public function getMimeType(string $path): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function hash($type, $path, $raw = false): never {
+ public function hash(string $type, string $path, bool $raw = false): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function free_space($path): never {
+ public function free_space(string $path): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function touch($path, $mtime = null): never {
+ public function touch(string $path, ?int $mtime = null): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function getLocalFile($path): never {
+ public function getLocalFile(string $path): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function hasUpdated($path, $time): never {
+ public function hasUpdated(string $path, int $time): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function getETag($path): never {
+ public function getETag(string $path): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function getDirectDownload($path): never {
+ public function getDirectDownload(string $path): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function verifyPath($path, $fileName): void {
+ public function verifyPath(string $path, string $fileName): void {
}
- public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false): never {
+ public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath, bool $preserveMtime = false): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): never {
+ public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function acquireLock($path, $type, ILockingProvider $provider): never {
+ public function acquireLock(string $path, int $type, ILockingProvider $provider): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function releaseLock($path, $type, ILockingProvider $provider): never {
+ public function releaseLock(string $path, int $type, ILockingProvider $provider): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function changeLock($path, $type, ILockingProvider $provider): never {
+ public function changeLock(string $path, int $type, ILockingProvider $provider): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function setAvailability($isAvailable): never {
+ public function setAvailability(bool $isAvailable): never {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
- public function getCache($path = '', $storage = null): FailedCache {
+ public function getCache(string $path = '', ?IStorage $storage = null): FailedCache {
return new FailedCache();
}
}
use OC\Files\Cache\HomePropagator;
use OCP\Files\Cache\ICache;
use OCP\Files\Cache\IPropagator;
+use OCP\Files\Storage\IStorage;
use OCP\IUser;
/**
return $this->id;
}
- public function getCache($path = '', $storage = null): ICache {
+ public function getCache(string $path = '', ?IStorage $storage = null): ICache {
if (!$storage) {
$storage = $this;
}
return $this->cache;
}
- public function getPropagator($storage = null): IPropagator {
+ public function getPropagator(?IStorage $storage = null): IPropagator {
if (!$storage) {
$storage = $this;
}
return $this->user;
}
- public function getOwner($path): string|false {
+ public function getOwner(string $path): string|false {
return $this->user->getUID();
}
}
return 'local::' . $this->datadir;
}
- public function mkdir($path): bool {
+ public function mkdir(string $path): bool {
$sourcePath = $this->getSourcePath($path);
$oldMask = umask($this->defUMask);
$result = @mkdir($sourcePath, 0777, true);
return $result;
}
- public function rmdir($path): bool {
+ public function rmdir(string $path): bool {
if (!$this->isDeletable($path)) {
return false;
}
}
}
- public function opendir($path) {
+ public function opendir(string $path) {
return opendir($this->getSourcePath($path));
}
- public function is_dir($path): bool {
+ public function is_dir(string $path): bool {
if ($this->caseInsensitive && !$this->file_exists($path)) {
return false;
}
return is_dir($this->getSourcePath($path));
}
- public function is_file($path): bool {
+ public function is_file(string $path): bool {
if ($this->caseInsensitive && !$this->file_exists($path)) {
return false;
}
return is_file($this->getSourcePath($path));
}
- public function stat($path): array|false {
+ public function stat(string $path): array|false {
$fullPath = $this->getSourcePath($path);
clearstatcache(true, $fullPath);
if (!file_exists($fullPath)) {
return $statResult;
}
- public function getMetaData($path): ?array {
+ public function getMetaData(string $path): ?array {
try {
$stat = $this->stat($path);
} catch (ForbiddenException $e) {
return $data;
}
- public function filetype($path): string|false {
+ public function filetype(string $path): string|false {
$filetype = filetype($this->getSourcePath($path));
if ($filetype == 'link') {
$filetype = filetype(realpath($this->getSourcePath($path)));
return $filetype;
}
- public function filesize($path): int|float|false {
+ public function filesize(string $path): int|float|false {
if (!$this->is_file($path)) {
return 0;
}
return filesize($fullPath);
}
- public function isReadable($path): bool {
+ public function isReadable(string $path): bool {
return is_readable($this->getSourcePath($path));
}
- public function isUpdatable($path): bool {
+ public function isUpdatable(string $path): bool {
return is_writable($this->getSourcePath($path));
}
- public function file_exists($path): bool {
+ public function file_exists(string $path): bool {
if ($this->caseInsensitive) {
$fullPath = $this->getSourcePath($path);
$parentPath = dirname($fullPath);
}
}
- public function filemtime($path): int|false {
+ public function filemtime(string $path): int|false {
$fullPath = $this->getSourcePath($path);
clearstatcache(true, $fullPath);
if (!$this->file_exists($path)) {
return filemtime($fullPath);
}
- public function touch($path, $mtime = null): bool {
+ public function touch(string $path, ?int $mtime = null): bool {
// sets the modification time of the file to the given value.
// If mtime is nil the current time is set.
// note that the access time of the file always changes to the current time.
return $result;
}
- public function file_get_contents($path): string|false {
+ public function file_get_contents(string $path): string|false {
return file_get_contents($this->getSourcePath($path));
}
- public function file_put_contents($path, $data): int|float|false {
+ public function file_put_contents(string $path, mixed $data): int|float|false {
$oldMask = umask($this->defUMask);
if ($this->unlinkOnTruncate) {
$this->unlink($path);
return $result;
}
- public function unlink($path): bool {
+ public function unlink(string $path): bool {
if ($this->is_dir($path)) {
return $this->rmdir($path);
} elseif ($this->is_file($path)) {
}
}
- public function rename($source, $target): bool {
+ public function rename(string $source, string $target): bool {
$srcParent = dirname($source);
$dstParent = dirname($target);
return $this->copy($source, $target) && $this->unlink($source);
}
- public function copy($source, $target): bool {
+ public function copy(string $source, string $target): bool {
if ($this->is_dir($source)) {
return parent::copy($source, $target);
} else {
}
}
- public function fopen($path, $mode) {
+ public function fopen(string $path, string $mode) {
$sourcePath = $this->getSourcePath($path);
if (!file_exists($sourcePath) && $mode === 'r') {
return false;
return $result;
}
- public function hash($type, $path, $raw = false): string|false {
+ public function hash(string $type, string $path, bool $raw = false): string|false {
return hash_file($type, $this->getSourcePath($path), $raw);
}
- public function free_space($path): int|float|false {
+ public function free_space(string $path): int|float|false {
$sourcePath = $this->getSourcePath($path);
// using !is_dir because $sourcePath might be a part file or
// non-existing file, so we'd still want to use the parent dir
return Util::numericToNumber($space);
}
- public function search($query): array {
+ public function search(string $query): array {
return $this->searchInDir($query);
}
- public function getLocalFile($path): string|false {
+ public function getLocalFile(string $path): string|false {
return $this->getSourcePath($path);
}
- /**
- * @param string $query
- * @param string $dir
- */
- protected function searchInDir($query, $dir = ''): array {
+ protected function searchInDir(string $query, string $dir = ''): array {
$files = [];
$physicalDir = $this->getSourcePath($dir);
foreach (scandir($physicalDir) as $item) {
return $files;
}
- public function hasUpdated($path, $time): bool {
+ public function hasUpdated(string $path, int $time): bool {
if ($this->file_exists($path)) {
return $this->filemtime($path) > $time;
} else {
/**
* Get the source path (on disk) of a given path
*
- * @param string $path
* @throws ForbiddenException
*/
- public function getSourcePath($path): string {
+ public function getSourcePath(string $path): string {
if (Filesystem::isFileBlacklisted($path)) {
throw new ForbiddenException('Invalid path: ' . $path, false);
}
return true;
}
- public function getETag($path): string|false {
+ public function getETag(string $path): string|false {
return $this->calculateEtag($path, $this->stat($path));
}
}
private function canDoCrossStorageMove(IStorage $sourceStorage): bool {
- /** @psalm-suppress UndefinedClass */
+ /** @psalm-suppress UndefinedClass,InvalidArgument */
return $sourceStorage->instanceOfStorage(Local::class)
// Don't treat ACLStorageWrapper like local storage where copy can be done directly.
// Instead, use the slower recursive copying in php from Common::copyFromStorage with
&& !$sourceStorage->instanceOfStorage(Encryption::class);
}
- public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false): bool {
+ public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath, bool $preserveMtime = false): bool {
if ($this->canDoCrossStorageMove($sourceStorage)) {
if ($sourceStorage->instanceOfStorage(Jail::class)) {
/**
}
}
- /**
- * @param IStorage $sourceStorage
- * @param string $sourceInternalPath
- * @param string $targetInternalPath
- * @return bool
- */
- public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool {
+ public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool {
if ($this->canDoCrossStorageMove($sourceStorage)) {
if ($sourceStorage->instanceOfStorage(Jail::class)) {
/**
use OC\Files\Cache\LocalRootScanner;
use OCP\Files\Cache\IScanner;
+use OCP\Files\Storage\IStorage;
class LocalRootStorage extends Local {
- public function getScanner($path = '', $storage = null): IScanner {
+ public function getScanner(string $path = '', ?IStorage $storage = null): IScanner {
if (!$storage) {
$storage = $this;
}
return $this->cachedFiles[$path];
}
- /**
- * @param string $path
- */
- protected function removeCachedFile($path): void {
+ protected function removeCachedFile(string $path): void {
unset($this->cachedFiles[$path]);
}
trait CopyDirectory {
/**
* Check if a path is a directory
- *
- * @param string $path
*/
- abstract public function is_dir($path): bool;
+ abstract public function is_dir(string $path): bool;
/**
* Check if a file or folder exists
- *
- * @param string $path
*/
- abstract public function file_exists($path): bool;
+ abstract public function file_exists(string $path): bool;
/**
* Delete a file or folder
- *
- * @param string $path
*/
- abstract public function unlink($path): bool;
+ abstract public function unlink(string $path): bool;
/**
* Open a directory handle for a folder
*
- * @param string $path
* @return resource|false
*/
- abstract public function opendir($path);
+ abstract public function opendir(string $path);
/**
* Create a new folder
- *
- * @param string $path
*/
- abstract public function mkdir($path): bool;
+ abstract public function mkdir(string $path): bool;
- public function copy($source, $target): bool {
+ public function copy(string $source, string $target): bool {
if ($this->is_dir($source)) {
if ($this->file_exists($target)) {
$this->unlink($target);
/**
* For adapters that don't support copying folders natively
*/
- protected function copyRecursive($source, $target): bool {
+ protected function copyRecursive(string $source, string $target): bool {
$dh = $this->opendir($source);
$result = true;
while (($file = readdir($dh)) !== false) {
* All paths passed to the storage are relative to the storage and should NOT have a leading slash.
*/
interface Storage extends IStorage, ILockingStorage {
- /**
- * @param string $path
- * @param ?IStorage $storage
- */
- public function getCache($path = '', $storage = null): ICache;
+ public function getCache(string $path = '', ?IStorage $storage = null): ICache;
- /**
- * @param string $path
- * @param ?IStorage $storage
- */
- public function getScanner($path = '', $storage = null): IScanner;
+ public function getScanner(string $path = '', ?IStorage $storage = null): IScanner;
- /**
- * @param string $path
- * @param ?IStorage $storage
- */
- public function getWatcher($path = '', $storage = null): IWatcher;
+ public function getWatcher(string $path = '', ?IStorage $storage = null): IWatcher;
- /**
- * @param ?IStorage $storage
- */
- public function getPropagator($storage = null): IPropagator;
+ public function getPropagator(?IStorage $storage = null): IPropagator;
- /**
- * @param ?IStorage $storage
- */
- public function getUpdater($storage = null): IUpdater;
+ public function getUpdater(?IStorage $storage = null): IUpdater;
public function getStorageCache(): \OC\Files\Cache\Storage;
- /**
- * @param string $path
- */
- public function getMetaData($path): ?array;
+ public function getMetaData(string $path): ?array;
/**
* Get the contents of a directory with metadata
*
- * @param string $directory
- *
* The metadata array will contain the following fields
*
* - name
* - storage_mtime
* - permissions
*/
- public function getDirectoryContent($directory): \Traversable;
+ public function getDirectoryContent(string $directory): \Traversable;
}
*/
private $storageWrappers = [];
- public function addStorageWrapper($wrapperName, $callback, $priority = 50, $existingMounts = []): bool {
+ public function addStorageWrapper(string $wrapperName, callable $callback, int $priority = 50, array $existingMounts = []): bool {
if (isset($this->storageWrappers[$wrapperName])) {
return false;
}
* Remove a storage wrapper by name.
* Note: internal method only to be used for cleanup
*
- * @param string $wrapperName name of the wrapper
* @internal
*/
- public function removeStorageWrapper($wrapperName): void {
+ public function removeStorageWrapper(string $wrapperName): void {
unset($this->storageWrappers[$wrapperName]);
}
/**
* Create an instance of a storage and apply the registered storage wrappers
- *
- * @param string $class
- * @param array $arguments
- * @return IStorage
*/
- public function getInstance(IMountPoint $mountPoint, $class, $arguments): IStorage {
+ public function getInstance(IMountPoint $mountPoint, string $class, array $arguments): IStorage {
if (!is_a($class, IConstructableStorage::class, true)) {
\OCP\Server::get(LoggerInterface::class)->warning('Building a storage not implementing IConstructableStorage is deprecated since 31.0.0', ['class' => $class]);
}
return $this->wrap($mountPoint, new $class($arguments));
}
- /**
- * @param IStorage $storage
- */
- public function wrap(IMountPoint $mountPoint, $storage): IStorage {
+ public function wrap(IMountPoint $mountPoint, IStorage $storage): IStorage {
$wrappers = array_values($this->storageWrappers);
usort($wrappers, function ($a, $b) {
return $b['priority'] - $a['priority'];
}
}
- public function mkdir($path): bool {
+ public function mkdir(string $path): bool {
$this->checkAvailability();
try {
return parent::mkdir($path);
}
}
- public function rmdir($path): bool {
+ public function rmdir(string $path): bool {
$this->checkAvailability();
try {
return parent::rmdir($path);
}
}
- public function opendir($path) {
+ public function opendir(string $path) {
$this->checkAvailability();
try {
return parent::opendir($path);
}
}
- public function is_dir($path): bool {
+ public function is_dir(string $path): bool {
$this->checkAvailability();
try {
return parent::is_dir($path);
}
}
- public function is_file($path): bool {
+ public function is_file(string $path): bool {
$this->checkAvailability();
try {
return parent::is_file($path);
}
}
- public function stat($path): array|false {
+ public function stat(string $path): array|false {
$this->checkAvailability();
try {
return parent::stat($path);
}
}
- public function filetype($path): string|false {
+ public function filetype(string $path): string|false {
$this->checkAvailability();
try {
return parent::filetype($path);
}
}
- public function filesize($path): int|float|false {
+ public function filesize(string $path): int|float|false {
$this->checkAvailability();
try {
return parent::filesize($path);
}
}
- public function isCreatable($path): bool {
+ public function isCreatable(string $path): bool {
$this->checkAvailability();
try {
return parent::isCreatable($path);
}
}
- public function isReadable($path): bool {
+ public function isReadable(string $path): bool {
$this->checkAvailability();
try {
return parent::isReadable($path);
}
}
- public function isUpdatable($path): bool {
+ public function isUpdatable(string $path): bool {
$this->checkAvailability();
try {
return parent::isUpdatable($path);
}
}
- public function isDeletable($path): bool {
+ public function isDeletable(string $path): bool {
$this->checkAvailability();
try {
return parent::isDeletable($path);
}
}
- public function isSharable($path): bool {
+ public function isSharable(string $path): bool {
$this->checkAvailability();
try {
return parent::isSharable($path);
}
}
- public function getPermissions($path): int {
+ public function getPermissions(string $path): int {
$this->checkAvailability();
try {
return parent::getPermissions($path);
}
}
- public function file_exists($path): bool {
+ public function file_exists(string $path): bool {
if ($path === '') {
return true;
}
}
}
- public function filemtime($path): int|false {
+ public function filemtime(string $path): int|false {
$this->checkAvailability();
try {
return parent::filemtime($path);
}
}
- public function file_get_contents($path): string|false {
+ public function file_get_contents(string $path): string|false {
$this->checkAvailability();
try {
return parent::file_get_contents($path);
}
}
- public function file_put_contents($path, $data): int|float|false {
+ public function file_put_contents(string $path, mixed $data): int|float|false {
$this->checkAvailability();
try {
return parent::file_put_contents($path, $data);
}
}
- public function unlink($path): bool {
+ public function unlink(string $path): bool {
$this->checkAvailability();
try {
return parent::unlink($path);
}
}
- public function rename($source, $target): bool {
+ public function rename(string $source, string $target): bool {
$this->checkAvailability();
try {
return parent::rename($source, $target);
}
}
- public function copy($source, $target): bool {
+ public function copy(string $source, string $target): bool {
$this->checkAvailability();
try {
return parent::copy($source, $target);
}
}
- public function fopen($path, $mode) {
+ public function fopen(string $path, string $mode) {
$this->checkAvailability();
try {
return parent::fopen($path, $mode);
}
}
- public function getMimeType($path): string|false {
+ public function getMimeType(string $path): string|false {
$this->checkAvailability();
try {
return parent::getMimeType($path);
}
}
- public function hash($type, $path, $raw = false): string|false {
+ public function hash(string $type, string $path, bool $raw = false): string|false {
$this->checkAvailability();
try {
return parent::hash($type, $path, $raw);
}
}
- public function free_space($path): int|float|false {
+ public function free_space(string $path): int|float|false {
$this->checkAvailability();
try {
return parent::free_space($path);
}
}
- public function touch($path, $mtime = null): bool {
+ public function touch(string $path, ?int $mtime = null): bool {
$this->checkAvailability();
try {
return parent::touch($path, $mtime);
}
}
- public function getLocalFile($path): string|false {
+ public function getLocalFile(string $path): string|false {
$this->checkAvailability();
try {
return parent::getLocalFile($path);
}
}
- public function hasUpdated($path, $time): bool {
+ public function hasUpdated(string $path, int $time): bool {
if (!$this->isAvailable()) {
return false;
}
}
}
- public function getOwner($path): string|false {
+ public function getOwner(string $path): string|false {
try {
return parent::getOwner($path);
} catch (StorageNotAvailableException $e) {
}
}
- public function getETag($path): string|false {
+ public function getETag(string $path): string|false {
$this->checkAvailability();
try {
return parent::getETag($path);
}
}
- public function getDirectDownload($path): array|false {
+ public function getDirectDownload(string $path): array|false {
$this->checkAvailability();
try {
return parent::getDirectDownload($path);
}
}
- public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool {
+ public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool {
$this->checkAvailability();
try {
return parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
}
}
- public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool {
+ public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool {
$this->checkAvailability();
try {
return parent::moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
}
}
- public function getMetaData($path): ?array {
+ public function getMetaData(string $path): ?array {
$this->checkAvailability();
try {
return parent::getMetaData($path);
- public function getDirectoryContent($directory): \Traversable {
+ public function getDirectoryContent(string $directory): \Traversable {
$this->checkAvailability();
try {
return parent::getDirectoryContent($directory);
/**
* Returns whether the given string is only made of ASCII characters
- *
- * @param string $str string
*/
- private function isAscii($str): bool {
+ private function isAscii(string $str): bool {
return !preg_match('/[\\x80-\\xff]+/', $str);
}
* each form for each path section and returns the correct form.
* If no existing path found, returns the path as it was given.
*
- * @param string $fullPath path to check
- *
* @return string original or converted path
*/
- private function findPathToUse($fullPath): string {
+ private function findPathToUse(string $fullPath): string {
$cachedPath = $this->namesCache[$fullPath];
if ($cachedPath !== null) {
return $cachedPath;
* Checks whether the last path section of the given path exists in NFC or NFD form
* and returns the correct form. If no existing path found, returns null.
*
- * @param string $basePath base path to check
* @param string $lastSection last section of the path to check for NFD/NFC variations
*
* @return string|null original or converted path, or null if none of the forms was found
*/
- private function findPathToUseLastSection($basePath, $lastSection): ?string {
+ private function findPathToUseLastSection(string $basePath, string $lastSection): ?string {
$fullPath = $basePath . $lastSection;
if ($lastSection === '' || $this->isAscii($lastSection) || $this->storage->file_exists($fullPath)) {
$this->namesCache[$fullPath] = $fullPath;
return null;
}
- public function mkdir($path): bool {
+ public function mkdir(string $path): bool {
// note: no conversion here, method should not be called with non-NFC names!
$result = $this->storage->mkdir($path);
if ($result) {
return $result;
}
- public function rmdir($path): bool {
+ public function rmdir(string $path): bool {
$result = $this->storage->rmdir($this->findPathToUse($path));
if ($result) {
unset($this->namesCache[$path]);
return $result;
}
- public function opendir($path) {
+ public function opendir(string $path) {
$handle = $this->storage->opendir($this->findPathToUse($path));
return EncodingDirectoryWrapper::wrap($handle);
}
- public function is_dir($path): bool {
+ public function is_dir(string $path): bool {
return $this->storage->is_dir($this->findPathToUse($path));
}
- public function is_file($path): bool {
+ public function is_file(string $path): bool {
return $this->storage->is_file($this->findPathToUse($path));
}
- public function stat($path): array|false {
+ public function stat(string $path): array|false {
return $this->storage->stat($this->findPathToUse($path));
}
- public function filetype($path): string|false {
+ public function filetype(string $path): string|false {
return $this->storage->filetype($this->findPathToUse($path));
}
- public function filesize($path): int|float|false {
+ public function filesize(string $path): int|float|false {
return $this->storage->filesize($this->findPathToUse($path));
}
- public function isCreatable($path): bool {
+ public function isCreatable(string $path): bool {
return $this->storage->isCreatable($this->findPathToUse($path));
}
- public function isReadable($path): bool {
+ public function isReadable(string $path): bool {
return $this->storage->isReadable($this->findPathToUse($path));
}
- public function isUpdatable($path): bool {
+ public function isUpdatable(string $path): bool {
return $this->storage->isUpdatable($this->findPathToUse($path));
}
- public function isDeletable($path): bool {
+ public function isDeletable(string $path): bool {
return $this->storage->isDeletable($this->findPathToUse($path));
}
- public function isSharable($path): bool {
+ public function isSharable(string $path): bool {
return $this->storage->isSharable($this->findPathToUse($path));
}
- public function getPermissions($path): int {
+ public function getPermissions(string $path): int {
return $this->storage->getPermissions($this->findPathToUse($path));
}
- public function file_exists($path): bool {
+ public function file_exists(string $path): bool {
return $this->storage->file_exists($this->findPathToUse($path));
}
- public function filemtime($path): int|false {
+ public function filemtime(string $path): int|false {
return $this->storage->filemtime($this->findPathToUse($path));
}
- public function file_get_contents($path): string|false {
+ public function file_get_contents(string $path): string|false {
return $this->storage->file_get_contents($this->findPathToUse($path));
}
- public function file_put_contents($path, $data): int|float|false {
+ public function file_put_contents(string $path, mixed $data): int|float|false {
return $this->storage->file_put_contents($this->findPathToUse($path), $data);
}
- public function unlink($path): bool {
+ public function unlink(string $path): bool {
$result = $this->storage->unlink($this->findPathToUse($path));
if ($result) {
unset($this->namesCache[$path]);
return $result;
}
- public function rename($source, $target): bool {
+ public function rename(string $source, string $target): bool {
// second name always NFC
return $this->storage->rename($this->findPathToUse($source), $this->findPathToUse($target));
}
- public function copy($source, $target): bool {
+ public function copy(string $source, string $target): bool {
return $this->storage->copy($this->findPathToUse($source), $this->findPathToUse($target));
}
- public function fopen($path, $mode) {
+ public function fopen(string $path, string $mode) {
$result = $this->storage->fopen($this->findPathToUse($path), $mode);
if ($result && $mode !== 'r' && $mode !== 'rb') {
unset($this->namesCache[$path]);
return $result;
}
- public function getMimeType($path): string|false {
+ public function getMimeType(string $path): string|false {
return $this->storage->getMimeType($this->findPathToUse($path));
}
- public function hash($type, $path, $raw = false): string|false {
+ public function hash(string $type, string $path, bool $raw = false): string|false {
return $this->storage->hash($type, $this->findPathToUse($path), $raw);
}
- public function free_space($path): int|float|false {
+ public function free_space(string $path): int|float|false {
return $this->storage->free_space($this->findPathToUse($path));
}
- public function touch($path, $mtime = null): bool {
+ public function touch(string $path, ?int $mtime = null): bool {
return $this->storage->touch($this->findPathToUse($path), $mtime);
}
- public function getLocalFile($path): string|false {
+ public function getLocalFile(string $path): string|false {
return $this->storage->getLocalFile($this->findPathToUse($path));
}
- public function hasUpdated($path, $time): bool {
+ public function hasUpdated(string $path, int $time): bool {
return $this->storage->hasUpdated($this->findPathToUse($path), $time);
}
- public function getCache($path = '', $storage = null): \OCP\Files\Cache\ICache {
+ public function getCache(string $path = '', ?IStorage $storage = null): \OCP\Files\Cache\ICache {
if (!$storage) {
$storage = $this;
}
return $this->storage->getCache($this->findPathToUse($path), $storage);
}
- public function getScanner($path = '', $storage = null): IScanner {
+ public function getScanner(string $path = '', ?IStorage $storage = null): IScanner {
if (!$storage) {
$storage = $this;
}
return $this->storage->getScanner($this->findPathToUse($path), $storage);
}
- public function getETag($path): string|false {
+ public function getETag(string $path): string|false {
return $this->storage->getETag($this->findPathToUse($path));
}
- public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool {
+ public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool {
if ($sourceStorage === $this) {
return $this->copy($sourceInternalPath, $this->findPathToUse($targetInternalPath));
}
return $result;
}
- public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool {
+ public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool {
if ($sourceStorage === $this) {
$result = $this->rename($sourceInternalPath, $this->findPathToUse($targetInternalPath));
if ($result) {
return $result;
}
- public function getMetaData($path): ?array {
+ public function getMetaData(string $path): ?array {
$entry = $this->storage->getMetaData($this->findPathToUse($path));
$entry['name'] = trim(Filesystem::normalizePath($entry['name']), '/');
return $entry;
}
- public function getDirectoryContent($directory): \Traversable {
+ public function getDirectoryContent(string $directory): \Traversable {
$entries = $this->storage->getDirectoryContent($this->findPathToUse($directory));
foreach ($entries as $entry) {
$entry['name'] = trim(Filesystem::normalizePath($entry['name']), '/');
parent::__construct($parameters);
}
- public function filesize($path): int|float|false {
+ public function filesize(string $path): int|float|false {
$fullPath = $this->getFullPath($path);
$info = $this->getCache()->get($path);
return $this->storage->filesize($path);
}
- /**
- * @param string $path
- * @param array $data
- * @return array
- */
private function modifyMetaData(string $path, array $data): array {
$fullPath = $this->getFullPath($path);
$info = $this->getCache()->get($path);
return $data;
}
- public function getMetaData($path): ?array {
+ public function getMetaData(string $path): ?array {
$data = $this->storage->getMetaData($path);
if (is_null($data)) {
return null;
return $this->modifyMetaData($path, $data);
}
- public function getDirectoryContent($directory): \Traversable {
+ public function getDirectoryContent(string $directory): \Traversable {
$parent = rtrim($directory, '/');
foreach ($this->getWrapperStorage()->getDirectoryContent($directory) as $data) {
yield $this->modifyMetaData($parent . '/' . $data['name'], $data);
}
}
- public function file_get_contents($path): string|false {
+ public function file_get_contents(string $path): string|false {
$encryptionModule = $this->getEncryptionModule($path);
if ($encryptionModule) {
return $this->storage->file_get_contents($path);
}
- public function file_put_contents($path, $data): int|float|false {
+ public function file_put_contents(string $path, mixed $data): int|float|false {
// file put content will always be translated to a stream write
$handle = $this->fopen($path, 'w');
if (is_resource($handle)) {
return false;
}
- public function unlink($path): bool {
+ public function unlink(string $path): bool {
$fullPath = $this->getFullPath($path);
if ($this->util->isExcluded($fullPath)) {
return $this->storage->unlink($path);
return $this->storage->unlink($path);
}
- public function rename($source, $target): bool {
+ public function rename(string $source, string $target): bool {
$result = $this->storage->rename($source, $target);
if ($result &&
return $result;
}
- public function rmdir($path): bool {
+ public function rmdir(string $path): bool {
$result = $this->storage->rmdir($path);
$fullPath = $this->getFullPath($path);
if ($result &&
return $result;
}
- public function isReadable($path): bool {
+ public function isReadable(string $path): bool {
$isReadable = true;
$metaData = $this->getMetaData($path);
return $this->storage->isReadable($path) && $isReadable;
}
- public function copy($source, $target): bool {
+ public function copy(string $source, string $target): bool {
$sourcePath = $this->getFullPath($source);
if ($this->util->isExcluded($sourcePath)) {
return $this->copyFromStorage($this, $source, $target);
}
- public function fopen($path, $mode) {
+ public function fopen(string $path, string $mode) {
// check if the file is stored in the array cache, this means that we
// copy a file over to the versions folder, in this case we don't want to
// decrypt it
* This is required as stream_read only returns smaller chunks of data when the stream fetches from a
* remote storage over the internet and it does not care about the given $blockSize.
*
- * @param handle the stream to read from
+ * @param resource $handle the stream to read from
* @param int $blockSize Length of requested data block in bytes
* @return string Data fetched from stream.
*/
public function moveFromStorage(
Storage\IStorage $sourceStorage,
- $sourceInternalPath,
- $targetInternalPath,
+ string $sourceInternalPath,
+ string $targetInternalPath,
$preserveMtime = true,
): bool {
if ($sourceStorage === $this) {
public function copyFromStorage(
Storage\IStorage $sourceStorage,
- $sourceInternalPath,
- $targetInternalPath,
+ string $sourceInternalPath,
+ string $targetInternalPath,
$preserveMtime = false,
$isRename = false,
): bool {
/**
* Update the encrypted cache version in the database
- *
- * @param Storage\IStorage $sourceStorage
- * @param string $sourceInternalPath
- * @param string $targetInternalPath
- * @param bool $isRename
- * @param bool $keepEncryptionVersion
*/
private function updateEncryptedVersion(
Storage\IStorage $sourceStorage,
- $sourceInternalPath,
- $targetInternalPath,
- $isRename,
- $keepEncryptionVersion,
+ string $sourceInternalPath,
+ string $targetInternalPath,
+ bool $isRename,
+ bool $keepEncryptionVersion,
): void {
$isEncrypted = $this->encryptionManager->isEnabled() && $this->shouldEncrypt($targetInternalPath);
$cacheInformation = [
/**
* copy file between two storages
- *
- * @param Storage\IStorage $sourceStorage
- * @param string $sourceInternalPath
- * @param string $targetInternalPath
- * @param bool $preserveMtime
- * @param bool $isRename
- * @return bool
* @throws \Exception
*/
private function copyBetweenStorage(
Storage\IStorage $sourceStorage,
- $sourceInternalPath,
- $targetInternalPath,
- $preserveMtime,
- $isRename,
+ string $sourceInternalPath,
+ string $targetInternalPath,
+ bool $preserveMtime,
+ bool $isRename,
): bool {
// for versions we have nothing to do, because versions should always use the
// key from the original file. Just create a 1:1 copy and done
return (bool)$result;
}
- public function getLocalFile($path): string|false {
+ public function getLocalFile(string $path): string|false {
if ($this->encryptionManager->isEnabled()) {
$cachedFile = $this->getCachedFile($path);
if (is_string($cachedFile)) {
return $this->storage->isLocal();
}
- public function stat($path): array|false {
+ public function stat(string $path): array|false {
$stat = $this->storage->stat($path);
if (!$stat) {
return false;
return $stat;
}
- public function hash($type, $path, $raw = false): string|false {
+ public function hash(string $type, string $path, bool $raw = false): string|false {
$fh = $this->fopen($path, 'rb');
$ctx = hash_init($type);
hash_update_stream($ctx, $fh);
* @param string $path relative to mount point
* @return string full path including mount point
*/
- protected function getFullPath($path): string {
+ protected function getFullPath(string $path): string {
return Filesystem::normalizePath($this->mountPoint . '/' . $path);
}
/**
* read first block of encrypted file, typically this will contain the
* encryption header
- *
- * @param string $path
- * @return string
*/
- protected function readFirstBlock($path): string {
+ protected function readFirstBlock(string $path): string {
$firstBlock = '';
if ($this->storage->is_file($path)) {
$handle = $this->storage->fopen($path, 'r');
/**
* return header size of given file
- *
- * @param string $path
- * @return int
*/
- protected function getHeaderSize($path): int {
+ protected function getHeaderSize(string $path): int {
$headerSize = 0;
$realFile = $this->util->stripPartialFileExtension($path);
if ($this->storage->is_file($realFile)) {
/**
* read header from file
- *
- * @param string $path
- * @return array
*/
- protected function getHeader($path): array {
+ protected function getHeader(string $path): array {
$realFile = $this->util->stripPartialFileExtension($path);
$exists = $this->storage->is_file($realFile);
if ($exists) {
/**
* read encryption module needed to read/write the file located at $path
*
- * @param string $path
- * @return null|\OCP\Encryption\IEncryptionModule
* @throws ModuleDoesNotExistsException
* @throws \Exception
*/
- protected function getEncryptionModule($path): ?\OCP\Encryption\IEncryptionModule {
+ protected function getEncryptionModule(string $path): ?\OCP\Encryption\IEncryptionModule {
$encryptionModule = null;
$header = $this->getHeader($path);
$encryptionModuleId = $this->util->getEncryptionModuleId($header);
return $encryptionModule;
}
- /**
- * @param string $path
- * @param int $unencryptedSize
- */
- public function updateUnencryptedSize($path, $unencryptedSize): void {
+ public function updateUnencryptedSize(string $path, int|float $unencryptedSize): void {
$this->unencryptedSize[$path] = $unencryptedSize;
}
*
* @param string $source path relative to data/
* @param string $target path relative to data/
- * @return bool
*/
- protected function copyKeys($source, $target): bool {
+ protected function copyKeys(string $source, string $target): bool {
if (!$this->util->isExcluded($source)) {
return $this->keyStorage->copyKeys($source, $target);
}
/**
* check if path points to a files version
- *
- * @param $path
- * @return bool
*/
- protected function isVersion($path): bool {
+ protected function isVersion(string $path): bool {
$normalized = Filesystem::normalizePath($path);
return substr($normalized, 0, strlen('/files_versions/')) === '/files_versions/';
}
/**
* check if the given storage should be encrypted or not
- *
- * @param $path
- * @return bool
*/
- protected function shouldEncrypt($path): bool {
+ protected function shouldEncrypt(string $path): bool {
$fullPath = $this->getFullPath($path);
$mountPointConfig = $this->mount->getOption('encrypt', true);
if ($mountPointConfig === false) {
/**
* Allow temporarily disabling the wrapper
- *
- * @param bool $enabled
- * @return void
*/
public function setEnabled(bool $enabled): void {
$this->enabled = $enabled;
$this->rootPath = $arguments['root'];
}
- public function getUnjailedPath($path): string {
+ public function getUnjailedPath(string $path): string {
return trim(Filesystem::normalizePath($this->rootPath . '/' . $path), '/');
}
}
- public function getJailedPath($path): ?string {
+ public function getJailedPath(string $path): ?string {
$root = rtrim($this->rootPath, '/') . '/';
if ($path !== $this->rootPath && !str_starts_with($path, $root)) {
return parent::getId();
}
- public function mkdir($path): bool {
+ public function mkdir(string $path): bool {
return $this->getWrapperStorage()->mkdir($this->getUnjailedPath($path));
}
- public function rmdir($path): bool {
+ public function rmdir(string $path): bool {
return $this->getWrapperStorage()->rmdir($this->getUnjailedPath($path));
}
- public function opendir($path) {
+ public function opendir(string $path) {
return $this->getWrapperStorage()->opendir($this->getUnjailedPath($path));
}
- public function is_dir($path): bool {
+ public function is_dir(string $path): bool {
return $this->getWrapperStorage()->is_dir($this->getUnjailedPath($path));
}
- public function is_file($path): bool {
+ public function is_file(string $path): bool {
return $this->getWrapperStorage()->is_file($this->getUnjailedPath($path));
}
- public function stat($path): array|false {
+ public function stat(string $path): array|false {
return $this->getWrapperStorage()->stat($this->getUnjailedPath($path));
}
- public function filetype($path): string|false {
+ public function filetype(string $path): string|false {
return $this->getWrapperStorage()->filetype($this->getUnjailedPath($path));
}
- public function filesize($path): int|float|false {
+ public function filesize(string $path): int|float|false {
return $this->getWrapperStorage()->filesize($this->getUnjailedPath($path));
}
- public function isCreatable($path): bool {
+ public function isCreatable(string $path): bool {
return $this->getWrapperStorage()->isCreatable($this->getUnjailedPath($path));
}
- public function isReadable($path): bool {
+ public function isReadable(string $path): bool {
return $this->getWrapperStorage()->isReadable($this->getUnjailedPath($path));
}
- public function isUpdatable($path): bool {
+ public function isUpdatable(string $path): bool {
return $this->getWrapperStorage()->isUpdatable($this->getUnjailedPath($path));
}
- public function isDeletable($path): bool {
+ public function isDeletable(string $path): bool {
return $this->getWrapperStorage()->isDeletable($this->getUnjailedPath($path));
}
- public function isSharable($path): bool {
+ public function isSharable(string $path): bool {
return $this->getWrapperStorage()->isSharable($this->getUnjailedPath($path));
}
- public function getPermissions($path): int {
+ public function getPermissions(string $path): int {
return $this->getWrapperStorage()->getPermissions($this->getUnjailedPath($path));
}
- public function file_exists($path): bool {
+ public function file_exists(string $path): bool {
return $this->getWrapperStorage()->file_exists($this->getUnjailedPath($path));
}
- public function filemtime($path): int|false {
+ public function filemtime(string $path): int|false {
return $this->getWrapperStorage()->filemtime($this->getUnjailedPath($path));
}
- public function file_get_contents($path): string|false {
+ public function file_get_contents(string $path): string|false {
return $this->getWrapperStorage()->file_get_contents($this->getUnjailedPath($path));
}
- public function file_put_contents($path, $data): int|float|false {
+ public function file_put_contents(string $path, mixed $data): int|float|false {
return $this->getWrapperStorage()->file_put_contents($this->getUnjailedPath($path), $data);
}
- public function unlink($path): bool {
+ public function unlink(string $path): bool {
return $this->getWrapperStorage()->unlink($this->getUnjailedPath($path));
}
- public function rename($source, $target): bool {
+ public function rename(string $source, string $target): bool {
return $this->getWrapperStorage()->rename($this->getUnjailedPath($source), $this->getUnjailedPath($target));
}
- public function copy($source, $target): bool {
+ public function copy(string $source, string $target): bool {
return $this->getWrapperStorage()->copy($this->getUnjailedPath($source), $this->getUnjailedPath($target));
}
- public function fopen($path, $mode) {
+ public function fopen(string $path, string $mode) {
return $this->getWrapperStorage()->fopen($this->getUnjailedPath($path), $mode);
}
- public function getMimeType($path): string|false {
+ public function getMimeType(string $path): string|false {
return $this->getWrapperStorage()->getMimeType($this->getUnjailedPath($path));
}
- public function hash($type, $path, $raw = false): string|false {
+ public function hash(string $type, string $path, bool $raw = false): string|false {
return $this->getWrapperStorage()->hash($type, $this->getUnjailedPath($path), $raw);
}
- public function free_space($path): int|float|false {
+ public function free_space(string $path): int|float|false {
return $this->getWrapperStorage()->free_space($this->getUnjailedPath($path));
}
- public function touch($path, $mtime = null): bool {
+ public function touch(string $path, ?int $mtime = null): bool {
return $this->getWrapperStorage()->touch($this->getUnjailedPath($path), $mtime);
}
- public function getLocalFile($path): string|false {
+ public function getLocalFile(string $path): string|false {
return $this->getWrapperStorage()->getLocalFile($this->getUnjailedPath($path));
}
- public function hasUpdated($path, $time): bool {
+ public function hasUpdated(string $path, int $time): bool {
return $this->getWrapperStorage()->hasUpdated($this->getUnjailedPath($path), $time);
}
- public function getCache($path = '', $storage = null): ICache {
+ public function getCache(string $path = '', ?IStorage $storage = null): ICache {
$sourceCache = $this->getWrapperStorage()->getCache($this->getUnjailedPath($path));
return new CacheJail($sourceCache, $this->rootPath);
}
- public function getOwner($path): string|false {
+ public function getOwner(string $path): string|false {
return $this->getWrapperStorage()->getOwner($this->getUnjailedPath($path));
}
- public function getWatcher($path = '', $storage = null): IWatcher {
+ public function getWatcher(string $path = '', ?IStorage $storage = null): IWatcher {
$sourceWatcher = $this->getWrapperStorage()->getWatcher($this->getUnjailedPath($path), $this->getWrapperStorage());
return new JailWatcher($sourceWatcher, $this->rootPath);
}
- public function getETag($path): string|false {
+ public function getETag(string $path): string|false {
return $this->getWrapperStorage()->getETag($this->getUnjailedPath($path));
}
- public function getMetaData($path): ?array {
+ public function getMetaData(string $path): ?array {
return $this->getWrapperStorage()->getMetaData($this->getUnjailedPath($path));
}
- public function acquireLock($path, $type, ILockingProvider $provider): void {
+ public function acquireLock(string $path, int $type, ILockingProvider $provider): void {
$this->getWrapperStorage()->acquireLock($this->getUnjailedPath($path), $type, $provider);
}
- public function releaseLock($path, $type, ILockingProvider $provider): void {
+ public function releaseLock(string $path, int $type, ILockingProvider $provider): void {
$this->getWrapperStorage()->releaseLock($this->getUnjailedPath($path), $type, $provider);
}
- public function changeLock($path, $type, ILockingProvider $provider): void {
+ public function changeLock(string $path, int $type, ILockingProvider $provider): void {
$this->getWrapperStorage()->changeLock($this->getUnjailedPath($path), $type, $provider);
}
/**
* Resolve the path for the source of the share
- *
- * @param string $path
*/
- public function resolvePath($path): array {
+ public function resolvePath(string $path): array {
return [$this->getWrapperStorage(), $this->getUnjailedPath($path)];
}
- public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool {
+ public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool {
if ($sourceStorage === $this) {
return $this->copy($sourceInternalPath, $targetInternalPath);
}
return $this->getWrapperStorage()->copyFromStorage($sourceStorage, $sourceInternalPath, $this->getUnjailedPath($targetInternalPath));
}
- public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool {
+ public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool {
if ($sourceStorage === $this) {
return $this->rename($sourceInternalPath, $targetInternalPath);
}
return $this->getWrapperStorage()->moveFromStorage($sourceStorage, $sourceInternalPath, $this->getUnjailedPath($targetInternalPath));
}
- public function getPropagator($storage = null): IPropagator {
+ public function getPropagator(?IStorage $storage = null): IPropagator {
if (isset($this->propagator)) {
return $this->propagator;
}
}
}
- public function getDirectoryContent($directory): \Traversable {
+ public function getDirectoryContent(string $directory): \Traversable {
return $this->getWrapperStorage()->getDirectoryContent($this->getUnjailedPath($directory));
}
}
$this->clock = $arguments['clock'];
}
- public function file_put_contents($path, $data): int|float|false {
+ public function file_put_contents(string $path, mixed $data): int|float|false {
$result = parent::file_put_contents($path, $data);
if ($result) {
$now = $this->clock->now()->getTimestamp();
return $result;
}
- public function stat($path): array|false {
+ public function stat(string $path): array|false {
$stat = parent::stat($path);
if ($stat) {
$this->applyKnownMtime($path, $stat);
return $stat;
}
- public function getMetaData($path): ?array {
+ public function getMetaData(string $path): ?array {
$stat = parent::getMetaData($path);
if ($stat) {
$this->applyKnownMtime($path, $stat);
}
}
- public function filemtime($path): int|false {
+ public function filemtime(string $path): int|false {
$knownMtime = $this->knowMtimes->get($path) ?? 0;
return max(parent::filemtime($path), $knownMtime);
}
- public function mkdir($path): bool {
+ public function mkdir(string $path): bool {
$result = parent::mkdir($path);
if ($result) {
$this->knowMtimes->set($path, $this->clock->now()->getTimestamp());
return $result;
}
- public function rmdir($path): bool {
+ public function rmdir(string $path): bool {
$result = parent::rmdir($path);
if ($result) {
$this->knowMtimes->set($path, $this->clock->now()->getTimestamp());
return $result;
}
- public function unlink($path): bool {
+ public function unlink(string $path): bool {
$result = parent::unlink($path);
if ($result) {
$this->knowMtimes->set($path, $this->clock->now()->getTimestamp());
return $result;
}
- public function rename($source, $target): bool {
+ public function rename(string $source, string $target): bool {
$result = parent::rename($source, $target);
if ($result) {
$this->knowMtimes->set($target, $this->clock->now()->getTimestamp());
return $result;
}
- public function copy($source, $target): bool {
+ public function copy(string $source, string $target): bool {
$result = parent::copy($source, $target);
if ($result) {
$this->knowMtimes->set($target, $this->clock->now()->getTimestamp());
return $result;
}
- public function fopen($path, $mode) {
+ public function fopen(string $path, string $mode) {
$result = parent::fopen($path, $mode);
if ($result && $mode === 'w') {
$this->knowMtimes->set($path, $this->clock->now()->getTimestamp());
return $result;
}
- public function touch($path, $mtime = null): bool {
+ public function touch(string $path, ?int $mtime = null): bool {
$result = parent::touch($path, $mtime);
if ($result) {
$this->knowMtimes->set($path, $mtime ?? $this->clock->now()->getTimestamp());
return $result;
}
- public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool {
+ public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool {
$result = parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
if ($result) {
$this->knowMtimes->set($targetInternalPath, $this->clock->now()->getTimestamp());
return $result;
}
- public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool {
+ public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool {
$result = parent::moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
if ($result) {
$this->knowMtimes->set($targetInternalPath, $this->clock->now()->getTimestamp());
use OC\Files\Cache\Wrapper\CachePermissionsMask;
use OCP\Constants;
+use OCP\Files\Storage\IStorage;
/**
* Mask the permissions of a storage
$this->mask = $arguments['mask'];
}
- private function checkMask($permissions): bool {
+ private function checkMask(int $permissions): bool {
return ($this->mask & $permissions) === $permissions;
}
- public function isUpdatable($path): bool {
+ public function isUpdatable(string $path): bool {
return $this->checkMask(Constants::PERMISSION_UPDATE) and parent::isUpdatable($path);
}
- public function isCreatable($path): bool {
+ public function isCreatable(string $path): bool {
return $this->checkMask(Constants::PERMISSION_CREATE) and parent::isCreatable($path);
}
- public function isDeletable($path): bool {
+ public function isDeletable(string $path): bool {
return $this->checkMask(Constants::PERMISSION_DELETE) and parent::isDeletable($path);
}
- public function isSharable($path): bool {
+ public function isSharable(string $path): bool {
return $this->checkMask(Constants::PERMISSION_SHARE) and parent::isSharable($path);
}
- public function getPermissions($path): int {
+ public function getPermissions(string $path): int {
return $this->storage->getPermissions($path) & $this->mask;
}
- public function rename($source, $target): bool {
+ public function rename(string $source, string $target): bool {
//This is a rename of the transfer file to the original file
if (dirname($source) === dirname($target) && strpos($source, '.ocTransferId') > 0) {
return $this->checkMask(Constants::PERMISSION_CREATE) and parent::rename($source, $target);
return $this->checkMask(Constants::PERMISSION_UPDATE) and parent::rename($source, $target);
}
- public function copy($source, $target): bool {
+ public function copy(string $source, string $target): bool {
return $this->checkMask(Constants::PERMISSION_CREATE) and parent::copy($source, $target);
}
- public function touch($path, $mtime = null): bool {
+ public function touch(string $path, ?int $mtime = null): bool {
$permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE;
return $this->checkMask($permissions) and parent::touch($path, $mtime);
}
- public function mkdir($path): bool {
+ public function mkdir(string $path): bool {
return $this->checkMask(Constants::PERMISSION_CREATE) and parent::mkdir($path);
}
- public function rmdir($path): bool {
+ public function rmdir(string $path): bool {
return $this->checkMask(Constants::PERMISSION_DELETE) and parent::rmdir($path);
}
- public function unlink($path): bool {
+ public function unlink(string $path): bool {
return $this->checkMask(Constants::PERMISSION_DELETE) and parent::unlink($path);
}
- public function file_put_contents($path, $data): int|float|false {
+ public function file_put_contents(string $path, mixed $data): int|float|false {
$permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE;
return $this->checkMask($permissions) ? parent::file_put_contents($path, $data) : false;
}
- public function fopen($path, $mode) {
+ public function fopen(string $path, string $mode) {
if ($mode === 'r' or $mode === 'rb') {
return parent::fopen($path, $mode);
} else {
}
}
- public function getCache($path = '', $storage = null): \OCP\Files\Cache\ICache {
+ public function getCache(string $path = '', ?IStorage $storage = null): \OCP\Files\Cache\ICache {
if (!$storage) {
$storage = $this;
}
return new CachePermissionsMask($sourceCache, $this->mask);
}
- public function getMetaData($path): ?array {
+ public function getMetaData(string $path): ?array {
$data = parent::getMetaData($path);
if ($data && isset($data['permissions'])) {
return $data;
}
- public function getScanner($path = '', $storage = null): \OCP\Files\Cache\IScanner {
+ public function getScanner(string $path = '', ?IStorage $storage = null): \OCP\Files\Cache\IScanner {
if (!$storage) {
$storage = $this->storage;
}
return parent::getScanner($path, $storage);
}
- public function getDirectoryContent($directory): \Traversable {
+ public function getDirectoryContent(string $directory): \Traversable {
foreach ($this->getWrapperStorage()->getDirectoryContent($directory) as $data) {
$data['scan_permissions'] = $data['scan_permissions'] ?? $data['permissions'];
$data['permissions'] &= $this->mask;
return $this->getQuota() !== FileInfo::SPACE_UNLIMITED;
}
- /**
- * @param string $path
- * @param IStorage $storage
- */
- protected function getSize($path, $storage = null): int|float {
+ protected function getSize(string $path, ?IStorage $storage = null): int|float {
if ($this->quotaIncludeExternalStorage) {
$rootInfo = Filesystem::getFileInfo('', 'ext');
if ($rootInfo) {
}
}
- public function free_space($path): int|float|false {
+ public function free_space(string $path): int|float|false {
if (!$this->hasQuota()) {
return $this->storage->free_space($path);
}
}
}
- public function file_put_contents($path, $data): int|float|false {
+ public function file_put_contents(string $path, mixed $data): int|float|false {
if (!$this->hasQuota()) {
return $this->storage->file_put_contents($path, $data);
}
}
}
- public function copy($source, $target): bool {
+ public function copy(string $source, string $target): bool {
if (!$this->hasQuota()) {
return $this->storage->copy($source, $target);
}
}
}
- public function fopen($path, $mode) {
+ public function fopen(string $path, string $mode) {
if (!$this->hasQuota()) {
return $this->storage->fopen($path, $mode);
}
* @param string $path Path that may identify a .part file
* @note this is needed for reusing keys
*/
- private function isPartFile($path): bool {
+ private function isPartFile(string $path): bool {
$extension = pathinfo($path, PATHINFO_EXTENSION);
return ($extension === 'part');
return str_starts_with(ltrim($path, '/'), 'files/');
}
- public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool {
+ public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool {
if (!$this->hasQuota()) {
return $this->storage->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
}
}
}
- public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool {
+ public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool {
if (!$this->hasQuota()) {
return $this->storage->moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
}
}
}
- public function mkdir($path): bool {
+ public function mkdir(string $path): bool {
if (!$this->hasQuota()) {
return $this->storage->mkdir($path);
}
return parent::mkdir($path);
}
- public function touch($path, $mtime = null): bool {
+ public function touch(string $path, ?int $mtime = null): bool {
if (!$this->hasQuota()) {
return $this->storage->touch($path, $mtime);
}
return $this->getWrapperStorage()->getId();
}
- public function mkdir($path): bool {
+ public function mkdir(string $path): bool {
return $this->getWrapperStorage()->mkdir($path);
}
- public function rmdir($path): bool {
+ public function rmdir(string $path): bool {
return $this->getWrapperStorage()->rmdir($path);
}
- public function opendir($path) {
+ public function opendir(string $path) {
return $this->getWrapperStorage()->opendir($path);
}
- public function is_dir($path): bool {
+ public function is_dir(string $path): bool {
return $this->getWrapperStorage()->is_dir($path);
}
- public function is_file($path): bool {
+ public function is_file(string $path): bool {
return $this->getWrapperStorage()->is_file($path);
}
- public function stat($path): array|false {
+ public function stat(string $path): array|false {
return $this->getWrapperStorage()->stat($path);
}
- public function filetype($path): string|false {
+ public function filetype(string $path): string|false {
return $this->getWrapperStorage()->filetype($path);
}
- public function filesize($path): int|float|false {
+ public function filesize(string $path): int|float|false {
return $this->getWrapperStorage()->filesize($path);
}
- public function isCreatable($path): bool {
+ public function isCreatable(string $path): bool {
return $this->getWrapperStorage()->isCreatable($path);
}
- public function isReadable($path): bool {
+ public function isReadable(string $path): bool {
return $this->getWrapperStorage()->isReadable($path);
}
- public function isUpdatable($path): bool {
+ public function isUpdatable(string $path): bool {
return $this->getWrapperStorage()->isUpdatable($path);
}
- public function isDeletable($path): bool {
+ public function isDeletable(string $path): bool {
return $this->getWrapperStorage()->isDeletable($path);
}
- public function isSharable($path): bool {
+ public function isSharable(string $path): bool {
return $this->getWrapperStorage()->isSharable($path);
}
- public function getPermissions($path): int {
+ public function getPermissions(string $path): int {
return $this->getWrapperStorage()->getPermissions($path);
}
- public function file_exists($path): bool {
+ public function file_exists(string $path): bool {
return $this->getWrapperStorage()->file_exists($path);
}
- public function filemtime($path): int|false {
+ public function filemtime(string $path): int|false {
return $this->getWrapperStorage()->filemtime($path);
}
- public function file_get_contents($path): string|false {
+ public function file_get_contents(string $path): string|false {
return $this->getWrapperStorage()->file_get_contents($path);
}
- public function file_put_contents($path, $data): int|float|false {
+ public function file_put_contents(string $path, mixed $data): int|float|false {
return $this->getWrapperStorage()->file_put_contents($path, $data);
}
- public function unlink($path): bool {
+ public function unlink(string $path): bool {
return $this->getWrapperStorage()->unlink($path);
}
- public function rename($source, $target): bool {
+ public function rename(string $source, string $target): bool {
return $this->getWrapperStorage()->rename($source, $target);
}
- public function copy($source, $target): bool {
+ public function copy(string $source, string $target): bool {
return $this->getWrapperStorage()->copy($source, $target);
}
- public function fopen($path, $mode) {
+ public function fopen(string $path, string $mode) {
return $this->getWrapperStorage()->fopen($path, $mode);
}
- public function getMimeType($path): string|false {
+ public function getMimeType(string $path): string|false {
return $this->getWrapperStorage()->getMimeType($path);
}
- public function hash($type, $path, $raw = false): string|false {
+ public function hash(string $type, string $path, bool $raw = false): string|false {
return $this->getWrapperStorage()->hash($type, $path, $raw);
}
- public function free_space($path): int|float|false {
+ public function free_space(string $path): int|float|false {
return $this->getWrapperStorage()->free_space($path);
}
- public function touch($path, $mtime = null): bool {
+ public function touch(string $path, ?int $mtime = null): bool {
return $this->getWrapperStorage()->touch($path, $mtime);
}
- public function getLocalFile($path): string|false {
+ public function getLocalFile(string $path): string|false {
return $this->getWrapperStorage()->getLocalFile($path);
}
- public function hasUpdated($path, $time): bool {
+ public function hasUpdated(string $path, int $time): bool {
return $this->getWrapperStorage()->hasUpdated($path, $time);
}
- public function getCache($path = '', $storage = null): ICache {
+ public function getCache(string $path = '', ?IStorage $storage = null): ICache {
if (!$storage) {
$storage = $this;
}
return $this->getWrapperStorage()->getCache($path, $storage);
}
- public function getScanner($path = '', $storage = null): IScanner {
+ public function getScanner(string $path = '', ?IStorage $storage = null): IScanner {
if (!$storage) {
$storage = $this;
}
return $this->getWrapperStorage()->getScanner($path, $storage);
}
- public function getOwner($path): string|false {
+ public function getOwner(string $path): string|false {
return $this->getWrapperStorage()->getOwner($path);
}
- public function getWatcher($path = '', $storage = null): IWatcher {
+ public function getWatcher(string $path = '', ?IStorage $storage = null): IWatcher {
if (!$storage) {
$storage = $this;
}
return $this->getWrapperStorage()->getWatcher($path, $storage);
}
- public function getPropagator($storage = null): IPropagator {
+ public function getPropagator(?IStorage $storage = null): IPropagator {
if (!$storage) {
$storage = $this;
}
return $this->getWrapperStorage()->getPropagator($storage);
}
- public function getUpdater($storage = null): IUpdater {
+ public function getUpdater(?IStorage $storage = null): IUpdater {
if (!$storage) {
$storage = $this;
}
return $this->getWrapperStorage()->getStorageCache();
}
- public function getETag($path): string|false {
+ public function getETag(string $path): string|false {
return $this->getWrapperStorage()->getETag($path);
}
return $this->getWrapperStorage()->isLocal();
}
- public function instanceOfStorage($class): bool {
+ public function instanceOfStorage(string $class): bool {
if (ltrim($class, '\\') === 'OC\Files\Storage\Shared') {
// FIXME Temporary fix to keep existing checks working
$class = '\OCA\Files_Sharing\SharedStorage';
/**
* Pass any methods custom to specific storage implementations to the wrapped storage
*
- * @param string $method
- * @param array $args
* @return mixed
*/
- public function __call($method, $args) {
+ public function __call(string $method, array $args) {
return call_user_func_array([$this->getWrapperStorage(), $method], $args);
}
- public function getDirectDownload($path): array|false {
+ public function getDirectDownload(string $path): array|false {
return $this->getWrapperStorage()->getDirectDownload($path);
}
return $this->getWrapperStorage()->getAvailability();
}
- public function setAvailability($isAvailable): void {
+ public function setAvailability(bool $isAvailable): void {
$this->getWrapperStorage()->setAvailability($isAvailable);
}
- public function verifyPath($path, $fileName): void {
+ public function verifyPath(string $path, string $fileName): void {
$this->getWrapperStorage()->verifyPath($path, $fileName);
}
- public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool {
+ public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool {
if ($sourceStorage === $this) {
return $this->copy($sourceInternalPath, $targetInternalPath);
}
return $this->getWrapperStorage()->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
}
- public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool {
+ public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool {
if ($sourceStorage === $this) {
return $this->rename($sourceInternalPath, $targetInternalPath);
}
return $this->getWrapperStorage()->moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
}
- public function getMetaData($path): ?array {
+ public function getMetaData(string $path): ?array {
return $this->getWrapperStorage()->getMetaData($path);
}
- public function acquireLock($path, $type, ILockingProvider $provider): void {
+ public function acquireLock(string $path, int $type, ILockingProvider $provider): void {
if ($this->getWrapperStorage()->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) {
$this->getWrapperStorage()->acquireLock($path, $type, $provider);
}
}
- public function releaseLock($path, $type, ILockingProvider $provider): void {
+ public function releaseLock(string $path, int $type, ILockingProvider $provider): void {
if ($this->getWrapperStorage()->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) {
$this->getWrapperStorage()->releaseLock($path, $type, $provider);
}
}
- public function changeLock($path, $type, ILockingProvider $provider): void {
+ public function changeLock(string $path, int $type, ILockingProvider $provider): void {
if ($this->getWrapperStorage()->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) {
$this->getWrapperStorage()->changeLock($path, $type, $provider);
}
}
}
- public function getDirectoryContent($directory): \Traversable {
+ public function getDirectoryContent(string $directory): \Traversable {
return $this->getWrapperStorage()->getDirectoryContent($directory);
}
return 'null';
}
- public function mkdir($path): never {
+ public function mkdir(string $path): never {
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
}
- public function rmdir($path): never {
+ public function rmdir(string $path): never {
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
}
- public function opendir($path): IteratorDirectory {
+ public function opendir(string $path): IteratorDirectory {
return new IteratorDirectory([]);
}
- public function is_dir($path): bool {
+ public function is_dir(string $path): bool {
return $path === '';
}
- public function is_file($path): bool {
+ public function is_file(string $path): bool {
return false;
}
- public function stat($path): never {
+ public function stat(string $path): never {
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
}
- public function filetype($path): string|false {
+ public function filetype(string $path): string|false {
return ($path === '') ? 'dir' : false;
}
- public function filesize($path): never {
+ public function filesize(string $path): never {
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
}
- public function isCreatable($path): bool {
+ public function isCreatable(string $path): bool {
return false;
}
- public function isReadable($path): bool {
+ public function isReadable(string $path): bool {
return $path === '';
}
- public function isUpdatable($path): bool {
+ public function isUpdatable(string $path): bool {
return false;
}
- public function isDeletable($path): bool {
+ public function isDeletable(string $path): bool {
return false;
}
- public function isSharable($path): bool {
+ public function isSharable(string $path): bool {
return false;
}
- public function getPermissions($path): int {
+ public function getPermissions(string $path): int {
return 0;
}
- public function file_exists($path): bool {
+ public function file_exists(string $path): bool {
return $path === '';
}
- public function filemtime($path): int|false {
+ public function filemtime(string $path): int|false {
return ($path === '') ? time() : false;
}
- public function file_get_contents($path): never {
+ public function file_get_contents(string $path): never {
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
}
- public function file_put_contents($path, $data): never {
+ public function file_put_contents(string $path, mixed $data): never {
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
}
- public function unlink($path): never {
+ public function unlink(string $path): never {
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
}
- public function rename($source, $target): never {
+ public function rename(string $source, string $target): never {
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
}
- public function copy($source, $target): never {
+ public function copy(string $source, string $target): never {
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
}
- public function fopen($path, $mode): never {
+ public function fopen(string $path, string $mode): never {
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
}
- public function getMimeType($path): never {
+ public function getMimeType(string $path): never {
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
}
- public function hash($type, $path, $raw = false): never {
+ public function hash(string $type, string $path, bool $raw = false): never {
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
}
- public function free_space($path): int {
+ public function free_space(string $path): int {
return FileInfo::SPACE_UNKNOWN;
}
- public function touch($path, $mtime = null): never {
+ public function touch(string $path, ?int $mtime = null): never {
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
}
- public function getLocalFile($path): string|false {
+ public function getLocalFile(string $path): string|false {
return false;
}
- public function hasUpdated($path, $time): bool {
+ public function hasUpdated(string $path, int $time): bool {
return false;
}
- public function getETag($path): string {
+ public function getETag(string $path): string {
return '';
}
return false;
}
- public function getDirectDownload($path): array|false {
+ public function getDirectDownload(string $path): array|false {
return false;
}
- public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false): never {
+ public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath, bool $preserveMtime = false): never {
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
}
- public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): never {
+ public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): never {
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
}
return true;
}
- public function getOwner($path): string|false {
+ public function getOwner(string $path): string|false {
return false;
}
- public function getCache($path = '', $storage = null): ICache {
+ public function getCache(string $path = '', ?IStorage $storage = null): ICache {
return new NullCache();
}
}
public function startChunkedWrite(string $targetPath): string;
/**
- * @param string $targetPath
- * @param string $writeToken
- * @param string $chunkId
* @param resource $data
- * @param int|null $size
* @throws GenericFileException
* @since 26.0.0
*/
public function putChunkedWritePart(string $targetPath, string $writeToken, string $chunkId, $data, ?int $size = null): ?array;
/**
- * @param string $targetPath
- * @param string $writeToken
- * @return int
* @throws GenericFileException
* @since 26.0.0
*/
public function completeChunkedWrite(string $targetPath, string $writeToken): int;
/**
- * @param string $targetPath
- * @param string $writeToken
* @throws GenericFileException
* @since 26.0.0
*/
/**
* @param string $path The path of the file to acquire the lock for
* @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
- * @param \OCP\Lock\ILockingProvider $provider
* @throws \OCP\Lock\LockedException
* @since 9.0.0
*/
- public function acquireLock($path, $type, ILockingProvider $provider);
+ public function acquireLock(string $path, int $type, ILockingProvider $provider);
/**
* @param string $path The path of the file to acquire the lock for
* @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
- * @param \OCP\Lock\ILockingProvider $provider
* @throws \OCP\Lock\LockedException
* @since 9.0.0
*/
- public function releaseLock($path, $type, ILockingProvider $provider);
+ public function releaseLock(string $path, int $type, ILockingProvider $provider);
/**
* @param string $path The path of the file to change the lock for
* @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
- * @param \OCP\Lock\ILockingProvider $provider
* @throws \OCP\Lock\LockedException
* @since 9.0.0
*/
- public function changeLock($path, $type, ILockingProvider $provider);
+ public function changeLock(string $path, int $type, ILockingProvider $provider);
}
/**
* Start the notification handler for this storage
*
- * @param $path
* @return INotifyHandler
*
* @since 12.0.0
*/
- public function notify($path);
+ public function notify(string $path);
}
/**
* The the associated share
*
- * @return IShare
* @since 30.0.0
*/
public function getShare(): IShare;
* see https://www.php.net/manual/en/function.mkdir.php
* implementations need to implement a recursive mkdir
*
- * @param string $path
* @return bool
* @since 9.0.0
*/
- public function mkdir($path);
+ public function mkdir(string $path);
/**
* see https://www.php.net/manual/en/function.rmdir.php
*
- * @param string $path
* @return bool
* @since 9.0.0
*/
- public function rmdir($path);
+ public function rmdir(string $path);
/**
* see https://www.php.net/manual/en/function.opendir.php
*
- * @param string $path
* @return resource|false
* @since 9.0.0
*/
- public function opendir($path);
+ public function opendir(string $path);
/**
* see https://www.php.net/manual/en/function.is-dir.php
*
- * @param string $path
* @return bool
* @since 9.0.0
*/
- public function is_dir($path);
+ public function is_dir(string $path);
/**
* see https://www.php.net/manual/en/function.is-file.php
*
- * @param string $path
* @return bool
* @since 9.0.0
*/
- public function is_file($path);
+ public function is_file(string $path);
/**
* see https://www.php.net/manual/en/function.stat.php
* only the following keys are required in the result: size and mtime
*
- * @param string $path
* @return array|false
* @since 9.0.0
*/
- public function stat($path);
+ public function stat(string $path);
/**
* see https://www.php.net/manual/en/function.filetype.php
*
- * @param string $path
* @return string|false
* @since 9.0.0
*/
- public function filetype($path);
+ public function filetype(string $path);
/**
* see https://www.php.net/manual/en/function.filesize.php
* The result for filesize when called on a folder is required to be 0
*
- * @param string $path
* @return int|float|false
* @since 9.0.0
*/
- public function filesize($path);
+ public function filesize(string $path);
/**
* check if a file can be created in $path
*
- * @param string $path
* @return bool
* @since 9.0.0
*/
- public function isCreatable($path);
+ public function isCreatable(string $path);
/**
* check if a file can be read
*
- * @param string $path
* @return bool
* @since 9.0.0
*/
- public function isReadable($path);
+ public function isReadable(string $path);
/**
* check if a file can be written to
*
- * @param string $path
* @return bool
* @since 9.0.0
*/
- public function isUpdatable($path);
+ public function isUpdatable(string $path);
/**
* check if a file can be deleted
*
- * @param string $path
* @return bool
* @since 9.0.0
*/
- public function isDeletable($path);
+ public function isDeletable(string $path);
/**
* check if a file can be shared
*
- * @param string $path
* @return bool
* @since 9.0.0
*/
- public function isSharable($path);
+ public function isSharable(string $path);
/**
* get the full permissions of a path.
* Should return a combination of the PERMISSION_ constants defined in lib/public/constants.php
*
- * @param string $path
* @return int
* @since 9.0.0
*/
- public function getPermissions($path);
+ public function getPermissions(string $path);
/**
- * see https://www.php.net/manual/en/function.file_exists.php
+ * see https://www.php.net/manual/en/function.file-exists.php
*
- * @param string $path
* @return bool
* @since 9.0.0
*/
- public function file_exists($path);
+ public function file_exists(string $path);
/**
* see https://www.php.net/manual/en/function.filemtime.php
*
- * @param string $path
* @return int|false
* @since 9.0.0
*/
- public function filemtime($path);
+ public function filemtime(string $path);
/**
- * see https://www.php.net/manual/en/function.file_get_contents.php
+ * see https://www.php.net/manual/en/function.file-get-contents.php
*
- * @param string $path
* @return string|false
* @since 9.0.0
*/
- public function file_get_contents($path);
+ public function file_get_contents(string $path);
/**
- * see https://www.php.net/manual/en/function.file_put_contents.php
+ * see https://www.php.net/manual/en/function.file-put-contents.php
*
- * @param string $path
- * @param mixed $data
* @return int|float|false
* @since 9.0.0
*/
- public function file_put_contents($path, $data);
+ public function file_put_contents(string $path, mixed $data);
/**
* see https://www.php.net/manual/en/function.unlink.php
*
- * @param string $path
* @return bool
* @since 9.0.0
*/
- public function unlink($path);
+ public function unlink(string $path);
/**
* see https://www.php.net/manual/en/function.rename.php
*
- * @param string $source
- * @param string $target
* @return bool
* @since 9.0.0
*/
- public function rename($source, $target);
+ public function rename(string $source, string $target);
/**
* see https://www.php.net/manual/en/function.copy.php
*
- * @param string $source
- * @param string $target
* @return bool
* @since 9.0.0
*/
- public function copy($source, $target);
+ public function copy(string $source, string $target);
/**
* see https://www.php.net/manual/en/function.fopen.php
*
- * @param string $path
- * @param string $mode
* @return resource|false
* @since 9.0.0
*/
- public function fopen($path, $mode);
+ public function fopen(string $path, string $mode);
/**
* get the mimetype for a file or folder
* The mimetype for a folder is required to be "httpd/unix-directory"
*
- * @param string $path
* @return string|false
* @since 9.0.0
*/
- public function getMimeType($path);
+ public function getMimeType(string $path);
/**
* see https://www.php.net/manual/en/function.hash-file.php
*
- * @param string $type
- * @param string $path
- * @param bool $raw
* @return string|false
* @since 9.0.0
*/
- public function hash($type, $path, $raw = false);
+ public function hash(string $type, string $path, bool $raw = false);
/**
* see https://www.php.net/manual/en/function.disk-free-space.php
*
- * @param string $path
* @return int|float|false
* @since 9.0.0
*/
- public function free_space($path);
+ public function free_space(string $path);
/**
* see https://www.php.net/manual/en/function.touch.php
* If the backend does not support the operation, false should be returned
*
- * @param string $path
- * @param int $mtime
* @return bool
* @since 9.0.0
*/
- public function touch($path, $mtime = null);
+ public function touch(string $path, ?int $mtime = null);
/**
* get the path to a local version of the file.
* The local version of the file can be temporary and doesn't have to be persistent across requests
*
- * @param string $path
* @return string|false
* @since 9.0.0
*/
- public function getLocalFile($path);
+ public function getLocalFile(string $path);
/**
* check if a file or folder has been updated since $time
*
- * @param string $path
- * @param int $time
* @return bool
* @since 9.0.0
*
* hasUpdated for folders should return at least true if a file inside the folder is add, removed or renamed.
* returning true for other changes in the folder is optional
*/
- public function hasUpdated($path, $time);
+ public function hasUpdated(string $path, int $time);
/**
* get the ETag for a file or folder
*
- * @param string $path
* @return string|false
* @since 9.0.0
*/
- public function getETag($path);
+ public function getETag(string $path);
/**
* Returns whether the storage is local, which means that files
* Check if the storage is an instance of $class or is a wrapper for a storage that is an instance of $class
*
* @template T of IStorage
- * @param string $class
* @psalm-param class-string<T> $class
* @return bool
* @since 9.0.0
* @psalm-assert-if-true T $this
*/
- public function instanceOfStorage($class);
+ public function instanceOfStorage(string $class);
/**
* A custom storage implementation can return an url for direct download of a give file.
*
* For now the returned array can hold the parameter url - in future more attributes might follow.
*
- * @param string $path
* @return array|false
* @since 9.0.0
*/
- public function getDirectDownload($path);
+ public function getDirectDownload(string $path);
/**
- * @param string $path the path of the target folder
- * @param string $fileName the name of the file itself
* @return void
* @throws InvalidPathException
* @since 9.0.0
*/
- public function verifyPath($path, $fileName);
+ public function verifyPath(string $path, string $fileName);
/**
- * @param IStorage $sourceStorage
- * @param string $sourceInternalPath
- * @param string $targetInternalPath
* @return bool
* @since 9.0.0
*/
- public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath);
+ public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath);
/**
- * @param IStorage $sourceStorage
- * @param string $sourceInternalPath
- * @param string $targetInternalPath
* @return bool
* @since 9.0.0
*/
- public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath);
+ public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath);
/**
* Test a storage for availability
/**
* @since 9.0.0
- * @param bool $isAvailable
* @return void
*/
- public function setAvailability($isAvailable);
+ public function setAvailability(bool $isAvailable);
/**
* @since 12.0.0
public function needsPartFile();
/**
- * @param string $path path for which to retrieve the owner
* @return string|false
* @since 9.0.0
*/
- public function getOwner($path);
+ public function getOwner(string $path);
/**
- * @param string $path
- * @param IStorage|null $storage
* @return ICache
* @since 9.0.0
*/
- public function getCache($path = '', $storage = null);
+ public function getCache(string $path = '', ?IStorage $storage = null);
/**
* @return IPropagator
* This can be used for storages that do not have a dedicated owner, where we want to
* pass the user that we setup the mountpoint for along to the storage layer
*
- * @param string|null $user Owner user id
+ * @param ?string $user Owner user id
* @return void
* @since 30.0.0
*/
*
* $callback should be a function of type (string $mountPoint, Storage $storage) => Storage
*
- * @param string $wrapperName
- * @param callable $callback
* @return bool true if the wrapper was added, false if there was already a wrapper with this
* name registered
* @since 8.0.0
*/
- public function addStorageWrapper($wrapperName, $callback);
+ public function addStorageWrapper(string $wrapperName, callable $callback);
/**
- * @param IMountPoint $mountPoint
- * @param string $class
- * @param array $arguments
* @return IStorage
* @since 8.0.0
*/
- public function getInstance(IMountPoint $mountPoint, $class, $arguments);
+ public function getInstance(IMountPoint $mountPoint, string $class, array $arguments);
}
/**
* Write the data from a stream to a file
*
- * @param string $path
* @param resource $stream
- * @param int|null $size the size of the stream if known in advance
+ * @param ?int $size the size of the stream if known in advance
* @return int the number of bytes written
* @throws GenericFileException
* @since 15.0.0
namespace Test\Files\Mount;
use OC\Files\Storage\StorageFactory;
+use OC\Lockdown\Filesystem\NullStorage;
use OCP\Files\Storage\IStorage;
-class DummyStorage {
-}
-
class MountPointTest extends \Test\TestCase {
public function testGetStorage(): void {
$storage = $this->createMock(IStorage::class);
$mountPoint = new \OC\Files\Mount\MountPoint(
// just use this because a real class is needed
- '\Test\Files\Mount\DummyStorage',
+ NullStorage::class,
'/mountpoint',
null,
$loader
$mountPoint = new \OC\Files\Mount\MountPoint(
// just use this because a real class is needed
- '\Test\Files\Mount\DummyStorage',
+ NullStorage::class,
'/mountpoint',
null,
$loader
use OC\Files\Storage\Temporary;
class StorageNoRecursiveCopy extends Temporary {
- public function copy($path1, $path2): bool {
- if ($this->is_dir($path1)) {
+ public function copy(string $source, string $target): bool {
+ if ($this->is_dir($source)) {
return false;
}
- return copy($this->getSourcePath($path1), $this->getSourcePath($path2));
+ return copy($this->getSourcePath($source), $this->getSourcePath($target));
}
}
use Test\Traits\UserTrait;
class TemporaryNoTouch extends Temporary {
- public function touch($path, $mtime = null): bool {
+ public function touch(string $path, ?int $mtime = null): bool {
return false;
}
}
class TemporaryNoCross extends Temporary {
- public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = null): bool {
+ public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath, bool $preserveMtime = false): bool {
return Common::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime);
}
- public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool {
+ public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool {
return Common::moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
}
}
class TemporaryNoLocal extends Temporary {
- public function instanceOfStorage($className): bool {
- if ($className === '\OC\Files\Storage\Local') {
+ public function instanceOfStorage(string $class): bool {
+ if ($class === '\OC\Files\Storage\Local') {
return false;
} else {
- return parent::instanceOfStorage($className);
+ return parent::instanceOfStorage($class);
}
}
}