better error detection and don't use glob()
This commit is contained in:
parent
5610842e56
commit
4d1086c35f
|
@ -214,15 +214,24 @@ class Keymanager {
|
||||||
*
|
*
|
||||||
* @param \OC_FilesystemView $view
|
* @param \OC_FilesystemView $view
|
||||||
* @param string $path path of the file the key belongs to
|
* @param string $path path of the file the key belongs to
|
||||||
|
* @param string $userId the user to whom the file belongs
|
||||||
* @return bool Outcome of unlink operation
|
* @return bool Outcome of unlink operation
|
||||||
* @note $path must be relative to data/user/files. e.g. mydoc.txt NOT
|
* @note $path must be relative to data/user/files. e.g. mydoc.txt NOT
|
||||||
* /data/admin/files/mydoc.txt
|
* /data/admin/files/mydoc.txt
|
||||||
*/
|
*/
|
||||||
public static function deleteFileKey(\OC_FilesystemView $view, $path) {
|
public static function deleteFileKey($view, $path, $userId=null) {
|
||||||
|
|
||||||
$trimmed = ltrim($path, '/');
|
$trimmed = ltrim($path, '/');
|
||||||
|
|
||||||
|
if ($trimmed === '') {
|
||||||
|
\OCP\Util::writeLog('Encryption library',
|
||||||
|
'Can\'t delete file-key empty path given!', \OCP\Util::ERROR);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($userId === null) {
|
||||||
$userId = Helper::getUser($path);
|
$userId = Helper::getUser($path);
|
||||||
|
}
|
||||||
$util = new Util($view, $userId);
|
$util = new Util($view, $userId);
|
||||||
|
|
||||||
if($util->isSystemWideMountPoint($path)) {
|
if($util->isSystemWideMountPoint($path)) {
|
||||||
|
@ -402,7 +411,15 @@ class Keymanager {
|
||||||
* @param string $userId owner of the file
|
* @param string $userId owner of the file
|
||||||
* @param string $filePath path to the file, relative to the owners file dir
|
* @param string $filePath path to the file, relative to the owners file dir
|
||||||
*/
|
*/
|
||||||
public static function delAllShareKeys(\OC_FilesystemView $view, $userId, $filePath) {
|
public static function delAllShareKeys($view, $userId, $filePath) {
|
||||||
|
|
||||||
|
$filePath = ltrim($filePath, '/');
|
||||||
|
|
||||||
|
if ($filePath === '') {
|
||||||
|
\OCP\Util::writeLog('Encryption library',
|
||||||
|
'Can\'t delete share-keys empty path given!', \OCP\Util::ERROR);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$util = new util($view, $userId);
|
$util = new util($view, $userId);
|
||||||
|
|
||||||
|
@ -413,17 +430,15 @@ class Keymanager {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($view->is_dir($userId . '/files/' . $filePath)) {
|
if ($view->is_dir($baseDir . $filePath)) {
|
||||||
$view->unlink($baseDir . $filePath);
|
$view->unlink($baseDir . $filePath);
|
||||||
} else {
|
} else {
|
||||||
$localKeyPath = $view->getLocalFile($baseDir . $filePath);
|
$parentDir = dirname($baseDir . $filePath);
|
||||||
$escapedPath = Helper::escapeGlobPattern($localKeyPath);
|
$filename = pathinfo($filePath, PATHINFO_BASENAME);
|
||||||
$matches = glob($escapedPath . '*.shareKey');
|
foreach($view->getDirectoryContent($parentDir) as $content) {
|
||||||
foreach ($matches as $ma) {
|
$path = $content['path'];
|
||||||
$result = unlink($ma);
|
if (strpos($content['name'], $filename) === 0) {
|
||||||
if (!$result) {
|
$view->unlink('/' . $userId . '/' . $path);
|
||||||
\OCP\Util::writeLog('Encryption library',
|
|
||||||
'Keyfile or shareKey could not be deleted for file "' . $filePath . '"', \OCP\Util::ERROR);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue