From 6c24be9f4679181ba3a0dbacb7a4a9a25159c31d Mon Sep 17 00:00:00 2001 From: comp500 Date: Tue, 17 Sep 2019 21:52:23 +0100 Subject: [PATCH] Create the containing directory if it fails --- core/mod.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/core/mod.go b/core/mod.go index 9b4e7c9..7974def 100644 --- a/core/mod.go +++ b/core/mod.go @@ -6,6 +6,7 @@ import ( "errors" "io" "os" + "path/filepath" "github.com/BurntSushi/toml" ) @@ -76,7 +77,14 @@ func (m *Mod) SetMetaName(metaName string) string { func (m Mod) Write() (string, string, error) { f, err := os.Create(m.metaFile) if err != nil { - return "sha256", "", err + // Attempt to create the containing directory + err2 := os.MkdirAll(filepath.Dir(m.metaFile), os.ModePerm) + if err2 == nil { + f, err = os.Create(m.metaFile) + } + if err == nil { + return "sha256", "", err + } } defer f.Close()