Skip to content

Commit 9d4c645

Browse files
committed
handle errors during file handle closure
1 parent 2dff1e2 commit 9d4c645

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

cmd/cloudexec/push.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,19 @@ func UploadDirectoryToSpaces(config config.Config, bucket string, sourcePath str
8080
return err
8181
}
8282

83+
// Explicitly close the file once we're done to prevent a "too many open files" error
84+
err = file.Close()
85+
if err != nil {
86+
return err
87+
}
88+
8389
// Write this file to the zipped archive
8490
_, err = io.Copy(zipFileEntry, file)
8591
if err != nil {
8692
return err
8793
}
88-
8994
file.Close()
95+
9096
return nil
9197
})
9298
if err != nil {
@@ -106,8 +112,14 @@ func UploadDirectoryToSpaces(config config.Config, bucket string, sourcePath str
106112
}
107113

108114
// Manually Closing is necessary to prevent zip file corruption during upload
109-
zipWriter.Close()
110-
zipFile.Close()
115+
err = zipWriter.Close()
116+
if err != nil {
117+
return err
118+
}
119+
err = zipFile.Close()
120+
if err != nil {
121+
return err
122+
}
111123

112124
// Read the zipped archive
113125
fileBytes, err := os.ReadFile(zipFilePath)

0 commit comments

Comments
 (0)