mirror of
https://git.freecumextremist.com/grumbulon/pomme.git
synced 2024-12-22 17:20:44 +00:00
capture error on defer, doc string, lint
This commit is contained in:
parent
92100e27a0
commit
ae3e7a1ae6
2 changed files with 12 additions and 3 deletions
|
@ -11,7 +11,7 @@ import (
|
|||
|
||||
var errEmptyFile = errors.New("will not save empty file to FS")
|
||||
|
||||
// makeLocal takes a type path and then saves a zone file to either tmp or a permanent location
|
||||
// makeLocal takes a type path and then saves a zone file to either tmp or a permanent location.
|
||||
func makeLocal(where path, zone *ZoneRequest) error {
|
||||
var (
|
||||
path string
|
||||
|
@ -20,7 +20,7 @@ func makeLocal(where path, zone *ZoneRequest) error {
|
|||
err error
|
||||
)
|
||||
|
||||
if _, err := os.Stat(fmt.Sprintf(zone.FileName, zone.User)); !os.IsNotExist(err) {
|
||||
if _, err = os.Stat(fmt.Sprintf(zone.FileName, zone.User)); !os.IsNotExist(err) {
|
||||
return fmt.Errorf("file %s already exists: %w", zone.FileName, err)
|
||||
}
|
||||
|
||||
|
@ -33,13 +33,17 @@ func makeLocal(where path, zone *ZoneRequest) error {
|
|||
path = fmt.Sprintf("/tmp/tmpfile-%s-%s", zone.RawFileName, zone.User)
|
||||
case Perm:
|
||||
c, err = internal.ReadConfig()
|
||||
|
||||
if err != nil {
|
||||
logHandler(genericResponseFields{"error": err.Error(), "message": "no config file defined"})
|
||||
|
||||
return fmt.Errorf("unable to parse directory: %w", err)
|
||||
}
|
||||
|
||||
path = fmt.Sprintf("%s/%s/", c.ZoneDir, zone.RawFileName)
|
||||
|
||||
file = zone.RawFileName
|
||||
|
||||
if err = os.MkdirAll(path, 0o750); err != nil {
|
||||
logHandler(genericResponseFields{"error": err.Error(), "message": "unable to make directory for zone files"})
|
||||
|
||||
|
|
|
@ -138,7 +138,12 @@ func (zone *ZoneRequest) parse() error {
|
|||
|
||||
func (zone *ZoneRequest) save(path) error {
|
||||
// clean up the tmp file
|
||||
defer os.Remove(filepath.Clean("/tmp/" + zone.FileName))
|
||||
defer func() (err error) {
|
||||
if err = os.Remove(filepath.Clean("/tmp/" + zone.FileName)); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}()
|
||||
|
||||
return makeLocal(Perm, zone)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue