Skip to content

Commit

Permalink
Don't full remove unzip dir on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
JackDallas committed Jun 26, 2022
1 parent 802eeed commit d9bd141
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
11 changes: 3 additions & 8 deletions internal/service/transfer_manager_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,12 @@ func (t *TransferManagerService) CleanUpUnzipDir() {
return
}

err = os.RemoveAll(unzipBase)
err = utils.RemoveContents(unzipBase)
if err != nil {
log.Errorf("Error removing unzip base location: %s", err.Error())
return
}

err = os.MkdirAll(unzipBase, 0755)
if err != nil {
log.Errorf("Error creating unzip base location: %s", err.Error())
log.Errorf("Error cleaning unzip directory: %s", err.Error())
return
}

}

func (manager *TransferManagerService) ConfigUpdatedCallback(currentConfig config.Config, newConfig config.Config) {
Expand Down
20 changes: 20 additions & 0 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,23 @@ func IsDirectoryWriteable(path string) bool {

return true
}

//https://stackoverflow.com/questions/33450980/how-to-remove-all-contents-of-a-directory-using-golang
func RemoveContents(dir string) error {
d, err := os.Open(dir)
if err != nil {
return err
}
defer d.Close()
names, err := d.Readdirnames(-1)
if err != nil {
return err
}
for _, name := range names {
err = os.RemoveAll(filepath.Join(dir, name))
if err != nil {
return err
}
}
return nil
}

0 comments on commit d9bd141

Please sign in to comment.