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: Fix Windows zip file #816

Merged
merged 1 commit into from
Aug 7, 2023
Merged

fix: Fix Windows zip file #816

merged 1 commit into from
Aug 7, 2023

Conversation

tianfeng92
Copy link
Contributor

@tianfeng92 tianfeng92 commented Aug 4, 2023

Proposed changes

When triggering tests on a Mac platform from a Windows machine, there is an issue with unzipping packages that have an @ prefix in the node_modules zip.

Passed job: https://app.saucelabs.com/tests/979a262f57724f80b45de70392039333

After:
Screenshot 2023-08-04 at 3 51 08 PM

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)

Checklist

  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • I have updated the json schema (if appropriate)

Further comments

@tianfeng92 tianfeng92 added the bug Something isn't working label Aug 4, 2023
@tianfeng92 tianfeng92 marked this pull request as ready for review August 4, 2023 22:57
@tianfeng92 tianfeng92 requested a review from a team as a code owner August 4, 2023 22:57
Copy link
Contributor

@mhan83 mhan83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So given that all docs say to explicitly use forward slashes, I'm confused whether this change actually fixes the issue. Kind of seems like it could be making things worse? How did you test this?

Given this node_modules:

node_modules
└── @saucelabs
    └── testcafe-reporter-saucelabs

On Windows, before your change, the archived directory would be node_modules\@saucelabs/testcafe-reporter-saucelabs (note the last separator is a /) since archive/zip is using path.Join instead of filepath.Join. And when unarchiving on Mac we would see this hierarchy (which matches what I see in the jira ticket):

└── node_modules
└── node_modules\@saucelabs
    └── testcafe-reporter-saucelabs

But after this change, the archived directory would be node_modules\@saucelabs\testcafe-reporter-saucelabs which, I think, would be unarchived like this on Mac? (I dunno I can't test this):

└── node_modules
└── node_modules\@saucelabs
└── node_modules\@saucelabs\testcafe-reporter-saucelabs

Makes me think maybe all we need here is filepath.ToSlash to make sure the path we give to Create always has forward slashes, regardless of platform... (https://pkg.go.dev/path/filepath#ToSlash)

internal/archive/zip/zip.go Outdated Show resolved Hide resolved
internal/archive/zip/zip.go Outdated Show resolved Hide resolved
@@ -71,7 +72,7 @@ func ArchiveFiles(targetFileName string, targetDir string, sourceDir string, fil
if err != nil {
return "", err
}
fileCount, length, err := z.Add(f, rel)
fileCount, length, err := z.Add(f, filepath.ToSlash(rel))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The root cause is

filepath.Rel(sourceDir, filepath.Dir(f))

returns node_modules\@cucumber on Windows.

@alexplischke alexplischke merged commit 5bcc18a into main Aug 7, 2023
18 checks passed
@alexplischke alexplischke deleted the devx-2459 branch August 7, 2023 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants