feat: file permission.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user