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
26 changes: 8 additions & 18 deletions pkg/unpackerr/folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (u *Unpackerr) extractTrackedItem(name string, folder *Folder, now time.Tim
return
}

exclude := folderExcludeSuffixes(name, folder.Config)
exclude := folderExcludeSuffixes(folder.Config)

if folder.Config.MoveBack {
found := xtractr.FindCompressedFiles(xtractr.Filter{
Expand Down Expand Up @@ -155,24 +155,14 @@ func (u *Unpackerr) skipR00Extraction(name string, now time.Time) bool {
}

// folderExcludeSuffixes returns archive suffixes to ignore when scanning for items to extract.
// For watched archive files with disable_recursion enabled, exclude all archive suffixes so
// extracted nested archives are not picked up by follow-up scans in the extraction library.
func folderExcludeSuffixes(path string, cfg *FolderConfig) []string {
exclude := []string{}
if !cfg.ExtractISOs {
exclude = append(exclude, ".iso")
}

if !cfg.DisableRecursion {
return exclude
}

stat, err := os.Stat(path)
if err != nil || stat.IsDir() || !xtractr.IsArchiveFile(path) {
return exclude
// xtractr applies this list even when the search path is the archive itself, so a watched
// archive must stay searchable. Nested archives are skipped with DisableRecursion.
func folderExcludeSuffixes(cfg *FolderConfig) []string {
if cfg.ExtractISOs {
return nil
}

return append(exclude, xtractr.SupportedExtensions()...)
return []string{".iso"}
}

func getFileList(path string) []os.FileInfo {
Expand Down Expand Up @@ -660,7 +650,7 @@ func (u *Unpackerr) folderArchiveCount(name string, folder *Folder) int {

found := xtractr.FindCompressedFiles(xtractr.Filter{
Path: name,
ExcludeSuffix: folderExcludeSuffixes(name, cfg),
ExcludeSuffix: folderExcludeSuffixes(cfg),
AllowSymlinks: cfg.AllowSymlinks,
})

Expand Down
17 changes: 10 additions & 7 deletions pkg/unpackerr/folder_recursion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ func TestFolderDisableRecursionFalseExtractsNested(t *testing.T) {
func TestFolderExcludeSuffixesDirectoryDoesNotExcludeAllArchives(t *testing.T) {
t.Parallel()

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

if !containsString(exclude, ".iso") {
t.Fatalf("expected .iso exclusion when extract_isos=false; got: %v", exclude)
Expand All @@ -65,22 +64,26 @@ func TestFolderExcludeSuffixesDirectoryDoesNotExcludeAllArchives(t *testing.T) {
}
}

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

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

if !containsString(exclude, ".zip") {
t.Fatalf("expected archive suffix exclusions for watched archive file; got: %v", exclude)
if containsString(exclude, ".zip") {
t.Fatalf("watched archive suffix must stay searchable; got: %v", exclude)
}

if xtractr.FindCompressedFiles(xtractr.Filter{Path: archivePath, ExcludeSuffix: exclude}).Count() != 1 {
t.Fatal("expected FindCompressedFiles to return the watched archive")
}
}

func runExtraction(t *testing.T, archivePath string, disableRecursion bool) *xtractr.Response {
t.Helper()

cfg := &FolderConfig{DisableRecursion: disableRecursion, ExtractISOs: false}
exclude := folderExcludeSuffixes(archivePath, cfg)
exclude := folderExcludeSuffixes(cfg)

queue := xtractr.NewQueue(&xtractr.Config{
Parallel: 1,
Expand Down
Loading