File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,18 +18,23 @@ func Edit(path myS3.Path, params *config.AWSParams) {
1818
1919 object := myS3 .GetObject (svc , path )
2020
21- tempfilePath := createTempfile (path , object .Body )
22- defer os .Remove ( tempfilePath )
21+ tempDirPath , tempfilePath := createTempfile (path , object .Body )
22+ defer os .RemoveAll ( tempDirPath )
2323
2424 editedBody := editFile (tempfilePath )
2525 object .Body = []byte (editedBody )
2626 myS3 .PutObject (svc , path , object )
2727}
2828
29- func createTempfile (path myS3.Path , body []byte ) (tempfilePath string ) {
29+ func createTempfile (path myS3.Path , body []byte ) (tempDirPath string , tempfilePath string ) {
30+ tempDirPath , err := ioutil .TempDir ("/tmp" , "s3-edit" )
31+ if err != nil {
32+ fmt .Println (err )
33+ os .Exit (1 )
34+ }
3035 keys := strings .Split (path .Key , "/" )
3136 fileName := keys [len (keys )- 1 ]
32- tempfilePath = "/tmp /" + fileName
37+ tempfilePath = tempDirPath + " /" + fileName
3338
3439 if err := ioutil .WriteFile (tempfilePath , body , os .ModePerm ); err != nil {
3540 fmt .Println (err )
You can’t perform that action at this time.
0 commit comments