cake-build / cake-build/cake

Zip doesn't preserve file permissions on Linux

Open
#2,592 12 comments 0 reactions 0 assignees View on GitHub
Bug Help wanted Up-for-grabs
Dominant language
C#
Stars
4.2k
Forks
778
Avg merge
3h 37m
Merged PRs (30d)
21

Description

### What You Are Seeing?
Using something like:

```
Zip(Directory("d"), File("test.zip"));
```

The zip file contents are correct, but linux file permissions (ugoa rwx) are not preserved within the zip file, when run on Linux.

### What is Expected?

I should be able to list the zip file contents using `unzip -Zl` and see the linux file permissions that were set before zipping.

### What version of Cake are you using?
dotnet core
cake.tool version '0.34.1'

### Are you running on a 32 or 64 bit system?
64 bit

### What environment are you running on? Windows? Linux? Mac?
Linux

### Are you running on a CI Server? If so, which one?
Yes, but I see the same results running locally.

### How Did You Get This To Happen? (Steps to Reproduce)
1. Create a script file on Linux:
```bash
mkdir d
echo '#!/bin/bash' > d/test.sh
echo "echo foo" >> d/test.sh
chmod a+x d/test.sh
```
2. Write a build.cake script to zip the directory:
```c#
Zip(Directory("d"), File("test.zip"));
```
3. Install the cake.tool
```bash
dotnet tool install -g cake.tool
```
4. Run the cake script
```bash
dotnet cake
```
5. Check the contents of the zipped file:
```bash
$ unzip -Zl test.zip
Archive: test.zip
Zip file size: 135 bytes, number of entries: 1
?--------- 2.0 unx 21 b- 23 defN 19-Aug-05 14:13 test.sh
1 file, 21 bytes uncompressed, 23 bytes compressed: -9.5%
```

In contrast, if the zip file is created with the linux zip command (infozip), the file contents are:
```bash
$ unzip -Zl linux-test.zip
Archive: linux-test.zip
Zip file size: 185 bytes, number of entries: 1
-rwxrwxrwx 3.0 unx 21 tx 21 stor 19-Aug-05 14:13 test.sh
1 file, 21 bytes uncompressed, 21 bytes compressed: 0.0%
```
which shows that the file permissions are preserved in the zip file.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with the provided build.cake Zip(Directory("d"), File("test.zip")) script on Linux, then inspect the Cake Zip implementation and its existing tests. Compare unzip -Zl output with the Info-ZIP result; done means archive entries retain the source files' Linux permissions.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, linux
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.