77 "errors"
88 "log"
99 "os"
10+ "time"
1011
1112 "github.com/google/uuid"
1213)
@@ -27,24 +28,27 @@ func CreateFile(input models.CodeFiles, Folder string, Content []byte) (models.C
2728 var existingFile models.CodeFiles
2829 database .DBConn .Where ("environment_id = ? and node_id =? and file_name = ?" , input .EnvironmentID , input .NodeID , input .FileName ).First (& existingFile )
2930
30- if _ , err := os .Stat (config .CodeDirectory + Folder ); os .IsNotExist (err ) {
31+ // -------- if LocalFile --------
32+ if config .FSCodeFileStorage == "LocalFile" {
33+ if _ , err := os .Stat (config .CodeDirectory + Folder ); os .IsNotExist (err ) {
3134
32- if config .Debug == "true" {
33- log .Println ("Directory doesnt exists: " , config .CodeDirectory + Folder )
34- return input , returnpath , errors .New ("Directory doesnt exists" )
35- }
35+ if config .Debug == "true" {
36+ log .Println ("Directory doesnt exists: " , config .CodeDirectory + Folder )
37+ return input , returnpath , errors .New ("Directory doesnt exists" )
38+ }
3639
37- } else {
40+ } else {
3841
39- err := os .WriteFile (createFile , Content , 0644 )
40- if err != nil {
41- return input , returnpath , errors .New ("Failed to write file" )
42- }
42+ err := os .WriteFile (createFile , Content , 0644 )
43+ if err != nil {
44+ return input , returnpath , errors .New ("Failed to write file" )
45+ }
4346
44- if config .Debug == "true" {
45- log .Println ("Created file: " , createFile )
46- }
47+ if config .Debug == "true" {
48+ log .Println ("Created file: " , createFile )
49+ }
4750
51+ }
4852 }
4953
5054 // Create record if doesnt exist
@@ -58,6 +62,8 @@ func CreateFile(input models.CodeFiles, Folder string, Content []byte) (models.C
5862 }
5963
6064 }
65+ } else {
66+ database .DBConn .Model (& models.CodeFiles {}).Where ("file_id = ?" , existingFile .FileID ).Update ("updated_at" , time .Now ().UTC ())
6167 }
6268
6369 return input , returnpath , nil
0 commit comments