Skip to content

Commit ecddcf3

Browse files
author
Jack Tang
committed
FIX: divide by zero bug if file size is 0
1 parent 9d96c08 commit ecddcf3

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

internal/server/server.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Options:
3737
--store-size BYTE Size of space allowed for storage [default: 0]
3838
--timeout TIMEOUT Read timeout for connections in milliseconds. A zero value means that reads will not timeout [default: 30*1000]
3939
--behind-proxy Respect X-Forwarded-* and similar headers which may be set by proxies [default: false]
40-
--inc Sort filename in increasingly alphabetical order in listing page [default: false]
40+
--inc Sort filename in increasingly alphabetical order in listing page [default: false]
4141
`
4242

4343
type ServerConf struct {
@@ -209,7 +209,6 @@ td {
209209
filename := f.Name()
210210
ext := ".info"
211211
lenOfID := len(filename) - len(ext)
212-
fmt.Println("filename", filename, filename[lenOfID:])
213212

214213
// only care .info file
215214
if lenOfID > 0 && filename[lenOfID:] == ext {
@@ -222,13 +221,17 @@ td {
222221
if fn, ok := info.MetaData["filename"]; ok {
223222
filename = fn
224223
}
224+
var offset int64 = 100
225+
if info.Size != 0 {
226+
fmt.Println(info.Size)
227+
offset = info.Offset * 100 / info.Size
228+
}
225229
rows = append(rows, Row{
226230
ID: info.ID,
227231
Filename: filename,
228232
Size: humanize.Bytes(uint64(info.Size)),
229-
Offset: info.Offset * 100 / info.Size,
233+
Offset: offset,
230234
})
231-
fmt.Println("info", info)
232235
}
233236
}
234237
}

0 commit comments

Comments
 (0)