mirror of
https://github.com/nextcloud/server.git
synced 2026-03-09 01:40:53 -04:00
more optimized getPermissions/getMetaData
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
2b592c3be2
commit
50d51542bc
1 changed files with 44 additions and 0 deletions
|
|
@ -41,6 +41,8 @@ use Icewind\Streams\IteratorDirectory;
|
|||
use Icewind\Streams\RetryWrapper;
|
||||
use OC\Files\Filesystem;
|
||||
use OC\Files\Storage\Common;
|
||||
use OCP\Constants;
|
||||
use OCP\Files\FileInfo;
|
||||
use phpseclib\Net\SFTP\Stream;
|
||||
|
||||
/**
|
||||
|
|
@ -532,4 +534,46 @@ class SFTP extends Common {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public function getPermissions($path) {
|
||||
$stat = $this->getConnection()->stat($this->absPath($path));
|
||||
if (!$stat) {
|
||||
return 0;
|
||||
}
|
||||
if ($stat['type'] === NET_SFTP_TYPE_DIRECTORY) {
|
||||
return Constants::PERMISSION_ALL;
|
||||
} else {
|
||||
return Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE;
|
||||
}
|
||||
}
|
||||
|
||||
public function getMetaData($path) {
|
||||
$stat = $this->getConnection()->stat($this->absPath($path));
|
||||
if (!$stat) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($stat['type'] === NET_SFTP_TYPE_DIRECTORY) {
|
||||
$permissions = Constants::PERMISSION_ALL;
|
||||
} else {
|
||||
$permissions = Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE;
|
||||
}
|
||||
|
||||
if ($stat['type'] === NET_SFTP_TYPE_DIRECTORY) {
|
||||
$stat['size'] = -1;
|
||||
$stat['mimetype'] = FileInfo::MIMETYPE_FOLDER;
|
||||
} else {
|
||||
$stat['mimetype'] = \OC::$server->getMimeTypeDetector()->detectPath($path);
|
||||
}
|
||||
|
||||
$stat['etag'] = $this->getETag($path);
|
||||
$stat['storage_mtime'] = $stat['mtime'];
|
||||
$stat['permissions'] = $permissions;
|
||||
$stat['name'] = basename($path);
|
||||
|
||||
$keys = ['size', 'mtime', 'mimetype', 'etag', 'storage_mtime', 'permissions', 'name'];
|
||||
return array_intersect_key($stat, array_flip($keys));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue