mirror of
https://github.com/issadarkthing/gomu.git
synced 2025-04-25 13:48:49 +08:00
create neccessary parent folder if path does not exists
This commit is contained in:
parent
1689a6208b
commit
d672b15108
10
utils.go
10
utils.go
@ -213,10 +213,18 @@ func contains(needle int, haystack []int) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// appendFile appends to a file, create the file if not exists
|
||||
func appendFile(path string, content string) error {
|
||||
f, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
return tracerr.Wrap(err)
|
||||
if err != os.ErrNotExist {
|
||||
return tracerr.Wrap(err)
|
||||
}
|
||||
// create the neccessary parent directory
|
||||
err = os.MkdirAll(filepath.Dir(expandFilePath(path)), os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
defer f.Close()
|
||||
if _, err := f.WriteString(content); err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user