Skip to content

Commit 25c33b8

Browse files
author
Roberto Sora
committed
added blacklisting for path and files in findBaseDir
1 parent 04adc9c commit 25c33b8

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

tools/download.go

+18-2
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ func stringInSlice(str string, list []string) bool {
319319
return false
320320
}
321321

322-
func CommonPrefix(sep byte, paths []string) string {
322+
func commonPrefix(sep byte, paths []string) string {
323323
// Handle special cases.
324324
switch len(paths) {
325325
case 0:
@@ -365,11 +365,27 @@ func CommonPrefix(sep byte, paths []string) string {
365365
return string(c)
366366
}
367367

368+
func removeStringFromSlice(s []string, r string) []string {
369+
for i, v := range s {
370+
if v == r {
371+
return append(s[:i], s[i+1:]...)
372+
}
373+
}
374+
return s
375+
}
376+
368377
func findBaseDir(dirList []string) string {
369378
if len(dirList) == 1 {
370379
return filepath.Dir(dirList[0]) + "/"
371380
}
372-
commonBaseDir := CommonPrefix(os.PathSeparator, dirList)
381+
382+
// https://github.com/backdrop-ops/contrib/issues/55#issuecomment-73814500
383+
dontdiff := []string{"pax_global_header"}
384+
for _, v := range dontdiff {
385+
dirList = removeStringFromSlice(dirList, v)
386+
}
387+
388+
commonBaseDir := commonPrefix(os.PathSeparator, dirList)
373389
if commonBaseDir != "" {
374390
commonBaseDir = commonBaseDir + "/"
375391
}

tools/download_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ func Test_findBaseDir(t *testing.T) {
1414
{[]string{"bin/", "bin/bossac"}, "bin/"},
1515
{[]string{"bin/", "bin/bossac", "example"}, ""},
1616
{[]string{"avrdude/bin/avrdude", "avrdude/etc/avrdude.conf"}, "avrdude/"},
17+
{[]string{"pax_global_header","bin/", "bin/bossac"}, "bin/"},
18+
1719
}
1820
for _, tt := range cases {
1921
t.Run(fmt.Sprintln(tt.dirList), func(t *testing.T) {

0 commit comments

Comments
 (0)