Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add support for deleting individual images from zip galleries#7107

Open
NebuPookins wants to merge 1 commit into
stashapp:developstashapp/stash:developfrom
NebuPookins:developNebuPookins/stash:developCopy head branch name to clipboard
Open

Add support for deleting individual images from zip galleries#7107
NebuPookins wants to merge 1 commit into
stashapp:developstashapp/stash:developfrom
NebuPookins:developNebuPookins/stash:developCopy head branch name to clipboard

Conversation

@NebuPookins

Copy link
Copy Markdown

Description

When deleting an image whose file lives inside a zip/cbz archive, remove just that entry from the zip. (Previously, these deletion requests would be silently ignored).

Uses a deferred rewrite strategy: entries are accumulated during the transaction and the zip is rewritten at Commit() time, keeping bulk deletions efficient.

Also extracts a shared decodeZipEntryNames helper to avoid duplicating charset-detection logic between the zip FS reader and the rewriter.

Related Issue

Fixes #7106

Testing

Deleted an image in a zip gallery, confirmed (by inspecting the zip) that the file actually got deleted.

Checklist

  • I have read and understood the Contributing document.
  • I have read and understood the AI Usage Policy document.
  • I have made corresponding changes to the documentation (if applicable).

AI Usage Disclosure

  • I have used AI tools to assist with this pull request, and I have disclosed the tools and how I used them below.

Collaborated with AI to write this code change.

When deleting an image whose file lives inside a zip/cbz archive,
remove just that entry from the zip. (Previously, these deletion
requests would be silently ignored).

Uses a deferred rewrite strategy: entries are accumulated during
the transaction and the zip is rewritten at Commit() time, keeping
bulk deletions efficient.

Also extracts a shared decodeZipEntryNames helper to avoid duplicating
charset-detection logic between the zip FS reader and the rewriter.

@Gykes Gykes left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a quick static review. Didn't test anything

Comment thread pkg/file/delete.go
Comment on lines +227 to +238
// Rewrite each zip that has pending entry removals.
for zipPath, entries := range d.zipEntries {
tmpPath, err := RemoveEntriesFromZip(zipPath, entries)
if err != nil {
logger.Warnf("Error rewriting zip %q: %v", zipPath, err)
continue
}
if err := d.RenamerRemover.Rename(tmpPath, zipPath); err != nil {
_ = d.RenamerRemover.Remove(tmpPath)
logger.Warnf("Error applying zip rewrite for %q: %v", zipPath, err)
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewriting the zip would shrink it on disk but I dont think it updates the zips stored Size. I believe this would break the gallery until you do another scan.

The zip rewrite also runs in the post commit hook so any kind of failure here would mean that the DB would be inconsistent with the archive and the image will be picked back up on scan.

Comment thread pkg/file/zip.go
// directory, excluding all entries whose relative paths (using forward slashes) appear in
// entriesToRemove. Returns the path of the temporary file. The caller is responsible for
// atomically replacing the original zip with the temp file, or cleaning it up on rollback.
func RemoveEntriesFromZip(zipPath string, entriesToRemove []string) (string, error) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to ignore Trash path. This would permanently delete the image rather than pushing it to the trash path (if set)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deleting an image in a zip gallery silently fails

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.