Close created file in ACME local store CheckFile func

This commit is contained in:
guangwu 2024-04-09 19:12:04 +08:00 committed by GitHub
parent cef842245c
commit 76723b1288
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -11,14 +11,15 @@ import (
// CheckFile checks file permissions and content size. // CheckFile checks file permissions and content size.
func CheckFile(name string) (bool, error) { func CheckFile(name string) (bool, error) {
f, err := os.Open(name) f, err := os.Open(name)
if err != nil { if err != nil && os.IsNotExist(err) {
if os.IsNotExist(err) { nf, err := os.Create(name)
f, err = os.Create(name) if err != nil {
if err != nil { return false, err
return false, err
}
return false, f.Chmod(0o600)
} }
defer nf.Close()
return false, nf.Chmod(0o600)
}
if err != nil {
return false, err return false, err
} }
defer f.Close() defer f.Close()