Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/codetests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ jobs:
go-version: stable
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
uses: golangci/golangci-lint-action@v7
with:
version: v1.59
version: v2.0
# Runs golangci-lint on linux against linux and windows.
golangci-linux:
strategy:
Expand All @@ -52,6 +52,6 @@ jobs:
go-version: stable
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
uses: golangci/golangci-lint-action@v7
with:
version: v1.59
version: v2.0
64 changes: 44 additions & 20 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,55 @@
run:
timeout: 1m

version: "2"
linters:
enable-all: true
default: all
disable:
# deprecated
- gomnd
- execinquery
# unused
- nlreturn
- exhaustruct
- depguard
- nonamedreturns
exclusions:
rules:
- linters:
- funlen
- goconst
- wsl
- errcheck
path: .+_test.go

output:
sort-results: true
settings:
gosec:
excludes:
- G304
gocritic:
enable-all: true
disabled-checks:
- whyNoLint
- commentedOutCode
settings:
unnamedResult:
checkExported: true
errcheck:
check-type-assertions: true
check-blank: true
disable-default-exclusions: true
exclude-functions:
- (*os.File).Close
- os.RemoveAll
- os.Remove
- (io.Closer).Close
- (*compress/gzip.Reader).Close
- (*archive/zip.ReadCloser).Close
- (*github.com/bodgit/sevenzip.ReadCloser).Close
- (*github.com/nwaples/rardecode.ReadCloser).Close

issues:
# disable the default limit so we see everything
max-same-issues: 0
max-issues-per-linter: 0

# default enable fix where the linter supports
max-same-issues: 0
fix: true
exclude-rules:
# Exclude some linters from testing files.
- linters:
- goconst
- wsl
- funlen
path: '.+_test.go'
formatters:
enable:
- gci
- gofmt
- gofumpt
- goimports

26 changes: 16 additions & 10 deletions 7z.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

// Extract7z extracts a 7zip archive.
// Volumes: https://github.com/bodgit/sevenzip/issues/54
func Extract7z(xFile *XFile) (int64, []string, []string, error) {
func Extract7z(xFile *XFile) (size int64, filesList, archiveList []string, err error) {
if len(xFile.Passwords) == 0 && xFile.Password == "" {
return extract7z(xFile)
}
Expand Down Expand Up @@ -64,7 +64,7 @@ func extract7z(xFile *XFile) (int64, []string, []string, error) {
size := int64(0)

for _, zipFile := range sevenZip.File {
fSize, err := xFile.un7zip(zipFile)
fSize, wfile, err := xFile.un7zip(zipFile)
if err != nil {
lastFile := xFile.FilePath
/* // https://github.com/bodgit/sevenzip/issues/54
Expand All @@ -77,36 +77,42 @@ func extract7z(xFile *XFile) (int64, []string, []string, error) {

files = append(files, filepath.Join(xFile.OutputDir, zipFile.Name))
size += fSize
xFile.Debugf("Wrote archived file: %s (%d bytes), total: %d files and %d bytes", wfile, fSize, len(files), size)
}

return size, files, sevenZip.Volumes(), nil
}

func (x *XFile) un7zip(zipFile *sevenzip.File) (int64, error) { //nolint:dupl
func (x *XFile) un7zip(zipFile *sevenzip.File) (int64, string, error) {
wfile := x.clean(zipFile.Name)
if !strings.HasPrefix(wfile, x.OutputDir) {
// The file being written is trying to write outside of our base path. Malicious archive?
return 0, fmt.Errorf("%s: %w: %s (from: %s)", zipFile.FileInfo().Name(), ErrInvalidPath, wfile, zipFile.Name)
return 0, wfile, fmt.Errorf("%s: %w: %s (from: %s)", zipFile.FileInfo().Name(), ErrInvalidPath, wfile, zipFile.Name)
}

if strings.HasSuffix(wfile, "/") || zipFile.FileInfo().IsDir() {
if zipFile.FileInfo().IsDir() {
x.Debugf("Writing archived directory: %s", wfile)

if err := os.MkdirAll(wfile, x.DirMode); err != nil {
return 0, fmt.Errorf("making zipFile dir: %w", err)
return 0, wfile, fmt.Errorf("making zipFile dir: %w", err)
}

return 0, nil
return 0, wfile, nil
}

x.Debugf("Writing archived file: %s (packed: %d, unpacked: %d)",
wfile, zipFile.FileInfo().Size(), zipFile.UncompressedSize)

zFile, err := zipFile.Open()
if err != nil {
return 0, fmt.Errorf("zipFile.Open: %w", err)
return 0, wfile, fmt.Errorf("zipFile.Open: %w", err)
}
defer zFile.Close()

s, err := writeFile(wfile, zFile, x.FileMode, x.DirMode)
if err != nil {
return s, fmt.Errorf("%s: %w: %s (from: %s)", zipFile.FileInfo().Name(), err, wfile, zipFile.Name)
return s, wfile, fmt.Errorf("%s: %w: %s (from: %s)", zipFile.FileInfo().Name(), err, wfile, zipFile.Name)
}

return s, nil
return s, wfile, nil
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2020-2024 Go Lift
Copyright (c) 2020-2025 Go Lift

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
3 changes: 2 additions & 1 deletion ar.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

// ExtractAr extracts a raw ar archive. Used by debian (.deb) packages.
func ExtractAr(xFile *XFile) (int64, []string, error) {
func ExtractAr(xFile *XFile) (size int64, filesList []string, err error) {
arFile, err := os.Open(xFile.FilePath)
if err != nil {
return 0, nil, fmt.Errorf("os.Open: %w", err)
Expand Down Expand Up @@ -45,6 +45,7 @@ func (x *XFile) unAr(reader io.Reader) (int64, []string, error) {
}

// ar format does not store directory paths. Flat list of files.
//nolint:gosec // we are not overflowing an integer with this conversion.
fSize, err := writeFile(wfile, arReader, os.FileMode(header.Mode), x.DirMode)
if err != nil {
return size, files, err
Expand Down
4 changes: 2 additions & 2 deletions cpio.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

// ExtractCPIOGzip extracts a gzip-compressed cpio archive (cpgz).
func ExtractCPIOGzip(xFile *XFile) (int64, []string, error) {
func ExtractCPIOGzip(xFile *XFile) (size int64, filesList []string, err error) {
compressedFile, err := os.Open(xFile.FilePath)
if err != nil {
return 0, nil, fmt.Errorf("os.Open: %w", err)
Expand All @@ -30,7 +30,7 @@ func ExtractCPIOGzip(xFile *XFile) (int64, []string, error) {
}

// ExtractCPIO extracts a .cpio file.
func ExtractCPIO(xFile *XFile) (int64, []string, error) {
func ExtractCPIO(xFile *XFile) (size int64, filesList []string, err error) {
fileReader, err := os.Open(xFile.FilePath)
if err != nil {
return 0, nil, fmt.Errorf("os.Open: %w", err)
Expand Down
Loading
Loading