providers/os: Add chmod function

This commit is contained in:
Sasha Koshka 2025-03-27 19:52:56 -04:00
parent bc3b486704
commit 8c5e69fcdf

View File

@ -42,6 +42,7 @@ func (this *Provider) FuncMapFor (document *step.Document) template.FuncMap {
"rename": stat.funcRename,
"createDir": stat.funcCreateDir,
"createDirAll": stat.funcCreateDirAll,
"chmod": stat.funcChmod,
// TODO: temporary files, dirs
}
}
@ -178,6 +179,12 @@ func (this *state) funcCreateDirAll(name string) error {
return os.MkdirAll(name, 755)
}
func (this *state) funcChmod(name string, mode fs.FileMode) error {
name, err := this.document.Rel(name)
if err != nil { return err }
return os.Chmod(name, mode)
}
func sortDirEntriesByDate(entries []fs.DirEntry) {
sort.Slice(entries, func(left, right int) bool{
var leftTime time.Time