fix: use os.IsNotExist for precise check, remove redundant cleanup

Agent-Logs-Url: https://github.com/odlev/gin/sessions/2d0f57ad-a46e-45f6-a2f2-b6d4c352f22e

Co-authored-by: odlev <65655276+odlev@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-04-07 20:38:20 +00:00 committed by GitHub
parent 592a2d08c2
commit f86381e7ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 1 additions and 4 deletions

View File

@ -734,7 +734,7 @@ func (c *Context) SaveUploadedFile(file *multipart.FileHeader, dst string, perm
} }
// Only chmod newly created directories to avoid "operation not permitted" // Only chmod newly created directories to avoid "operation not permitted"
// errors on pre-existing directories we may not own (e.g., /tmp). // errors on pre-existing directories we may not own (e.g., /tmp).
if statErr != nil { if os.IsNotExist(statErr) {
if err = os.Chmod(dir, mode); err != nil { if err = os.Chmod(dir, mode); err != nil {
return err return err
} }

View File

@ -294,9 +294,6 @@ func TestSaveUploadedFileToExistingDir(t *testing.T) {
dir := t.TempDir() dir := t.TempDir()
dst := filepath.Join(dir, "uploaded.txt") dst := filepath.Join(dir, "uploaded.txt")
require.NoError(t, c.SaveUploadedFile(f, dst)) require.NoError(t, c.SaveUploadedFile(f, dst))
t.Cleanup(func() {
os.Remove(dst)
})
} }
func TestContextReset(t *testing.T) { func TestContextReset(t *testing.T) {