From 7c89ebebe664a1fec84257a483d55479cf137e02 Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Tue, 12 Nov 2024 02:44:46 -0500 Subject: [PATCH] began implementing creating parent directories for output file --- internal/util/path.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/internal/util/path.go b/internal/util/path.go index 7f76318..7013734 100644 --- a/internal/util/path.go +++ b/internal/util/path.go @@ -51,6 +51,21 @@ func replaceRoot(inPath, outRoot string) string { return outPath } +func createFileWithParents(path string) error { + dir := filepath.Dir(path) + // Check if the parent directory already exists + // before trying to create it + if _, dirErr := os.Stat(dir); os.IsNotExist(dirErr) { + // create directories + err := os.MkdirAll(dir, os.ModePerm) + if err != nil { + return err + } + // TODO: write the file here + } + return nil +} + func processFile(inPath string, entry fs.DirEntry, err error, outRoot string) error { if err != nil { return err