mirror of
https://github.com/issadarkthing/gomu.git
synced 2025-04-28 13:48:53 +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
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// appendFile appends to a file, create the file if not exists
|
||||||
func appendFile(path string, content string) error {
|
func appendFile(path string, content string) error {
|
||||||
f, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
f, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||||
if err != nil {
|
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()
|
defer f.Close()
|
||||||
if _, err := f.WriteString(content); err != nil {
|
if _, err := f.WriteString(content); err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user