From 1fb13347a7207a05340d056380488f461312431f Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Mon, 13 Jan 2025 17:16:27 +0000 Subject: [PATCH] fix split files Signed-off-by: Austin Abro --- src/internal/packager2/layout/create.go | 2 +- src/internal/packager2/layout/package.go | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/internal/packager2/layout/create.go b/src/internal/packager2/layout/create.go index d459fc8e72..8f2429fab8 100644 --- a/src/internal/packager2/layout/create.go +++ b/src/internal/packager2/layout/create.go @@ -953,7 +953,7 @@ func splitFile(srcPath string, chunkSize int) (err error) { // iteration as soon as we're done writing. for { path := fmt.Sprintf("%s.part%03d", srcPath, fileCount+1) - dstFile, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR, helpers.ReadAllWriteUser) + dstFile, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR|os.O_TRUNC, helpers.ReadAllWriteUser) if err != nil { return err } diff --git a/src/internal/packager2/layout/package.go b/src/internal/packager2/layout/package.go index a6178604a9..402a65140c 100644 --- a/src/internal/packager2/layout/package.go +++ b/src/internal/packager2/layout/package.go @@ -224,7 +224,18 @@ func (p *PackageLayout) Archive(ctx context.Context, dirPath string, maxPackageS if fi.Size()/int64(chunkSize) > 999 { return fmt.Errorf("unable to split the package archive into multiple files: must be less than 1,000 files") } - err := splitFile(tarballPath, chunkSize) + // Remove any existing split files + existingChunks, err := filepath.Glob(tarballPath + ".part*") + if err != nil { + return err + } + for _, chunk := range existingChunks { + err := os.Remove(chunk) + if err != nil { + return fmt.Errorf("unable to remove existing chunk file %s: %w", chunk, err) + } + } + err = splitFile(tarballPath, chunkSize) if err != nil { return fmt.Errorf("unable to split the package archive into multiple files: %w", err) }