From c3cdacf1b3bfa9ec587d19cf7b06947defd01c62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beomgi=20Kim=20=7C=20=EA=B9=80=EB=B2=94=EA=B8=B0?= Date: Sun, 5 Nov 2023 17:24:27 +0900 Subject: [PATCH] add file cloese when write file (#18) * add file cloese * fix protobuf design --- README.md | 2 +- pkg/types/fileinfo/fileinfo.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a0ccc90..34b1371 100644 --- a/README.md +++ b/README.md @@ -544,7 +544,7 @@ Google's protobuf library is used to design protocol data. The protocol data str message Header { RequestType requestType = 1; bytes requestId = 2; - string error = 3; + string error = 3; } enum RequestType { diff --git a/pkg/types/fileinfo/fileinfo.go b/pkg/types/fileinfo/fileinfo.go index 411a4b0..4d4c9cb 100644 --- a/pkg/types/fileinfo/fileinfo.go +++ b/pkg/types/fileinfo/fileinfo.go @@ -84,6 +84,7 @@ func (f *FileInfo) WriteFileWithInfo(filePath string, fileContent io.Reader) err if err != nil { return err } + defer file.Close() // Set file metadata. err = file.Chmod(f.Mode) @@ -119,6 +120,7 @@ func (f *FileInfo) WriteFileWithInfo(filePath string, fileContent io.Reader) err return err } } + defer file.Close() // Write file content. n, err := io.Copy(file, fileContent)