From 4afdcd5b4ae7ae73758e39c53f1a5675c7f570c8 Mon Sep 17 00:00:00 2001 From: Chikage Date: Tue, 6 Sep 2022 16:25:46 +0800 Subject: [PATCH] fix write file error in windows --- modrinth/mrpack/overrides.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/modrinth/mrpack/overrides.go b/modrinth/mrpack/overrides.go index f73ba52..3001795 100644 --- a/modrinth/mrpack/overrides.go +++ b/modrinth/mrpack/overrides.go @@ -3,6 +3,7 @@ package mrpack import ( "archive/zip" "fmt" + "io" "log" "os" "path" @@ -48,13 +49,11 @@ func ExtractOverrides(zipFile string, target string) error { return err } - var buf []byte - _, err = fileReader.Read(buf) + outFile, err := os.OpenFile(targetPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) if err != nil { return err } - err = os.WriteFile(targetPath, buf, 0644) - if err != nil { + if _, err := io.Copy(outFile, fileReader); err != nil { return err } @@ -62,6 +61,10 @@ func ExtractOverrides(zipFile string, target string) error { if err != nil { return err } + err = outFile.Close() + if err != nil { + return err + } log.Println("Override file extracted:", targetPath) }