diff --git a/Makefile b/Makefile index 050269d..1ccd440 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -TAG ?= v1.1.12 +TAG ?= v1.1.13 IMAGE_TAG ?= docker.educg.net/cg/k8s-manager:$(TAG) build: export CGO_ENABLED=0 diff --git a/src/persistent_file_manager.go b/src/persistent_file_manager.go index 0c47962..d08a059 100644 --- a/src/persistent_file_manager.go +++ b/src/persistent_file_manager.go @@ -16,9 +16,11 @@ func GetFiles(c *gin.Context) { dirPath := path.Join(config.NFSPath, username, appName) dir, err := os.ReadDir(dirPath) if err != nil { - log.WithError(err).Error("Cannot ReadDir ", dirPath) - c.JSON(http.StatusBadRequest, gin.H{"ok": false, "msg": err}) - return + if !os.IsNotExist(err) { + log.WithError(err).Error("Cannot ReadDir ", dirPath) + c.JSON(http.StatusBadRequest, gin.H{"ok": false, "msg": err}) + return + } } c.JSON(http.StatusOK, gin.H{"ok": true, "files": funk.Map(dir, func(d fs.DirEntry) string { return d.Name() }).([]string)}) } @@ -27,6 +29,7 @@ func GetPostOrDeleteFile(c *gin.Context) { username := c.MustGet("username").(string) appName := c.Param("app") fileName := c.Param("filename") + dirPath := path.Join(config.NFSPath, username, appName) filePath := path.Join(config.NFSPath, username, appName, fileName) if c.Request.Method == http.MethodGet { c.FileAttachment(filePath, fileName) @@ -37,6 +40,12 @@ func GetPostOrDeleteFile(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"ok": false, "msg": err}) return } + if _, err := os.Stat(dirPath); os.IsNotExist(err) { + err := os.MkdirAll(dirPath, 0777) + if err != nil { + log.WithError(err).Error("GetPostOrDeleteFile: Make nfs dir error") + } + } err = c.SaveUploadedFile(file, filePath) if err != nil { log.WithError(err).Error("GetPostOrDeleteFile: Save file error")