Skip to content

Commit

Permalink
propagate file modes
Browse files Browse the repository at this point in the history
  • Loading branch information
ybirader committed Sep 24, 2023
1 parent 7417ee0 commit 6b734f5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Tests

on:
push:
branches:
- main
pull_request:
branches:
- main
Expand Down
34 changes: 29 additions & 5 deletions extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (e *extractor) Extract(ctx context.Context, archivePath string) (err error)
return derrors.Wrap(err, "ERROR: could not close file worker pool")
}

return err
return
}

func (e *extractor) Close() error {
Expand All @@ -90,15 +90,39 @@ func (e *extractor) Close() error {
func (e *extractor) extractFile(file *zip.File) (err error) {
outputPath := e.outputPath(file.Name)

if err = os.MkdirAll(filepath.Dir(outputPath), 0755); err != nil { // TODO: need to set correct file mode as specified by file
if err = os.MkdirAll(filepath.Dir(outputPath), 0755); err != nil {
return derrors.Errorf("ERROR: could not directories %s: %+v", outputPath, err)
}

if e.isDir(file.Name) {
return nil
if err = e.writeDir(outputPath, file); err != nil {
return derrors.Wrapf(err, "ERROR: could not write directory %s", file.Name)
}
return
}

if err = e.writeFile(outputPath, file); err != nil {
return derrors.Wrapf(err, "ERROR: could not write file %s", file.Name)
}

return
}

func (e *extractor) writeDir(outputPath string, file *zip.File) error {
err := os.Mkdir(outputPath, file.Mode())
if os.IsExist(err) {
os.Chmod(outputPath, file.Mode())
err = nil
}
if err != nil {
return derrors.Errorf("ERROR: could not create directory %s: %+v", file.Name, err)
}

outputFile, err := os.Create(e.outputPath(file.Name))
return nil
}

func (e *extractor) writeFile(outputPath string, file *zip.File) (err error) {
outputFile, err := os.OpenFile(outputPath, os.O_CREATE|os.O_WRONLY, file.Mode())
if err != nil {
return derrors.Errorf("ERROR: could not create file %s: %v", outputPath, err)
}
Expand All @@ -119,7 +143,7 @@ func (e *extractor) extractFile(file *zip.File) (err error) {
return derrors.Errorf("ERROR: could not decompress file %s", file.Name)
}

return nil
return
}

func (e *extractor) isDir(name string) bool {
Expand Down

0 comments on commit 6b734f5

Please sign in to comment.