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

FileArchive creates zip files with backslashes on Windows #16273

Open
stevebutler opened this issue May 28, 2024 · 2 comments
Open

FileArchive creates zip files with backslashes on Windows #16273

stevebutler opened this issue May 28, 2024 · 2 comments
Assignees
Labels
area/assets-and-archives FileAsset/FileArchive etc. kind/bug Some behavior is incorrect or out of spec os/windows

Comments

@stevebutler
Copy link

What happened?

In a Pulumi Python project, on a Windows 11 computer, I created an S3 bucket object based on an AssetArchive containing a FileArchive. The Pulumi update was successful, and the zip file was present in S3. An AWS CodeBuild project takes the zip file as its source, running on "aws/codebuild/amazonlinu2-x86_64-standard:5.0".

On the Linux host, I expected the "ls -R" command to show a nested directory tree. Instead, it showed a list of files with backslashes in their names.

I downloaded the zip file to Windows 11, and both Explorer and 7zip open the file and show the nested directory tree with no complaints. Opening the zip file in Notepad++, I see backslashes in filenames.

Example

ansible_bundle = aws.s3.BucketObject(
    resource_name="AnsibleBundleZip",
    key="codebuild-src/ansible-bundle.zip",
    bucket=deployment.src_bucket_id,
    source=pulumi.AssetArchive({
        ".": pulumi.FileArchive("AnsibleBundle"),
    }),
    server_side_encryption='AES256'
)

Output of pulumi about

pulumi about
CLI
Version 3.117.0
Go Version go1.22.3
Go Compiler gc

Plugins
KIND NAME VERSION
resource aws 6.37.1
resource aws-native 0.103.0
language python unknown

Host
OS Microsoft Windows 11 Enterprise
Version 10.0.22631 Build 22631
Arch x86_64

This project is written in python: executable='C:\projects\bit\poetry-demo.venv\Scripts\python.exe' version='3.12.3'
[...]

Additional context

A similar bug (#2784) was fixed five years ago.

Contributing

Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

@stevebutler stevebutler added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels May 28, 2024
@justinvp justinvp added area/assets-and-archives FileAsset/FileArchive etc. and removed needs-triage Needs attention from the triage team labels Jun 3, 2024
@justinvp
Copy link
Member

justinvp commented Jun 3, 2024

Thanks for opening the issue @stevebutler and sorry for the trouble. I was able to reproduce this behavior by running the following test on Windows and removing the filepath.ToSlash calls around the actual values.

assert.Equal(t, "foo/a.txt", filepath.ToSlash(files[0].Name))
assert.Equal(t, "foo/bar/b.txt", filepath.ToSlash(files[1].Name))
assert.Equal(t, "fake.txt", filepath.ToSlash(files[2].Name))

I would expect the names to be using forward slashes, but looks like they are not. I haven't had a chance to dig deeper yet.

@justinvp
Copy link
Member

justinvp commented Jun 3, 2024

Looks like the problem is here:

// The subarchive produced a valid blob. Return it.
return filepath.Join(r.archiveRoot, name), blob, nil

That is going to produce file names in the zip with back slashes on Windows, which is not what we want. That should be wrapped in filepath.ToSlash to avoid including back slashes in the name.

@justinvp justinvp self-assigned this Jun 3, 2024
@justinvp justinvp added this to the 0.105 milestone Jun 3, 2024
@mikhailshilkov mikhailshilkov removed this from the 0.105 milestone Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/assets-and-archives FileAsset/FileArchive etc. kind/bug Some behavior is incorrect or out of spec os/windows
Projects
None yet
Development

No branches or pull requests

3 participants