From bbd9ef1f5ce13914a11413b7b5ddf29d5aa04a31 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Sun, 14 Apr 2024 00:50:11 +0200 Subject: [PATCH] Create directories for subgroups. --- group/description.go | 9 ++++++++- group/description_test.go | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/group/description.go b/group/description.go index be7c276..53671d6 100644 --- a/group/description.go +++ b/group/description.go @@ -380,7 +380,14 @@ func rewriteDescriptionFile(filename string, desc *Description) error { return ErrDescriptionsNotWritable } - f, err := os.CreateTemp(path.Dir(filename), "*.temp") + dir := filepath.Dir(filename) + + err = os.MkdirAll(dir, 0700) + if err != nil { + return err + } + + f, err := os.CreateTemp(dir, "*.temp") if err != nil { return err } diff --git a/group/description_test.go b/group/description_test.go index 9e9221c..387cc18 100644 --- a/group/description_test.go +++ b/group/description_test.go @@ -306,3 +306,15 @@ func TestWritableGroups(t *testing.T) { ) } } + +func TestSubGroup(t *testing.T) { + err := setupTest(t.TempDir(), t.TempDir(), true) + if err != nil { + t.Fatalf("setupTest: %v", err) + } + + err = UpdateDescription("dir/test", "", &Description{}) + if err != nil { + t.Fatalf("UpdateDescription: got %v", err) + } +}