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

Commits on Jul 6, 2022

  1. Fix possibility to use forward slashes in cd_files for Windows

    Packer recommends that we use "/" as the path separator. There is a
    problem with using it on Windows because of the following behaviour:
    
    We might pass paths with forward slashes in `StepCreateCD` struct
    
    The string `rootFolder, err := tmp.Dir("packer_to_cdrom")` makes
    rootFolder use system-based slashes, which is "\" for Windows.
    
    This rootFolder is passed to `s.AddFile(rootFolder, toAdd)`
    
    And a mix of two slashes ruins our replace logic while going through
    the `visit` function. We end up having different slashes for `allDirs`
    and `discardPath` in
    `intermediaryDirs := strings.Replace(allDirs, discardPath, "", 1)`
    
    We change our replace login to don't depend on slashes.
    
    The tests we had didn't cover such cases as we passed all files with
    paths constructed with filepath.Join(dir, fname) which returns paths
    with "\\" on Windows. So we added a test case to specifically check
    forward slashes.
    tempora-mutantur committed Jul 6, 2022
    Copy the full SHA
    ed10ca1 View commit details
    Browse the repository at this point in the history