Skip to content

fix(compress): preserve dotfile name when generating zip archive#1485

Open
toller892 wants to merge 1 commit into
yorukot:mainfrom
toller892:fix/zip-dotfile-name
Open

fix(compress): preserve dotfile name when generating zip archive#1485
toller892 wants to merge 1 commit into
yorukot:mainfrom
toller892:fix/zip-dotfile-name

Conversation

@toller892

@toller892 toller892 commented Jun 18, 2026

Copy link
Copy Markdown

getZipArchiveName produces .zip (no source name) when compressing a dot file or directory such as .test. The root cause is that Go's filepath.Ext returns the entire leading-dot basename as the extension, so strings.TrimSuffix strips everything and we're left with .zip.

When stripping the extension yields an empty or dot-only basename, fall back to the original name so the resulting zip preserves the source identifier.

Cases covered by the new unit tests:

  • .test.test.zip (was .zip)
  • ..test..test.zip (was ..zip)
  • test.txttest.zip (unchanged)
  • .test.txt.test.zip (unchanged)
  • testtest.zip (unchanged)

Fixes #1470

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced zip archive creation to properly handle dotfiles by implementing intelligent extension trimming logic with fallback behavior for edge cases where trimming would result in empty or dot-only basenames.
  • Tests

    • Added comprehensive test coverage for archive name derivation, validating behavior across regular filenames, dotfiles, files without extensions, and complex path components.

Compressing a dot file or directory such as `.test` previously
produced `.zip` instead of `.test.zip`. The cause is that
`filepath.Ext` treats a leading-dot basename (e.g. `.test`) as
its entire extension, so trimming it leaves an empty string and
the resulting zip name becomes just `.zip`.

When stripping the extension leaves an empty or dot-only basename,
fall back to the original name so the zip preserves the source
identifier.

Fixes yorukot#1470
@github-actions github-actions Bot added awaiting pr review test related PR / Issue related to testcases or testing in general. labels Jun 18, 2026
@github-actions

Copy link
Copy Markdown

🎉 Thank you for your first contribution to superfile!

We’re really excited to have you here 🙌

A maintainer might ask you to make a few changes before we can merge this PR.
That’s totally normal and part of the process. Don’t worry, we’ll help guide you through it.

👉 Please also take a moment to review our Contribution Guide

If you have any questions, feel free to open a Discussion or just ask in the comments!

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b93d348e-464a-4110-9b97-e809ff8c118f

📥 Commits

Reviewing files that changed from the base of the PR and between 774a2d4 and 49061de.

📒 Files selected for processing (2)
  • src/internal/file_operation_compress_test.go
  • src/internal/file_operations_compress.go

📝 Walkthrough

Walkthrough

getZipArchiveName in file_operations_compress.go gains a dotfile guard: after stripping the extension with filepath.Ext, if the result is empty or dot-only, it falls back to the original base. A new table-driven test TestGetZipArchiveName covers regular filenames, dotfiles, extension-less inputs, and dot-prefixed segments.

Dotfile zip archive naming fix

Layer / File(s) Summary
getZipArchiveName dotfile guard and tests
src/internal/file_operations_compress.go, src/internal/file_operation_compress_test.go
getZipArchiveName adds logic to detect when extension-stripping yields an empty or dot-only basename and uses the original base as fallback, ensuring .test.test.zip; TestGetZipArchiveName validates this and the existing cases with subtests.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐇 A dotfile once zipped to a name with no flair,
Just .zip appeared — barely a name was there!
Now stripped and then checked, with a fallback in place,
.test becomes .test.zip with style and grace.
Hop hop, little fix — the archive looks right! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main fix: preserving dotfile names when generating zip archives, directly addressing the bug reported in #1470.
Linked Issues check ✅ Passed The code changes fully address #1470 by implementing a fallback mechanism in getZipArchiveName to preserve dotfile identifiers and adding comprehensive test coverage.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the dotfile compression bug; no out-of-scope modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@xelavopelk

Copy link
Copy Markdown
Contributor

the bug is popular
#1475

@yorukot

yorukot commented Jun 19, 2026

Copy link
Copy Markdown
Owner

This issue has been fixed by @xelavopelk in #1475. But still, thanks for your effort!

@yorukot yorukot closed this Jun 19, 2026
@yorukot yorukot reopened this Jun 19, 2026
@yorukot

yorukot commented Jun 19, 2026

Copy link
Copy Markdown
Owner

I noticed that the previous fix doesn't cover the test edge case. I’d love to go ahead and merge your PR, so could you please take a look and resolve the conflict? Thanks!

@xelavopelk

Copy link
Copy Markdown
Contributor

@toller892 , your solution is the best! Just resolve merge conflict!

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

Labels

awaiting pr review test related PR / Issue related to testcases or testing in general.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect name for a compressed dot file/dir

3 participants