Skip to content

Commit

Permalink
fix split files
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Abro <[email protected]>
  • Loading branch information
AustinAbro321 committed Jan 13, 2025
1 parent 1a01ac1 commit 1fb1334
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/internal/packager2/layout/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
13 changes: 12 additions & 1 deletion src/internal/packager2/layout/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 1fb1334

Please sign in to comment.