diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2014-02-03 13:39:05 +0100 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2014-02-03 13:39:05 +0100 |
commit | 97921d0c25469bd905906406c70a96eeb7fd1664 (patch) | |
tree | d0ff6600e9071fbd5195186f2fba5f6f12c95dcb /apps/files_encryption/lib/keymanager.php | |
parent | fe5f5122725869f837612c5f070335ba89d5fc50 (diff) | |
download | nextcloud-server-97921d0c25469bd905906406c70a96eeb7fd1664.tar.gz nextcloud-server-97921d0c25469bd905906406c70a96eeb7fd1664.zip |
add function to extract filename from sharekey name + tests
Diffstat (limited to 'apps/files_encryption/lib/keymanager.php')
-rwxr-xr-x | apps/files_encryption/lib/keymanager.php | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php index 17b8180bfdd..7abc565f609 100755 --- a/apps/files_encryption/lib/keymanager.php +++ b/apps/files_encryption/lib/keymanager.php @@ -437,7 +437,7 @@ class Keymanager { $filename = pathinfo($filePath, PATHINFO_BASENAME); foreach($view->getDirectoryContent($parentDir) as $content) { $path = $content['path']; - if (strpos($content['name'], $filename) === 0) { + if (self::getFilenameFromShareKey($content['name']) === $filename) { $view->unlink('/' . $userId . '/' . $path); } } @@ -538,4 +538,20 @@ class Keymanager { return $targetPath; } + + /** + * @brief extract filename from share key name + * @param string $shareKey (filename.userid.sharekey) + * @return mixed filename or false + */ + protected static function getFilenameFromShareKey($shareKey) { + $parts = explode('.', $shareKey); + + $filename = false; + if(count($parts) > 2) { + $filename = implode('.', array_slice($parts, 0, count($parts)-2)); + } + + return $filename; + } } |