fix: handle os.chmod errors (#457)

This commit is contained in:
Cameron 2023-12-25 11:17:31 -08:00 committed by GitHub
parent 13a4c05ff5
commit 585b55c2ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 13 deletions

View file

@ -3,10 +3,10 @@ package jsondb
import (
"encoding/json"
"fmt"
"os"
"path"
"github.com/ngoduykhanh/wireguard-ui/model"
"github.com/ngoduykhanh/wireguard-ui/util"
)
func (o *JsonDB) GetWakeOnLanHosts() ([]model.WakeOnLanHost, error) {
@ -70,7 +70,11 @@ func (o *JsonDB) SaveWakeOnLanHost(host model.WakeOnLanHost) error {
wakeOnLanHostPath := path.Join(path.Join(o.dbPath, model.WakeOnLanHostCollectionName), resourceName+".json")
output := o.conn.Write(model.WakeOnLanHostCollectionName, resourceName, host)
os.Chmod(wakeOnLanHostPath, 0600)
err = util.ManagePerms(wakeOnLanHostPath)
if err != nil {
return err
}
return output
}