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.
func CheckFile(name string) (bool, error) {
f, err := os.Open(name)
if err != nil {
if os.IsNotExist(err) {
f, err = os.Create(name)
if err != nil {
return false, err
}
return false, f.Chmod(0o600)
if err != nil && os.IsNotExist(err) {
nf, err := os.Create(name)
if err != nil {
return false, err
}
defer nf.Close()
return false, nf.Chmod(0o600)
}
if err != nil {
return false, err
}
defer f.Close()