Skip to content

Commit

Permalink
fix windows issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jkroepke committed Jul 30, 2024
1 parent 5943e85 commit 2c39a60
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions internal/provider/tar_archiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type TarArchiver struct {
compression TarCompressionType
filepath string
outputFileMode string // Default value "" means unset
filewriter *os.File
fileWriter *os.File
tarWriter *tar.Writer
compressionWriter io.WriteCloser
}
Expand Down Expand Up @@ -215,33 +215,44 @@ func (a *TarArchiver) SetOutputFileMode(outputFileMode string) {
}

func (a *TarArchiver) open() error {
file, err := os.Create(filepath.ToSlash(a.filepath))
var err error

a.fileWriter, err = os.Create(filepath.ToSlash(a.filepath))
if err != nil {
return err
}

switch a.compression {
case TarCompressionGz:
a.compressionWriter = gzip.NewWriter(file)
a.compressionWriter = gzip.NewWriter(a.fileWriter)
}

a.tarWriter = tar.NewWriter(a.compressionWriter)
return nil
}

func (a *TarArchiver) close() {
if a.filewriter != nil {
a.filewriter.Close()
a.filewriter = nil
}
if a.tarWriter != nil {
a.tarWriter.Close()
err := a.tarWriter.Close()
if err != nil {
fmt.Printf("error closing tarwriter : %s\n\n", err)
}
a.tarWriter = nil
}
if a.compressionWriter != nil {
a.compressionWriter.Close()
err := a.compressionWriter.Close()
if err != nil {
fmt.Printf("error closing compressionWriter : %s\n\n", err)
}
a.compressionWriter = nil
}
if a.fileWriter != nil {
err := a.fileWriter.Close()
if err != nil {
fmt.Printf("error closing fileWriter: %s\n\n", err)
}
a.fileWriter = nil
}
}

func (a *TarArchiver) addFile(filePath string, header *tar.Header) error {
Expand Down

0 comments on commit 2c39a60

Please sign in to comment.