Skip to content

Commit 2b7719b

Browse files
Propose a small refactoring of the func
1 parent faf9d47 commit 2b7719b

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

arduino/resources/install.go

+7-13
Original file line numberDiff line numberDiff line change
@@ -121,21 +121,15 @@ func findPackageRoot(parent *paths.Path) (*paths.Path, error) {
121121
return nil, fmt.Errorf(tr("reading package root dir: %s", err))
122122
}
123123

124+
files.FilterDirs()
124125
files.FilterOutPrefix("__MACOSX")
125126

126-
var root *paths.Path
127-
for _, file := range files {
128-
if !file.IsDir() {
129-
continue
130-
}
131-
if root == nil {
132-
root = file
133-
} else {
134-
return nil, fmt.Errorf(tr("no unique root dir in archive, found '%[1]s' and '%[2]s'", root, file))
135-
}
136-
}
137-
if root == nil {
127+
if len(files) == 0 {
138128
return nil, fmt.Errorf(tr("files in archive must be placed in a subdirectory"))
139129
}
140-
return root, nil
130+
if len(files) > 1 {
131+
return nil, fmt.Errorf(tr("no unique root dir in archive, found '%[1]s' and '%[2]s'", files[0], files[1]))
132+
}
133+
134+
return files[0], nil
141135
}

0 commit comments

Comments
 (0)