From 7f0a87be444571f2944c1ffcb106e83373eb672f Mon Sep 17 00:00:00 2001 From: bohwaz Date: Sun, 31 Dec 2023 16:53:00 +0100 Subject: [PATCH] Allow to empty trash from users page --- doc/CHANGES.md | 1 + lib/KaraDAV/Storage.php | 4 ++-- lib/KaraDAV/Users.php | 6 ++++++ www/index.php | 13 ++++++++++++- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/doc/CHANGES.md b/doc/CHANGES.md index 43cbca5..0383515 100644 --- a/doc/CHANGES.md +++ b/doc/CHANGES.md @@ -3,6 +3,7 @@ * Add support for `PROPPATCH`-ing last modification time * Fix creation of ghost directory in user directory (fix #46) * Fix bug with NextCloud client where files were not showing up anymore +* Allow to empty trash from user home * Update dependencies ## 0.4.2 diff --git a/lib/KaraDAV/Storage.php b/lib/KaraDAV/Storage.php index 893e0da..3b501e0 100644 --- a/lib/KaraDAV/Storage.php +++ b/lib/KaraDAV/Storage.php @@ -547,7 +547,7 @@ class Storage extends AbstractStorage implements TrashInterface while ($f = readdir($dir)) { // Skip dots - if ($f == '.' || $f = '..') { + if ($f === '.' || $f === '..') { continue; } @@ -564,7 +564,7 @@ class Storage extends AbstractStorage implements TrashInterface closedir($dir); - @rmdir($path); + rmdir($path); } static public function getDirectoryMTime(string $path): int diff --git a/lib/KaraDAV/Users.php b/lib/KaraDAV/Users.php index 62c8d30..a18ba9b 100644 --- a/lib/KaraDAV/Users.php +++ b/lib/KaraDAV/Users.php @@ -345,4 +345,10 @@ class Users Storage::deleteDirectory($user->path); DB::getInstance()->run('DELETE FROM users WHERE id = ?;', $user->id); } + + public function emptyTrash(?stdClass $user) + { + $path = rtrim($user->path, '/') . '/.trash'; + Storage::deleteDirectory($path); + } } diff --git a/www/index.php b/www/index.php index 4443801..d25d4f2 100644 --- a/www/index.php +++ b/www/index.php @@ -22,6 +22,12 @@ if (!$user) { exit; } +if (isset($_GET['empty_trash'])) { + $users->emptyTrash($user); + header('Location: ./'); + exit; +} + $quota = $users->quota($user, true); $free = format_bytes($quota->free); $used = format_bytes($quota->used); @@ -30,6 +36,11 @@ $trash = format_bytes($quota->trash ?? 0); $percent = $quota->total ? floor(($quota->used / $quota->total)*100) . '%' : '100%'; $www_url = WWW_URL; $username = htmlspecialchars($user->login); +$trash_button = ''; + +if ($quota->trash) { + $trash_button = '
Empty trash now'; +} html_head('My files'); @@ -40,7 +51,7 @@ echo <<

{$percent} used, {$free} free

Used {$used} out of a total of {$total}.
-
Trash: {$trash}.
+
Trash: {$trash}. {$trash_button}
WebDAV URL

{$user->dav_url}

NextCloud URL