Skip to content

Commit

Permalink
Copy all the files concurrently (Linux too)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjcdawkins committed Jan 10, 2025
1 parent acb945f commit 9a4d3ba
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions internal/legacy/legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"path/filepath"

"github.com/gofrs/flock"
"golang.org/x/sync/errgroup"

"github.com/platformsh/cli/internal/config"
"github.com/platformsh/cli/internal/file"
Expand Down Expand Up @@ -75,20 +76,28 @@ func (c *CLIWrapper) init() error {
c.debugLog("lock acquired: %s", fileLock.Path())
defer fileLock.Unlock() //nolint:errcheck

if err := file.CopyIfChanged(c.pharPath(cacheDir), phar, 0o644); err != nil {
return fmt.Errorf("could not copy phar file: %w", err)
}

// Always write the config.yaml file if it changed.
configContent, err := config.LoadYAML()
if err != nil {
return fmt.Errorf("could not load config for checking: %w", err)
}
if err := file.CopyIfChanged(filepath.Join(cacheDir, configBasename), configContent, 0o644); err != nil {
return fmt.Errorf("could not write config: %w", err)
}
g := errgroup.Group{}
g.Go(func() error {
if err := file.CopyIfChanged(c.pharPath(cacheDir), phar, 0o644); err != nil {
return fmt.Errorf("could not copy phar file: %w", err)
}
return nil
})
g.Go(func() error {
configContent, err := config.LoadYAML()
if err != nil {
return fmt.Errorf("could not load config for checking: %w", err)
}
if err := file.CopyIfChanged(filepath.Join(cacheDir, configBasename), configContent, 0o644); err != nil {
return fmt.Errorf("could not write config: %w", err)
}
return nil
})
g.Go(func() error {
return c.copyPHP(cacheDir)
})

return c.copyPHP(cacheDir)
return g.Wait()
}

// Exec a legacy CLI command with the given arguments
Expand Down

0 comments on commit 9a4d3ba

Please sign in to comment.