Repository navigation
fix(fs): don't remove stale compressed files of a custom FS.FS from disk - #2489
Merged
erikdubbelboer merged 1 commit intoOct 19, 2026
Merged
Conversation
When FS found a precompressed file in a custom FS.FS whose original was
newer, it removed the compressed file with os.Remove before compressing
again. The name is relative to the FS.FS, not to the working directory,
so this removed whatever file had the same relative name in the working
directory, and never the stale file itself unless FS.FS happened to be
os.DirFS(".").
Only remove stale compressed files for the default OS filesystem. For a
custom FS.FS the file is compressed again in memory, as before.
Collaborator
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
FS.Compressis on and a customFS.FScontains a precompressed file (for exampleapp.js.fasthttp.gz) that is older than the original,openFSFiletreats it as stale and callsos.Remove(filePath)before compressing again. For a customFS.FS,filePathis a name inside that filesystem, such asapp.js.fasthttp.gz, soos.Removeresolves it against the process working directory instead. It deletes whatever file has that name relative to the working directory, and it can't remove the stale file anyway since anfs.FSis read-only here.This change only removes the stale file for the default OS filesystem. For a custom
FS.FSthe file is compressed again in memory, which is what already happened after the removal.Behavior change
With
FS: os.DirFS(".")(or anotheros.DirFSwhose directory is the working directory), the relative name used to point at the real stale file, so it got deleted as a side effect. It now stays on disk, and a request for it is compressed in memory on each cache miss until the file is regenerated or removed by other means. Serving the default OS filesystem (FS.FSnil) is unchanged.Test
TestFSFSStaleCompressedFileNotRemovedFromDiskserves afstest.MapFSwith a freshpage.htmland an hour olderpage.html.fasthttp.gz, from a temporary working directory that holds an unrelatedpage.html.fasthttp.gz. It checks that the response is the original compressed again and that the file in the working directory is still there. It fails on master and passes with this change.Ran
go test -shuffle=on ./...on Windows and the root package on Linux,go vet ./...for windows, linux and darwin,gofmt -l ., andgolangci-lint run ./...(0 issues on linux).