Skip to content

Commit

Permalink
Merge pull request #158 from ibuildthecloud/main
Browse files Browse the repository at this point in the history
Auto create directories when using sys.write
  • Loading branch information
ibuildthecloud authored Mar 14, 2024
2 parents 6258645 + 75eab9c commit ed1a747
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/builtin/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,14 @@ func SysWrite(ctx context.Context, env []string, input string) (string, error) {
locker.Lock(params.Filename)
defer locker.Unlock(params.Filename)

dir := filepath.Dir(params.Filename)
if _, err := os.Stat(dir); errors.Is(err, fs.ErrNotExist) {
log.Debugf("Creating dir %s", dir)
if err := os.MkdirAll(dir, 0755); err != nil {
return "", fmt.Errorf("creating dir %s: %w", dir, err)
}
}

data := []byte(params.Content)
log.Debugf("Wrote %d bytes to file %s", len(data), params.Filename)

Expand Down

0 comments on commit ed1a747

Please sign in to comment.