From 1347b11f06f60b663da4ce02f38180be3f264e8e Mon Sep 17 00:00:00 2001 From: Ali Rizvi-Santiago Date: Tue, 11 Oct 2016 19:16:26 -0500 Subject: [PATCH] Fixed a bug due to some missing filepath.ToSlash calls in StepCreateFloppy.Add. If backslashes were in a filename (such as when running from Windows), this would cause the backslashes to be included in the filenames in the created floppy disk which caused havoc when Windows tried to parse it. Fixed a bug in fsDirectoryCache when using path.Clean() to normalize the input directory properly. This would cause an error where a new directory "." would be created instead of it correctly returning the root directory. Fixes issue #3977. --- common/step_create_floppy.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/common/step_create_floppy.go b/common/step_create_floppy.go index 273be1bc4..6bccc9fc4 100644 --- a/common/step_create_floppy.go +++ b/common/step_create_floppy.go @@ -222,7 +222,7 @@ func (s *StepCreateFloppy) Add(dircache directoryCache, src string) error { return err } - entry, err := d.AddFile(path.Base(src)) + entry, err := d.AddFile(path.Base(filepath.ToSlash(src))) if err != nil { return err } @@ -251,9 +251,9 @@ func (s *StepCreateFloppy) Add(dircache directoryCache, src string) error { _, err = dircache(filepath.ToSlash(base)) return err } - directory, filename := filepath.Split(pathname) + directory, filename := filepath.Split(filepath.ToSlash(pathname)) - base, err := removeBase(basedirectory, directory) + base, err := removeBase(basedirectory, filepath.FromSlash(directory)) if err != nil { return err } @@ -337,7 +337,10 @@ func fsDirectoryCache(rootDirectory fs.Directory) directoryCache { Input, Output, Error := make(chan string), make(chan fs.Directory), make(chan error) go func(Error chan error) { for { - input := path.Clean(<-Input) + input := <-Input + if len(input) > 0 { + input = path.Clean(input) + } // found a directory, so yield it res, ok := cache[input]