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
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Copyright (c) 2018-2022 David Newhall II
Copyright (c) 2023-2024 Go Lift - Building Strong Go Tools
Copyright (c) 2023-2026 Go Lift - Building Strong Go Tools

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module github.com/Unpackerr/unpackerr

go 1.24.9

toolchain go1.26.0
go 1.26.0

require (
code.cloudfoundry.org/bytefmt v0.64.0
Expand Down
35 changes: 23 additions & 12 deletions pkg/unpackerr/folder_recursion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package unpackerr
import (
"archive/zip"
"bytes"
"fmt"
"os"
"path/filepath"
"strings"
Expand All @@ -13,6 +14,8 @@ import (
)

func TestFolderDisableRecursionHonored(t *testing.T) {
t.Parallel()

archivePath := makeNestedZipFixture(t)
done := runExtraction(t, archivePath, true)

Expand All @@ -32,6 +35,8 @@ func TestFolderDisableRecursionHonored(t *testing.T) {
}

func TestFolderDisableRecursionFalseExtractsNested(t *testing.T) {
t.Parallel()

archivePath := makeNestedZipFixture(t)
done := runExtraction(t, archivePath, false)

Expand All @@ -46,6 +51,8 @@ func TestFolderDisableRecursionFalseExtractsNested(t *testing.T) {
}

func TestFolderExcludeSuffixesDirectoryDoesNotExcludeAllArchives(t *testing.T) {
t.Parallel()

dir := t.TempDir()
exclude := folderExcludeSuffixes(dir, &FolderConfig{DisableRecursion: true, ExtractISOs: false})

Expand All @@ -59,6 +66,8 @@ func TestFolderExcludeSuffixesDirectoryDoesNotExcludeAllArchives(t *testing.T) {
}

func TestFolderExcludeSuffixesArchiveExcludesAllWhenDisableRecursion(t *testing.T) {
t.Parallel()

archivePath := makeNestedZipFixture(t)
exclude := folderExcludeSuffixes(archivePath, &FolderConfig{DisableRecursion: true, ExtractISOs: false})

Expand All @@ -79,9 +88,11 @@ func runExtraction(t *testing.T, archivePath string, disableRecursion bool) *xtr
FileMode: defaultFileMode,
DirMode: defaultDirMode,
})

t.Cleanup(func() { queue.Stop() })

callbacks := make(chan *xtractr.Response, updateChanBuf)

_, err := queue.Extract(&xtractr.Xtract{
Name: archivePath,
Filter: xtractr.Filter{Path: archivePath, ExcludeSuffix: exclude},
Expand Down Expand Up @@ -131,7 +142,7 @@ func makeNestedZipFixture(t *testing.T) string {
t.Fatalf("building outer zip fixture: %v", err)
}

if err := os.WriteFile(archivePath, outerZipBytes, 0o644); err != nil {
if err := os.WriteFile(archivePath, outerZipBytes, 0o600); err != nil {
t.Fatalf("writing outer zip fixture: %v", err)
}

Expand All @@ -141,22 +152,22 @@ func makeNestedZipFixture(t *testing.T) string {
func buildZip(entries map[string][]byte) ([]byte, error) {
var output bytes.Buffer

w := zip.NewWriter(&output)
writer := zip.NewWriter(&output)
for name, data := range entries {
f, err := w.Create(name)
entry, err := writer.Create(name)
if err != nil {
_ = w.Close()
return nil, err
_ = writer.Close()
return nil, fmt.Errorf("creating zip entry: %w", err)
}

if _, err := f.Write(data); err != nil {
_ = w.Close()
return nil, err
if _, err := entry.Write(data); err != nil {
_ = writer.Close()
return nil, fmt.Errorf("creating zip entry: %w", err)
}
}

if err := w.Close(); err != nil {
return nil, err
if err := writer.Close(); err != nil {
return nil, fmt.Errorf("closing zip writer: %w", err)
}

return output.Bytes(), nil
Expand All @@ -167,7 +178,7 @@ func containsFileBase(root, base string) bool {

_ = filepath.WalkDir(root, func(path string, d os.DirEntry, err error) error {
if err != nil || d == nil || d.IsDir() {
return nil
return nil //nolint:nilerr
}

if filepath.Base(path) == base {
Expand All @@ -184,7 +195,7 @@ func listFiles(root string) []string {
files := []string{}
_ = filepath.WalkDir(root, func(path string, d os.DirEntry, err error) error {
if err != nil || d == nil || d.IsDir() {
return nil
return nil //nolint:nilerr
}

if rel, relErr := filepath.Rel(root, path); relErr == nil {
Expand Down
14 changes: 8 additions & 6 deletions pkg/unpackerr/folder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestFoldersProcessEventCurrentBehavior(t *testing.T) {
folders := newTestFolders(t, cfg)

archive := filepath.Join(watchPath, "movie.rar")
if err := os.WriteFile(archive, []byte("x"), 0o644); err != nil {
if err := os.WriteFile(archive, []byte("x"), 0o600); err != nil {
t.Fatalf("creating archive test file: %v", err)
}

Expand All @@ -78,7 +78,7 @@ func TestFoldersProcessEventCurrentBehavior(t *testing.T) {
}

plain := filepath.Join(watchPath, "note.txt")
if err := os.WriteFile(plain, []byte("x"), 0o644); err != nil {
if err := os.WriteFile(plain, []byte("x"), 0o600); err != nil {
t.Fatalf("creating non-archive test file: %v", err)
}

Expand All @@ -94,7 +94,7 @@ func TestFoldersProcessEventCurrentBehavior(t *testing.T) {
}

dir := filepath.Join(watchPath, "incoming")
if err := os.Mkdir(dir, 0o755); err != nil {
if err := os.Mkdir(dir, 0o700); err != nil {
t.Fatalf("creating folder test dir: %v", err)
}

Expand All @@ -114,13 +114,14 @@ func TestFoldersProcessEventExcludedPath(t *testing.T) {
t.Parallel()

watchPath := t.TempDir()

excluded := filepath.Join(watchPath, "permanent")
if err := os.MkdirAll(filepath.Join(excluded, "sub"), 0o755); err != nil {
if err := os.MkdirAll(filepath.Join(excluded, "sub"), 0o700); err != nil {
t.Fatalf("creating excluded test path: %v", err)
}

nested := filepath.Join(excluded, "sub", "file.rar")
if err := os.WriteFile(nested, []byte("x"), 0o644); err != nil {
if err := os.WriteFile(nested, []byte("x"), 0o600); err != nil {
t.Fatalf("creating nested archive file: %v", err)
}

Expand Down Expand Up @@ -191,8 +192,9 @@ func newTestFolders(t *testing.T, cfg *FolderConfig) *Folders {
if folders.Watcher != nil {
folders.Watcher.Close()
}

if folders.FSNotify != nil {
folders.FSNotify.Close()
_ = folders.FSNotify.Close()
}
})

Expand Down