Skip to content

fix: skip chmod for existing SaveUploadedFile destination directories#4647

Open
mike-lmctl wants to merge 1 commit into
gin-gonic:masterfrom
mike-lmctl:fix-saveuploadedfile-existing-dir-perms
Open

fix: skip chmod for existing SaveUploadedFile destination directories#4647
mike-lmctl wants to merge 1 commit into
gin-gonic:masterfrom
mike-lmctl:fix-saveuploadedfile-existing-dir-perms

Conversation

@mike-lmctl
Copy link
Copy Markdown

Fixes SaveUploadedFile so it no longer changes permissions on destination
directories that already exist. It still creates and applies the requested mode
to directories that Gin creates for the upload path.

The package tests pass in a Go 1.25 Docker container.

When SaveUploadedFile targets a path under an existing directory, applying
the optional permission mode to that existing directory can fail despite
the file creation itself being allowed. This change only creates and chmods
the destination directory when it does not already exist.

The permission tests now cover both newly created upload directories and
existing destination directories whose mode should be preserved.

Tested: docker run --rm --user "$(id -u):$(id -g)" -e GOMODCACHE=/tmp/gomodcache -e GOCACHE=/tmp/gocache -v "$PWD":/src -w /src golang:1.25.0 go test . -count=1
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.

1 participant