Skip to content

Commit c75cbf7

Browse files
committed
cmd/fitgen: handle zip archives including a 'wrapper' folder
From at least 21.30, the SDK zip archive contains a 'wrapper' folder, i.e. two levels, with an outer SDK folder containing the 'old' root SDK folder.
1 parent d9af6e1 commit c75cbf7

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

cmd/fitgen/main.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,17 +193,7 @@ func readDataFromZIP(path string) ([]byte, error) {
193193
}
194194
defer r.Close()
195195

196-
var wfile *zip.File
197-
for _, f := range r.File {
198-
if f.Name == workbookNameXLS {
199-
wfile = f
200-
break
201-
}
202-
if f.Name == workbookNameXLSX {
203-
wfile = f
204-
break
205-
}
206-
}
196+
wfile := scanForWorkbook(r.File)
207197
if wfile == nil {
208198
return nil, fmt.Errorf(
209199
"no file named %q or %q found in zip archive",
@@ -225,6 +215,15 @@ func readDataFromZIP(path string) ([]byte, error) {
225215
return data, nil
226216
}
227217

218+
func scanForWorkbook(files []*zip.File) *zip.File {
219+
for _, f := range files {
220+
if strings.HasSuffix(f.Name, workbookNameXLS) || strings.HasSuffix(f.Name, workbookNameXLSX) {
221+
return f
222+
}
223+
}
224+
return nil
225+
}
226+
228227
func readDataFromXLSX(path string) ([]byte, error) {
229228
return ioutil.ReadFile(path)
230229
}

0 commit comments

Comments
 (0)