Remove when download error

This commit is contained in:
世界 2023-11-05 15:30:03 +08:00
parent 0cfb14a18b
commit 46f79f25a2
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4
3 changed files with 11 additions and 7 deletions

2
go.mod
View File

@ -26,7 +26,7 @@ require (
github.com/sagernet/gvisor v0.0.0-20230930141345-5fef6f2e17ab
github.com/sagernet/quic-go v0.0.0-20231008035953-32727fef9460
github.com/sagernet/reality v0.0.0-20230406110435-ee17307e7691
github.com/sagernet/sing v0.2.16-0.20231028125948-afcc9cb766c2
github.com/sagernet/sing v0.2.16-0.20231105072849-64e91d772616
github.com/sagernet/sing-dns v0.1.10
github.com/sagernet/sing-mux v0.1.4-0.20231105044304-ae2745a33479
github.com/sagernet/sing-quic v0.1.3-0.20231026034240-fa3d997246b6

4
go.sum
View File

@ -114,8 +114,8 @@ github.com/sagernet/reality v0.0.0-20230406110435-ee17307e7691 h1:5Th31OC6yj8byL
github.com/sagernet/reality v0.0.0-20230406110435-ee17307e7691/go.mod h1:B8lp4WkQ1PwNnrVMM6KyuFR20pU8jYBD+A4EhJovEXU=
github.com/sagernet/sing v0.0.0-20220817130738-ce854cda8522/go.mod h1:QVsS5L/ZA2Q5UhQwLrn0Trw+msNd/NPGEhBKR/ioWiY=
github.com/sagernet/sing v0.1.8/go.mod h1:jt1w2u7lJQFFSGLiRrRIs5YWmx4kAPfWuOejuDW9qMk=
github.com/sagernet/sing v0.2.16-0.20231028125948-afcc9cb766c2 h1:PW18IgRodvppd09d4mewYM3Hedu3PtFERN8yOqkTVk0=
github.com/sagernet/sing v0.2.16-0.20231028125948-afcc9cb766c2/go.mod h1:AhNEHu0GXrpqkuzvTwvC8+j2cQUU/dh+zLEmq4C99pg=
github.com/sagernet/sing v0.2.16-0.20231105072849-64e91d772616 h1:zIm6f7NQR8zhkAaoCIe8sL9Rp3HAkfoF+FGb4XEN3SY=
github.com/sagernet/sing v0.2.16-0.20231105072849-64e91d772616/go.mod h1:AhNEHu0GXrpqkuzvTwvC8+j2cQUU/dh+zLEmq4C99pg=
github.com/sagernet/sing-dns v0.1.10 h1:iIU7nRBlUYj+fF2TaktGIvRiTFFrHwSMedLQsvlTZCI=
github.com/sagernet/sing-dns v0.1.10/go.mod h1:vtUimtf7Nq9EdvD5WTpfCr69KL1M7bcgOVKiYBiAY/c=
github.com/sagernet/sing-mux v0.1.4-0.20231105044304-ae2745a33479 h1:h6ANTA5wbP5BSqbjOT7s1OKLZgdsLqiXO564KQqY2i4=

View File

@ -181,9 +181,11 @@ func (r *Router) downloadGeoIPDatabase(savePath string) error {
if err != nil {
return E.Cause(err, "open output file: ", downloadURL)
}
defer saveFile.Close()
_, err = io.Copy(saveFile, response.Body)
saveFile.Close()
if err != nil {
filemanager.Remove(r.ctx, savePath)
}
return err
}
@ -234,9 +236,11 @@ func (r *Router) downloadGeositeDatabase(savePath string) error {
if err != nil {
return E.Cause(err, "open output file: ", downloadURL)
}
defer saveFile.Close()
_, err = io.Copy(saveFile, response.Body)
saveFile.Close()
if err != nil {
filemanager.Remove(r.ctx, savePath)
}
return err
}