mirror of
https://github.com/gin-gonic/gin.git
synced 2026-06-05 10:28:21 +08:00
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:
parent
592a2d08c2
commit
f86381e7ad
@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user