From 3cf97f6e27df9875fb36c1ee6b5ea04abf177e7d Mon Sep 17 00:00:00 2001 From: WithoutPants <53250216+WithoutPants@users.noreply.github.com> Date: Sat, 11 Feb 2023 09:21:18 +1100 Subject: [PATCH] Handle folder symlinks correctly during clean (#3415) --- pkg/file/clean.go | 18 ++++++++++++++++++ ui/v2.5/src/docs/en/Changelog/v0190.md | 1 + 2 files changed, 19 insertions(+) diff --git a/pkg/file/clean.go b/pkg/file/clean.go index cc8ebde6b..53c1c981e 100644 --- a/pkg/file/clean.go +++ b/pkg/file/clean.go @@ -5,6 +5,8 @@ import ( "errors" "fmt" "io/fs" + "os" + "path/filepath" "github.com/stashapp/stash/pkg/job" "github.com/stashapp/stash/pkg/logger" @@ -351,6 +353,22 @@ func (j *cleanJob) shouldCleanFolder(ctx context.Context, f *Folder) bool { return true } + // #3261 - handle symlinks + if info.Mode()&os.ModeSymlink == os.ModeSymlink { + finalPath, err := filepath.EvalSymlinks(path) + if err != nil { + // don't bail out if symlink is invalid + logger.Infof("Invalid symlink. Marking to clean: \"%s\"", path) + return true + } + + info, err = j.FS.Lstat(finalPath) + if err != nil { + logger.Errorf("error getting file info for %q (-> %s), not cleaning: %v", path, finalPath, err) + return false + } + } + // run through path filter, if returns false then the file should be cleaned filter := j.options.PathFilter diff --git a/ui/v2.5/src/docs/en/Changelog/v0190.md b/ui/v2.5/src/docs/en/Changelog/v0190.md index 3c5035d92..6e6169c90 100644 --- a/ui/v2.5/src/docs/en/Changelog/v0190.md +++ b/ui/v2.5/src/docs/en/Changelog/v0190.md @@ -14,6 +14,7 @@ * Changed performer aliases to be a list, rather than a string field. ([#3113](https://github.com/stashapp/stash/pull/3113)) ### 🐛 Bug fixes +* Fixed folder symlinks not being handled correctly during clean. ([#3415](https://github.com/stashapp/stash/pull/3415)) * Fixed error when clicking Scrape All when a file-less scene is in the scene list. ([#3414](https://github.com/stashapp/stash/pull/3414)) * Fixed clicking popover pills not clearing search term. ([#3408](https://github.com/stashapp/stash/pull/3408)) * Fixed URL not being preserved when redirected to login. ([#3305](https://github.com/stashapp/stash/pull/3305))