Skip to content

Commit

Permalink
Create all directories before creating a new file
Browse files Browse the repository at this point in the history
Summary: Resolves facebookincubator#506

Differential Revision: D61658174
  • Loading branch information
inesusvet authored and facebook-github-bot committed Aug 22, 2024
1 parent cb05962 commit cfb3cb5
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/blocks/createfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package blocks
import (
"fmt"
"os"
"path/filepath"

"github.com/facebookincubator/ttpforge/pkg/fileutils"
"github.com/facebookincubator/ttpforge/pkg/logging"
Expand Down Expand Up @@ -94,6 +95,15 @@ func (s *CreateFileStep) Execute(_ TTPExecutionContext) (*ActResult, error) {
mode = 0666
}

dir := filepath.Dir(pathToCreate)
exists, err = afero.Exists(fsys, dir)
if err != nil {
return nil, err
}
if !exists {
fsys.MkdirAll(dir, os.ModePerm)
}

// actually write the file
f, err := fsys.OpenFile(pathToCreate, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.FileMode(mode))
if err != nil {
Expand Down

0 comments on commit cfb3cb5

Please sign in to comment.