Skip to content

Compress-Archive is stripping UNIX file permissions #36

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

Open
pcgeek86 opened this issue Apr 19, 2017 · 16 comments
Open

Compress-Archive is stripping UNIX file permissions #36

pcgeek86 opened this issue Apr 19, 2017 · 16 comments
Milestone

Comments

@pcgeek86
Copy link

Related ticket: PowerShell/PowerShell#3590

Steps to reproduce

Set-Content -Path mytestfile.txt -Value testing
Compress-Archive -Path mytestfile.txt -Destination mytestzip.zip
zipinfo mytestzip.zip
Result of zipinfo command
Archive:  mytestzip.zip
Zip file size: 136 bytes, number of entries: 1
?---------  2.0 unx        8 b- defN 17-Apr-18 12:23 mytestfile.txt
1 file, 8 bytes uncompressed, 10 bytes compressed:  -25.0%

Expected behavior

Permissions of files are retained upon compression into ZIP format.

Actual behavior

Permissions are not preserved when files are compressed.

Environment data

Name                           Value
----                           -----
PSVersion                      6.0.0-alpha
PSEdition                      Core
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   3.0.0.0
GitCommitId                    v6.0.0-alpha.18
CLRVersion
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
PS /> uname -a
Darwin 16.5.0 Darwin Kernel Version 16.5.0: Fri Mar  3 16:52:33 PST 2017; root:xnu-3789.51.2~3/RELEASE_X86_64 x86_64

Cheers,
Trevor Sullivan

@tizoc
Copy link

tizoc commented Oct 3, 2019

Just got bitten by this.

@aktzbn
Copy link

aktzbn commented Oct 15, 2019

Have similar issue. After decompressing of archive created by Compress-Archive in pwsh a directory from archive has empty flags and it is not allowed enter there.

@phillip-haydon
Copy link

I'm running into this issue, does anyone have a solution?

@facekapow
Copy link

I'm running into this issue with Expand-Archive. I know that the archive was created with the permissions in place and other unarchivers extract it with the right permissions, but PowerShell's Expand-Archive doesn't extract the files with any permissions.

@MinuraIddamalgoda
Copy link

After trying to roll my own permissions updater in Python and Bash, I give up. It doesn't matter what the permissions for the file are before the Compress-Archive cmdlet is, the result is always the same as described in the OP.

Steps to re-create the container I'm running it in:

FROM openshift/jenkins-slave-maven-centos7:latest
...
curl https://packages.microsoft.com/config/rhel/7/prod.repo | tee /etc/yum.repos.d/microsoft.repo \
yum install -y powershell
...
bash-4.2$ pwsh -version
PowerShell 7.1.0
bash-4.2$ uname -a
Linux 37d8d15bcd70 4.19.76-linuxkit #1 SMP Tue May 26 11:42:35 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

The Python script I tried rolling vaguely looks like this:

subprocess.call(['chmod', '0755', path])

for root, dirs, files in os.walk(path):
  for d in dirs:
      os.chmod(os.path.join(root, d), 0o755)
  for f in files:
      os.chmod(os.path.join(root, f), 0o755)

Good luck to those who venture further, I think the easiest way forward is to fix the cmdlet or run Powershell on native Windows.

@Michael1015198808
Copy link

Got bitten by this as well. 😂

@jrjespersen
Copy link

I'm also encountering this issue - using PowerShell to zip up and update AWS lambda function (python) from macOS. Would like to continue using PowerShell for this, but I have no option to adjust file permissions after the file is unzipped.

@b-olesen
Copy link

b-olesen commented Oct 8, 2021

Got bitten by the same bug running PS 7.0.3
any fixes out there ?

GitCommitId 7.0.3
OS Darwin 19.6.0 Darwin Kernel Version 19.6.0: Thu May 6 00:48:39 PDT 2021; root:xnu-6153.141.33~1/RELEASE_X86_64

@phillip-haydon
Copy link

@b-olesen I moved my builds/deploys from windows to linux, partly because of this issue. I did temporarly pull down AWS toolkit and extract a tool from their code to do the zipping as a .net core cli tool which worked, but it was such a pain to setup.

As far as I'm concerned zipping via powershell is broken, and I'm too dumb to know how to fix it to ty contribute back :(

@scorpionlion
Copy link

scorpionlion commented Apr 21, 2022

faced the same issue while deploying the Zip created using Compress-Archive on Azure App Service (Linux). The service fails to start by throwing realpath(my.dll) failed: Input/output error when running startup command dotnet my.dll, upon listing the files in extracted folder we found the permissions were missing. So we ended up using linux zip command instead of PS core Compress-Archive. It would be nice if Compress-Archive also supports retaining permissions.

@SydneyhSmith SydneyhSmith added this to the 1.2.0 milestone Jun 1, 2022
@FCAADMIN
Copy link

FCAADMIN commented Jul 7, 2022

Any tentative timelines to fix this ?

@ayousuf23
Copy link
Contributor

Currently this is not possible due to .NET API limitations.

@fashaikh
Copy link

@ayousuf23 Any ETA on when the ,net API limitations will be addressed ?

@hwoodiwiss
Copy link

@ayousuf23 Any ETA on when the ,net API limitations will be addressed ?

If they haven't been in .NET 7, I would imagine it wouldn't be until at least November when .NET 8 releases.

@hwoodiwiss
Copy link

hwoodiwiss commented Mar 21, 2023

I think this may be possible in .NET 7? Couldn't FileSystemInfo.UnixFileMode be used to populate the ZipArchiveEntry.ExternalAttributes?

@hwoodiwiss
Copy link

It's worth noting that from pwsh 7.3, when this started being build for .NET 7, I think Compress-Archive should have started applying some default permissions (defined here), and that does seem to have been my experience, tested in WSL2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.