-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Compression.ZipFile support for Unix Permissions #1548
Comments
Users also run into this issue when attempting to use |
@stephentoub @JeremyKuhne @terrajobst @eerhardt @ViktorHofer this is now ready for review, so please take a look. I have a changeset with an implementation nearly ready to go, so I'd like to have this reviewed soon i.e. before I go on paternity leave :) |
What is the expected behavior if you try to do this on Windows? PlatformNotSupported? |
On Windows, the value of |
I see there are no API changes proposed for this behavior. Is the expectation that we will always store the permissions on Unix? Or will there be a way to |
Correct, we will always store the permissions when creating a zip on a Unix machine, such that roundtripping using There are a few reasons why I want this to be the default behavior:
I'm not against adding an opt-out, but I've got a lot of upcoming ZipFile APIs with new behavioral options, so the API space is going to get big fast. Another option would be instead of adding a bunch of public class ZipFileOptions
{
bool Overwrite = false;
bool preserveUnixPermissions = true;
Encoding encoding = null;
CompressionLevel compressionLevel = CompressionLevel.Optimal;
}
public static partial class ZipFile
{
...
public static void CreateFromDirectory(string sourceDirectoryName, string destinationArchiveFileName, ZipFileOptions options) {}
public static void ExtractToDirectory(string sourceArchiveFileName, string destinationDirectoryName, ZipFileOptions options) {}
...
}
public class ZipFileTests
{
...
CreateFromDirectory(somedir, outputzip, new ZipFileOptions() {overwrite = false, preserveUnixPermissions = false});
...
} |
I'm fine with not having an opt out, until we have a scenario for it. |
Works for me :) |
We'd prefer the default to be "preserve executable bit" on compression. We're leaning towards saying the same about extraction. Open questions:
@ianhays , could you follow up? |
@ianhays is on leave until late Sept. So if someone cares about this, they should look at these open questions (or ping him then...) |
Other zip tools all store the full permissions set when packaging and apply them when opening.
If we are fine with storing and applying the permissions every time, then the extra API is unnecessary.
@terrajobst Only the executable bit? I don't think I've seen that before. Seems like full RWX would be better. |
Tentatively moving this to the 3.0 milestone for better tracking |
This is DCR level work at this point. Moving to Future. |
Triage: Note: We could also expose the permissions in the ZipArchiveEntry. |
We are already exposing
It was done with dotnet/corefx#18565 |
How is it supposed to be used? Like this? I don't get it 🤷♂️ ZipArchiveEntry entry = zipArchive.CreateEntry("file.txt");
entry.ExternalAttributes = 644; |
@marcwittke The original issue (#20603) links to a Stack Exchange answer, which explains the format. It's certainly not as simple as using the octal notation of the permissions you want. |
yeah, found it, read the cryptic part (hey, I am writing code in .net for not having to shift bits 🤣 ) and came up with this: entry.ExternalAttributes = entry.ExternalAttributes | (Convert.ToInt32("664", 8) << 16); key is that the permission is an octal literal, that does not exist out-of-the-box in .net. |
This issue is now more than 3 years old, and the implementation is not that difficult; the conclusion from the discussion was that no API change was needed at this point since permissions save/apply on Unix is by-default, like other Unix tools (ZipInfo). |
When running on Unix, capture the file's permissions on ZipFile Create and write the captured file permissions on ZipFile Extract. Fix dotnet#1548
* Compression.ZipFile support for Unix Permissions When running on Unix, capture the file's permissions on ZipFile Create and write the captured file permissions on ZipFile Extract. Fix #1548
Thanks for doing this, @eerhardt!! |
Split from dotnet/corefx#17067
Proposal
We should add support in the Unix ZipFile for working with zips that contain entries with associated file permissions information. Right now the only way to capture or check the permissions info of an entry is to do some manual bit shifting of the
ExternalAttributes
field. We can do better than that.Wanting your zips to unzip with the same permissions they were zipped with is a very common scenario that we do not currently support. I propose that we do two things:
New API
Implementation
The follow-through here is relatively easy - stat files on creation, chmod them on extraction. The somewhat bothersome part is that we will need to make the System.IO.Compression.ZipFile assembly platform-specific because the new permissions support will be Unix-only.
Work-in-Progress solution available here: https://github.com/ianhays/corefx/commits/zipfile_perms
Benefit
Zips created using ZipFile on Unix will be usable interchangeably with those created using the
zip
command as far as permissions are concerned. Using ZipFile to unzip zips created withzip
will create files that have the same permissions as they were created with. Makes our Unix users happy. @eerhardt is happy.PTAL: @stephentoub @JeremyKuhne @terrajobst @eerhardt @ViktorHofer
The text was updated successfully, but these errors were encountered: