From 42a98f569cd2a630a5fb330ea52c629d6b9c70c2 Mon Sep 17 00:00:00 2001 From: Jared Davenport Date: Tue, 30 Dec 2025 07:21:35 +0800 Subject: [PATCH 1/3] walk and process TGZ path(s) async --- go.sum | 2 - internal/archive/targz.go | 110 +++++++++++++++++------------ internal/shorthand/env_var_test.go | 2 +- 3 files changed, 64 insertions(+), 50 deletions(-) diff --git a/go.sum b/go.sum index 727b717..87a9f4d 100644 --- a/go.sum +++ b/go.sum @@ -12,8 +12,6 @@ github.com/h2non/filetype v1.1.3 h1:FKkx9QbD7HR/zjK1Ia5XiBsq9zdLi5Kf3zGyFTAFkGg= github.com/h2non/filetype v1.1.3/go.mod h1:319b3zT68BvV+WRj7cwy856M2ehB3HqNOt6sy1HndBY= github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= -github.com/hathora/cloud-sdk-go/hathoracloud v0.12.0 h1:Fb4uTDn3J1FdZiA6TFuwV2ySwkH3QNHKDr1eGA/p8Qc= -github.com/hathora/cloud-sdk-go/hathoracloud v0.12.0/go.mod h1:16HoEwQ/NvaC4+tG6aHHTbgAUm3UP1cQ7cJtZ+RwUZQ= github.com/hathora/cloud-sdk-go/hathoracloud v0.13.0 h1:002OLIIPPv43XAgfBl0D+A3l+1GgI7Kfw2nASbGcDYU= github.com/hathora/cloud-sdk-go/hathoracloud v0.13.0/go.mod h1:16HoEwQ/NvaC4+tG6aHHTbgAUm3UP1cQ7cJtZ+RwUZQ= github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= diff --git a/internal/archive/targz.go b/internal/archive/targz.go index 0e3b26b..a70fabb 100644 --- a/internal/archive/targz.go +++ b/internal/archive/targz.go @@ -13,6 +13,7 @@ import ( "github.com/boyter/gocodewalker" "github.com/h2non/filetype" "go.uber.org/zap" + "golang.org/x/sync/errgroup" ) type TGZFile struct { @@ -45,59 +46,74 @@ func CreateTGZ(srcFolder string, ext string) (string, error) { return false }) - err = walker.Start() - if err != nil { - return "", fmt.Errorf("error walking directory: %w", err) - } - - for path := range paths { - - info, err := os.Stat(path.Location) - if err != nil { - return "", fmt.Errorf("error statting file: %w", err) - } - - if !info.Mode().IsRegular() { - continue - } - - relPath, err := filepath.Rel(srcFolder, path.Location) - if err != nil { - return "", fmt.Errorf("error getting relative path: %w", err) - } - - zap.L().Debug("Considering file: " + relPath) - - header, err := tar.FileInfoHeader(info, "") - if err != nil { - return "", fmt.Errorf("error creating tar file info header: %w", err) - } - header.Name = filepath.ToSlash(relPath) - - if err := tarWriter.WriteHeader(header); err != nil { - return "", err - } + var eg errgroup.Group - if info.IsDir() { - zap.L().Debug("Including directory reference: " + relPath) - continue - } + eg.Go(func() error { + return walker.Start() + }) - file, err := os.Open(path.Location) - if err != nil { - return "", fmt.Errorf("error opening file: %w", err) + processFiles := func() error { + for path := range paths { + info, err := os.Stat(path.Location) + if err != nil { + return fmt.Errorf("error statting file: %w", err) + } + + if !info.Mode().IsRegular() { + continue + } + + relPath, err := filepath.Rel(srcFolder, path.Location) + if err != nil { + return fmt.Errorf("error getting relative path: %w", err) + } + + zap.L().Debug("Considering file: " + relPath) + + header, err := tar.FileInfoHeader(info, "") + if err != nil { + return fmt.Errorf("error creating tar file info header: %w", err) + } + header.Name = filepath.ToSlash(relPath) + + if err := tarWriter.WriteHeader(header); err != nil { + return err + } + + if info.IsDir() { + zap.L().Debug("Including directory reference: " + relPath) + continue + } + + file, err := os.Open(path.Location) + if err != nil { + return fmt.Errorf("error opening file: %w", err) + } + + written, err := io.Copy(tarWriter, file) + file.Close() + if err != nil { + return fmt.Errorf("error copying file content for %s: %w", path.Location, err) + } + if written != info.Size() { + return fmt.Errorf("expected to write %d bytes but wrote %d bytes for file %s", info.Size(), written, path.Location) + } + + zap.L().Debug("Including file: " + relPath) } - defer file.Close() + return nil + } - written, err := io.Copy(tarWriter, file) - if err != nil { - return "", fmt.Errorf("error copying file content for %s: %w", path.Location, err) - } - if written != info.Size() { - return "", fmt.Errorf("expected to write %d bytes but wrote %d bytes for file %s", info.Size(), written, path.Location) + if err := processFiles(); err != nil { + walker.Terminate() + for range paths { // drain } + eg.Wait() + return "", err + } - zap.L().Debug("Including file: " + relPath) + if err := eg.Wait(); err != nil { + return "", err } return tarGzFile.Name(), nil diff --git a/internal/shorthand/env_var_test.go b/internal/shorthand/env_var_test.go index a762a36..685748b 100644 --- a/internal/shorthand/env_var_test.go +++ b/internal/shorthand/env_var_test.go @@ -45,7 +45,7 @@ func Test_DeploymentEnvVarShorthand(t *testing.T) { }, { name: "nested flag", - input: `KEY=-SomeFlag="With Spaces,And Commas"`, + input: `MAVERICK_MAP_OVERRIDE=/MAP_Hangman/Hangman_Main?game=/Script/Engine.GameModeBase`, expect: &components.DeploymentConfigV3Env{ Name: "KEY", Value: `-SomeFlag="With Spaces,And Commas"`, From bbded4adddf85f5bd515b6654fe47ab2ddd2f2db Mon Sep 17 00:00:00 2001 From: Jared Davenport Date: Tue, 30 Dec 2025 07:48:04 +0800 Subject: [PATCH 2/3] do nothing with this --- internal/archive/targz.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/archive/targz.go b/internal/archive/targz.go index a70fabb..3943cf5 100644 --- a/internal/archive/targz.go +++ b/internal/archive/targz.go @@ -108,7 +108,7 @@ func CreateTGZ(srcFolder string, ext string) (string, error) { walker.Terminate() for range paths { // drain } - eg.Wait() + _ = eg.Wait() return "", err } From 8df151ee08d0dd69cf873556be2ca0c83a405c24 Mon Sep 17 00:00:00 2001 From: Jared Davenport Date: Tue, 30 Dec 2025 07:58:33 +0800 Subject: [PATCH 3/3] revert this --- internal/shorthand/env_var_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/shorthand/env_var_test.go b/internal/shorthand/env_var_test.go index 685748b..a762a36 100644 --- a/internal/shorthand/env_var_test.go +++ b/internal/shorthand/env_var_test.go @@ -45,7 +45,7 @@ func Test_DeploymentEnvVarShorthand(t *testing.T) { }, { name: "nested flag", - input: `MAVERICK_MAP_OVERRIDE=/MAP_Hangman/Hangman_Main?game=/Script/Engine.GameModeBase`, + input: `KEY=-SomeFlag="With Spaces,And Commas"`, expect: &components.DeploymentConfigV3Env{ Name: "KEY", Value: `-SomeFlag="With Spaces,And Commas"`,