From 4f71e8502a5d12554719e9d6cf082569e3bc4652 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 27 Mar 2025 19:49:55 -0400 Subject: [PATCH] providers/os: Add functions for creating directories --- providers/os/os.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/providers/os/os.go b/providers/os/os.go index 060dc55..462472a 100644 --- a/providers/os/os.go +++ b/providers/os/os.go @@ -40,6 +40,8 @@ func (this *Provider) FuncMapFor (document *step.Document) template.FuncMap { "appendFile": stat.funcAppendFile, "removeFile": stat.funcRemoveFile, "rename": stat.funcRename, + "createDir": stat.funcCreateDir, + "createDirAll": stat.funcCreateDirAll, // TODO: temporary files, dirs } } @@ -164,6 +166,18 @@ func (this *state) funcRename (name, newName string) error { return os.Rename(name, newName) } +func (this *state) funcCreateDir(name string) error { + name, err := this.document.Rel(name) + if err != nil { return err } + return os.Mkdir(name, 755) +} + +func (this *state) funcCreateDirAll(name string) error { + name, err := this.document.Rel(name) + if err != nil { return err } + return os.MkdirAll(name, 755) +} + func sortDirEntriesByDate(entries []fs.DirEntry) { sort.Slice(entries, func(left, right int) bool{ var leftTime time.Time