diff --git a/context.go b/context.go index d541e50b..8014d4bc 100644 --- a/context.go +++ b/context.go @@ -734,7 +734,7 @@ func (c *Context) SaveUploadedFile(file *multipart.FileHeader, dst string, perm } // Only chmod newly created directories to avoid "operation not permitted" // 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 { return err } diff --git a/context_test.go b/context_test.go index 79d72275..2a3ce70f 100644 --- a/context_test.go +++ b/context_test.go @@ -294,9 +294,6 @@ func TestSaveUploadedFileToExistingDir(t *testing.T) { dir := t.TempDir() dst := filepath.Join(dir, "uploaded.txt") require.NoError(t, c.SaveUploadedFile(f, dst)) - t.Cleanup(func() { - os.Remove(dst) - }) } func TestContextReset(t *testing.T) {