From 2fb62f0468454beff9e2555cb22130a1e7d9966a Mon Sep 17 00:00:00 2001 From: kubi Date: Sun, 5 May 2024 19:11:16 +0000 Subject: [PATCH] Clean up empty backup directories --- server/backup/backup_local.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/server/backup/backup_local.go b/server/backup/backup_local.go index a16d22c..4ca44c3 100644 --- a/server/backup/backup_local.go +++ b/server/backup/backup_local.go @@ -51,7 +51,21 @@ func LocateLocal(client remote.Client, uuid string, suuid string) (*LocalBackup, // Remove removes a backup from the system. func (b *LocalBackup) Remove() error { - return os.Remove(b.Path()) + err := os.Remove(b.Path()) + if err != nil { + return err + } + d, err := os.ReadDir(filepath.Dir(b.Path())) + if err != nil { + return err + } + if len(d) == 0 { + err := os.Remove(filepath.Dir(b.Path())) + if err != nil { + return err + } + } + return nil } // WithLogContext attaches additional context to the log output for this backup.