From 69fd5a1527b690b45b043dd3b59eff05e67091dc Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Wed, 30 Sep 2020 15:07:26 -0700 Subject: [PATCH 1/2] fix pathing in cd_files copy to make sure directories make it into the cd root. --- common/step_create_cdrom.go | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/common/step_create_cdrom.go b/common/step_create_cdrom.go index 5680052fb..4655fcd8f 100644 --- a/common/step_create_cdrom.go +++ b/common/step_create_cdrom.go @@ -236,12 +236,26 @@ func (s *StepCreateCD) AddFile(dst, src string) error { return err } + // file is a directory, so we need to parse the filename into a path to + // dicard and a basename + discardPath, _ := filepath.Split(src) + // Add a directory and its subdirectories visit := func(pathname string, fi os.FileInfo, err error) error { if err != nil { return err } + // Clean up pathing so that we preserve the base directory provided by + // the user but not the local pathing to that directory. + allDirs, base := filepath.Split(pathname) + intermediaryDirs := strings.Replace(allDirs, discardPath, "", 1) + + dstPath := filepath.Join(dst, base) + if intermediaryDirs != "" { + dstPath = filepath.Join(dst, intermediaryDirs, base) + } + // add a file if !fi.IsDir() { inputF, err := os.Open(pathname) @@ -250,26 +264,26 @@ func (s *StepCreateCD) AddFile(dst, src string) error { } defer inputF.Close() - fileDst, err := os.Create(filepath.Join(dst, pathname)) + fileDst, err := os.Create(dstPath) if err != nil { - return fmt.Errorf("Error opening file %s on CD", src) + return fmt.Errorf("Error opening file %s on CD: %s", dstPath, err) } defer fileDst.Close() nBytes, err := io.Copy(fileDst, inputF) if err != nil { - return fmt.Errorf("Error copying %s to CD", src) + return fmt.Errorf("Error copying %s to CD: %s", dstPath, err) } - s.filesAdded[pathname] = true - log.Printf("Wrote %d bytes to %s", nBytes, pathname) + s.filesAdded[dstPath] = true + log.Printf("Wrote %d bytes to %s", nBytes, dstPath) return err } if fi.Mode().IsDir() { // create the directory on the CD, continue walk. - err := os.Mkdir(filepath.Join(dst, pathname), fi.Mode()) + err := os.MkdirAll(dstPath, fi.Mode()) if err != nil { err = fmt.Errorf("error creating new directory %s: %s", - filepath.Join(dst, pathname), err) + dstPath, err) } return err } From b105e5e4166cd320d38359e9488587634d474a3c Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Fri, 2 Oct 2020 09:17:29 -0700 Subject: [PATCH 2/2] Update common/step_create_cdrom.go Co-authored-by: Wilken Rivera --- common/step_create_cdrom.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/step_create_cdrom.go b/common/step_create_cdrom.go index 4655fcd8f..3a350cce9 100644 --- a/common/step_create_cdrom.go +++ b/common/step_create_cdrom.go @@ -237,7 +237,7 @@ func (s *StepCreateCD) AddFile(dst, src string) error { } // file is a directory, so we need to parse the filename into a path to - // dicard and a basename + // discard and a basename discardPath, _ := filepath.Split(src) // Add a directory and its subdirectories