feat: file permission.

This commit is contained in:
2026-04-28 21:09:27 +08:00
parent f6c06bd7ad
commit 641703ca69
5 changed files with 53 additions and 1 deletions
+9 -1
View File
@@ -74,8 +74,11 @@ func (lc *LessonPlanController) Upload(c *gin.Context) {
return
}
tempPath := tempFile.Name()
tempClosed := false
defer func() {
_ = tempFile.Close()
if !tempClosed {
_ = tempFile.Close()
}
if _, statErr := os.Stat(tempPath); statErr == nil {
_ = os.Remove(tempPath)
}
@@ -104,6 +107,11 @@ func (lc *LessonPlanController) Upload(c *gin.Context) {
storedFilename := buildStoredLessonPlanFilename(md5Value, fileHeader.Filename)
finalPath := filepath.Join(lessonPlanStorageDir, storedFilename)
if err := tempFile.Close(); err != nil {
writeError(c, http.StatusInternalServerError, "failed to finalize upload")
return
}
tempClosed = true
if err := os.Rename(tempPath, finalPath); err != nil {
writeError(c, http.StatusInternalServerError, "failed to finalize upload")
return