From c7e084050ab109710b2683441aae5ddc543bfc72 Mon Sep 17 00:00:00 2001 From: Jerico Pena Date: Sat, 23 Aug 2025 16:35:10 -0400 Subject: [PATCH] Copy offline dependencies instead of moving This is needed for multi-arch dependencies such as noarch or buildling from source where the same files are used on multiple platforms --- commands/pack.go | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/commands/pack.go b/commands/pack.go index b0c806e..b9d3281 100644 --- a/commands/pack.go +++ b/commands/pack.go @@ -2,6 +2,7 @@ package commands import ( "fmt" + "io" "os" "path/filepath" "runtime" @@ -191,9 +192,9 @@ func packRun(flags packFlags) error { return fmt.Errorf("failed to create platform specific dependencies directory: %s", err) } - err = os.Rename(filepath.Join(tmpDir, offlinePath), filepath.Join(tmpDir, targetPlatformDir, dependenciesDir, offlineFilename)) + _, err = copyFile(filepath.Join(tmpDir, offlinePath), filepath.Join(tmpDir, targetPlatformDir, dependenciesDir, offlineFilename)) if err != nil { - return fmt.Errorf("failed to move offline dependency to platform specific directory: %s", err) + return fmt.Errorf("failed to copy offline dependency to platform specific directory: %s", err) } config.Metadata.IncludeFiles = append(config.Metadata.IncludeFiles, filepath.Join(targetPlatformDir, dependenciesDir, offlineFilename)) @@ -302,3 +303,36 @@ func archFromSystem() string { return runtime.GOARCH } + +func copyFile(src string, dst string) (int64, error) { + sourceFileStat, err := os.Stat(src) + if err != nil { + return 0, err + } + if !sourceFileStat.Mode().IsRegular() { + return 0, fmt.Errorf("%s is not a regular file", src) + } + + source, err := os.Open(src) + if err != nil { + return 0, err + } + defer func() { + if err2 := source.Close(); err2 != nil && err == nil { + err = err2 + } + }() + + destination, err := os.Create(dst) + if err != nil { + return 0, err + } + defer func() { + if err2 := destination.Close(); err2 != nil && err == nil { + err = err2 + } + }() + + nBytes, err := io.Copy(destination, source) + return nBytes, err +}