Skip to content

Commit

Permalink
Merge pull request #254 from williambrode/cleanDirPerformance
Browse files Browse the repository at this point in the history
Performance improvement by avoiding running commands in docker
  • Loading branch information
Bluebugs committed Jul 13, 2024
2 parents 187fb53 + c870d6b commit c007692
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions internal/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,18 @@ Use "fyne-cross <command> -help" for more information about a command.
func cleanTargetDirs(ctx Context, image containerImage) error {

dirs := map[string]string{
"bin": volume.JoinPathContainer(ctx.BinDirContainer(), image.ID()),
"dist": volume.JoinPathContainer(ctx.DistDirContainer(), image.ID()),
"temp": volume.JoinPathContainer(ctx.TmpDirContainer(), image.ID()),
"bin": volume.JoinPathHost(ctx.Volume.BinDirHost(), image.ID()),
"dist": volume.JoinPathHost(ctx.Volume.DistDirHost(), image.ID()),
"temp": volume.JoinPathHost(ctx.Volume.TmpDirHost(), image.ID()),
}

log.Infof("[i] Cleaning target directories...")
for k, v := range dirs {
err := image.Run(ctx.Volume, options{}, []string{"rm", "-rf", v})
if err != nil {
if err := os.RemoveAll(v); err != nil {
return fmt.Errorf("could not clean the %q dir %s: %v", k, v, err)
}

err = image.Run(ctx.Volume, options{}, []string{"mkdir", "-p", v})
if err != nil {
if err := os.MkdirAll(v, os.ModePerm); err != nil {
return fmt.Errorf("could not create the %q dir %s: %v", k, v, err)
}

Expand Down Expand Up @@ -142,10 +140,12 @@ func prepareIcon(ctx Context, image containerImage) error {
}
}

err := image.Run(ctx.Volume, options{}, []string{"cp", volume.JoinPathContainer(ctx.WorkDirContainer(), ctx.Icon), volume.JoinPathContainer(ctx.TmpDirContainer(), image.ID(), icon.Default)})
if err != nil {
return fmt.Errorf("could not copy the icon to temp folder: %v", err)
if data, err := os.ReadFile(volume.JoinPathHost(ctx.Volume.WorkDirHost(), ctx.Icon)); err != nil {
return fmt.Errorf("could not read in icon %s: %w", ctx.Icon, err)
} else if err := os.WriteFile(volume.JoinPathHost(ctx.TmpDirHost(), image.ID(), icon.Default), data, 0644); err != nil {
return fmt.Errorf("could not copy icon %s to tmp folder: %w", ctx.Icon, err)
}

return nil
}

Expand Down

0 comments on commit c007692

Please sign in to comment.