Skip to content

Commit

Permalink
Do not overwrite assets if they already exist
Browse files Browse the repository at this point in the history
  • Loading branch information
DonnchaC committed Dec 19, 2023
1 parent 16c2e17 commit ef64791
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions acquisition/acquisition.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ func (a *Acquisition) Complete() {
a.Collector.Clean()
}

// Stop ADB server before trying to remove extracted assets
adb.Client.KillServer()
assets.CleanAssets()
}

Expand Down
15 changes: 14 additions & 1 deletion assets/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package assets
import (
"embed"
"os"
"errors"
"path/filepath"

saveRuntime "github.com/botherder/go-savetime/runtime"
Expand All @@ -27,7 +28,19 @@ func DeployAssets() error {

for _, asset := range getAssets() {
assetPath := filepath.Join(cwd, asset.Name)
err := os.WriteFile(assetPath, asset.Data, 0o755)

assetFile, err := os.OpenFile(assetPath, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0o755)
if err != nil {
// Asset file already exists. Do not try overwriting
if (errors.Is(err, os.ErrExist)) {
continue
} else {
return err
}
}
defer assetFile.Close()

_, err = assetFile.Write(asset.Data)
if err != nil {
return err
}
Expand Down

0 comments on commit ef64791

Please sign in to comment.