Skip to content

Commit 93cdd1d

Browse files
committed
Fix dpkg-query crash
1 parent 280b9ab commit 93cdd1d

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

fssize.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,24 @@ func (fssize *FSSize) AccumulatePackages() error {
283283
var builder strings.Builder
284284
for _, c := range output {
285285
if c == '\n' {
286-
split := strings.Split(builder.String(), ",")
286+
str := builder.String()
287+
if len(str) == 0 {
288+
panic("unexpected output from dpkg-query, empty line")
289+
}
290+
291+
// dpkg-query can output nothing as the size sometimes, like here with surge-xt:
292+
// 2508,sudo
293+
// ,surge-xt
294+
// 91,switcheroo-control
295+
if str[0] == ',' {
296+
continue
297+
}
298+
299+
split := strings.Split(str, ",")
287300
if len(split) != 2 {
288-
panic("unexpected output from dpkg-query, more than 1 comma in output")
301+
panic("unexpected output from dpkg-query, failed to split line by comma in output")
289302
}
303+
290304
packageName := split[1]
291305
estimatedKibibytes, err := strconv.Atoi(split[0])
292306
if err != nil {

main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
)
1717

1818
const programName = "fssize"
19-
const version = "v0.0.2"
19+
const version = "v0.0.3"
2020

2121
func printError(str string) {
2222
os.Stderr.WriteString("\x1b[0;31m" + programName + ": " + str + "\x1b[0m\n")

0 commit comments

Comments
 (0)