Skip to content

Commit

Permalink
Fix OpenFile flags to avoid garbled files
Browse files Browse the repository at this point in the history
  • Loading branch information
jcaamano committed Mar 5, 2021
1 parent 567c991 commit cd0aaca
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/charts/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func UpdateHelmMetadataWithDependencies(fs billy.Filesystem, mainHelmChartPath s
if !exists {
file, err = filesystem.CreateFileAndDirs(fs, path)
} else {
file, err = fs.OpenFile(path, os.O_RDWR, os.ModePerm)
file, err = fs.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, os.ModePerm)
}
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions pkg/filesystem/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func CopyFile(fs billy.Filesystem, srcPath string, dstPath string) error {
if !dstExists {
dstFile, err = CreateFileAndDirs(fs, dstPath)
} else {
dstFile, err = fs.OpenFile(dstPath, os.O_WRONLY, os.ModePerm)
dstFile, err = fs.OpenFile(dstPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.ModePerm)
}
if err != nil {
return err
Expand Down Expand Up @@ -184,7 +184,7 @@ func UnarchiveTgz(fs billy.Filesystem, tgzPath, tgzSubdirectory, destPath string
}
}
// Check if you can open the tgzPath as a tar file
tgz, err := fs.OpenFile(tgzPath, os.O_RDWR, os.ModePerm)
tgz, err := fs.OpenFile(tgzPath, os.O_RDONLY, os.ModePerm)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/helm/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func UpdateHelmMetadataWithName(fs billy.Filesystem, mainHelmChartPath string, n
if err != nil {
return err
}
file, err := fs.OpenFile(path, os.O_RDWR, os.ModePerm)
file, err := fs.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, os.ModePerm)
if err != nil {
return err
}
Expand Down Expand Up @@ -65,7 +65,7 @@ func TrimRCVersionFromHelmChart(fs billy.Filesystem, mainHelmChartPath string) e
if err != nil {
return err
}
file, err := fs.OpenFile(path, os.O_RDWR, os.ModePerm)
file, err := fs.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, os.ModePerm)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/options/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (c ChartOptions) WriteToFile(fs billy.Filesystem, path string) error {
if !exists {
file, err = filesystem.CreateFileAndDirs(fs, path)
} else {
file, err = fs.OpenFile(path, os.O_RDWR, os.ModePerm)
file, err = fs.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, os.ModePerm)
}
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/options/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (p PackageOptions) WriteToFile(fs billy.Filesystem, path string) error {
if !exists {
file, err = filesystem.CreateFileAndDirs(fs, path)
} else {
file, err = fs.OpenFile(path, os.O_RDWR, os.ModePerm)
file, err = fs.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, os.ModePerm)
}
if err != nil {
return err
Expand Down

0 comments on commit cd0aaca

Please sign in to comment.