Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix support for forward slashes with nested folders in cd_files for Windows #115

Merged
merged 1 commit into from Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion multistep/commonsteps/step_create_cdrom.go
Expand Up @@ -260,7 +260,9 @@ func (s *StepCreateCD) AddFile(dst, src string) error {
// 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)
allDirsSlashSafe := filepath.ToSlash(allDirs)
discardPathSlashSafe := filepath.ToSlash(discardPath)
intermediaryDirs := strings.Replace(allDirsSlashSafe, discardPathSlashSafe, "", 1)

dstPath := filepath.Join(dst, base)
if intermediaryDirs != "" {
Expand Down
30 changes: 18 additions & 12 deletions multistep/commonsteps/step_create_cdrom_test.go
Expand Up @@ -93,28 +93,33 @@ func TestStepCreateCD(t *testing.T) {
defer os.RemoveAll(dir)

createFiles(t, dir, map[string]string{
"test folder/b/test1": "1",
"test folder/b/test2": "2",
"test folder 2/x": "3",
"test_cd_roms.tmp": "4",
"test cd files.tmp": "5",
"Test-Test-Test5.tmp": "6",
"subfolder/meta-data": "subfolder/meta-data from files",
"subfolder/user-data": "subfolder/user-data from files",
"user-data": "user-data from files",
"vendor-data": "vendor-data from files",
"test folder/b/test1": "1",
"test folder/b/test2": "2",
"test folder 2/x": "3",
"test_cd_roms.tmp": "4",
"test cd files.tmp": "5",
"Test-Test-Test5.tmp": "6",
"fwdslashes/nested/test": "7",
"subfolder/meta-data": "subfolder/meta-data from files",
"subfolder/user-data": "subfolder/user-data from files",
"user-data": "user-data from files",
"vendor-data": "vendor-data from files",
})
step.Content = map[string]string{
"subfolder not created by files/test.tmp": "test",
"subfolder/meta-data": "subfolder/meta-data from content",
"user-data": "user-data from content",
}

files := []string{"test folder", "test folder 2/", "test_cd_roms.tmp", "test cd files.tmp", "Test-Test-Test5.tmp", "subfolder", "user-data", "vendor-data"}
files := []string{"test folder", "test folder 2/", "test_cd_roms.tmp", "test cd files.tmp", "Test-Test-Test5.tmp", "fwdslashes", "subfolder", "user-data", "vendor-data"}

step.Files = make([]string, len(files))
for i, fname := range files {
step.Files[i] = filepath.Join(dir, fname)
fullPath := filepath.Join(dir, fname)
if fname == "fwdslashes" {
fullPath = filepath.ToSlash(fullPath)
}
step.Files[i] = fullPath
}
action := step.Run(context.Background(), state)

Expand All @@ -139,6 +144,7 @@ func TestStepCreateCD(t *testing.T) {
"test_cd_roms.tmp": "4",
"test cd files.tmp": "5",
"Test-Test-Test5.tmp": "6",
"fwdslashes/nested/test": "7",
"subfolder not created by files/test.tmp": "test",
"subfolder/meta-data": "subfolder/meta-data from content",
"subfolder/user-data": "subfolder/user-data from files",
Expand Down