forked from stashapp/stash
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add exclude file from scan feature (stashapp#253)
* Added exclude file from scan feature * Abort exclusion instead of panicking when pattern isn't valid * Added UI configuration for exclude patterns * * cosmetic fixes * changed behavior of exclude function to continue and ignore invalide regex patterns * added some more tests (windows networks and continue after regex error)
- Loading branch information
Showing
8 changed files
with
174 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package manager | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestExcludeFiles(t *testing.T) { | ||
|
||
filenames := []string{ | ||
"/stash/videos/filename.mp4", | ||
"/stash/videos/new filename.mp4", | ||
"filename sample.mp4", | ||
"/stash/videos/exclude/not wanted.webm", | ||
"/stash/videos/exclude/not wanted2.webm", | ||
"/somewhere/trash/not wanted.wmv", | ||
"/disk2/stash/videos/exclude/!!wanted!!.avi", | ||
"/disk2/stash/videos/xcl/not wanted.avi", | ||
"/stash/videos/partial.file.001.webm", | ||
"/stash/videos/partial.file.002.webm", | ||
"/stash/videos/partial.file.003.webm", | ||
"/stash/videos/sample file sample.mkv", | ||
"/stash/videos/.ckRVp1/.still_encoding.mp4", | ||
"c:\\stash\\videos\\exclude\\filename windows.mp4", | ||
"c:\\stash\\videos\\filename windows.mp4", | ||
"\\\\network\\videos\\filename windows network.mp4", | ||
"\\\\network\\share\\windows network wanted.mp4", | ||
"\\\\network\\share\\windows network wanted sample.mp4", | ||
"\\\\network\\private\\windows.network.skip.mp4"} | ||
|
||
var excludeTests = []struct { | ||
testPattern []string | ||
expected int | ||
}{ | ||
{[]string{"sample\\.mp4$", "trash", "\\.[\\d]{3}\\.webm$"}, 6}, //generic | ||
{[]string{"no_match\\.mp4"}, 0}, //no match | ||
{[]string{"^/stash/videos/exclude/", "/videos/xcl/"}, 3}, //linux | ||
{[]string{"/\\.[[:word:]]+/"}, 1}, //linux hidden dirs (handbrake unraid issue?) | ||
{[]string{"c:\\\\stash\\\\videos\\\\exclude"}, 1}, //windows | ||
{[]string{"\\/[/invalid"}, 0}, //invalid pattern | ||
{[]string{"\\/[/invalid", "sample\\.[[:alnum:]]+$"}, 3}, //invalid pattern but continue | ||
{[]string{"^\\\\\\\\network"}, 4}, //windows net share | ||
{[]string{"\\\\private\\\\"}, 1}, //windows net share | ||
{[]string{"\\\\private\\\\", "sample\\.mp4"}, 3}, //windows net share | ||
} | ||
for _, test := range excludeTests { | ||
err := runExclude(filenames, test.testPattern, test.expected) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
} | ||
} | ||
|
||
func runExclude(filenames []string, patterns []string, expCount int) error { | ||
|
||
files, count := excludeFiles(filenames, patterns) | ||
|
||
if count != expCount { | ||
return fmt.Errorf("Was expecting %d, found %d", expCount, count) | ||
} | ||
if len(files) != len(filenames)-expCount { | ||
return fmt.Errorf("Returned list should have %d files, not %d ", len(filenames)-expCount, len(files)) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters