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

taskPack modified to correctly set file permissions in ZIP files on Unix and on Windows NTFS #897

Open
wants to merge 1 commit into
base: 1.x
Choose a base branch
from

Conversation

MirazMac
Copy link

@MirazMac MirazMac commented Oct 5, 2019

Overview

This pull request:

  • Adds a feature

Summary

taskPack modified to correctly set file permissions in ZIP files on Unix and on Windows NTFS.

Description

Without these changes, on any *nix or Windows system, created ZIP files stores the files with the permission there is no way to change it. This fix adds code to automatically set permissions in archive same to permissions of original files for *nix systems. And since on Windows the file permissions are different and even keeping the original permissions doesn't work there. So, it sets the files permissions to 0644 by default on Windows.

Referenced here but the pull wasn't merged because of the coding style issue. I fixed it and added the Windows system workaround.
#888

Copy link
Member

@greg-1-anderson greg-1-anderson left a comment

Choose a reason for hiding this comment

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

Please use octal for chmod constants.

Tests would be nice-to-have.

$zip->setExternalAttributesName(
"{$placementLocation}/{$relativePathname}",
\ZipArchive::OPSYS_WINDOWS_NTFS,
33188 // Is the decimal for 100644
Copy link
Member

Choose a reason for hiding this comment

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

This would be clearer if expressed in octal (0100644).

I guess there is no +x bit on Windows? is-executable returns true only for .exe files, which is pointless on Linux. I guess manipulating Linux files on a Windows system just has to be an edge case that we don't / can't support.

Copy link
Author

Choose a reason for hiding this comment

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

Using Octal expression doesn't work on Windows, it seems only decimal values work on windows via setExternalAttributesName().
And this is not an edge case, many of the PHP devs develop on windows and may create an archive to distribute on linux servers. It causes a huge problem, like if the index/root file has a permission of 0666, it shows an 403 forbidden error when accessed via HTTP and file compressed via Robo in windows has 0666 permission for all the files(except directories, they have 0755).
So, I guess it would be an essential things to implement, I'm using this locally and it's working for me and someone may face the same issue in future that's why I created the pull request, it's your choice if you want to merge or not.
Thanks.

Copy link
Member

Choose a reason for hiding this comment

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

What do you get when you run this on Windows?

php -r 'print 0100644;'

Copy link
Author

Choose a reason for hiding this comment

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

By saying octal expression doesn't work on windows I meant about the setExternalAttributesName(); method's parameter, not the OS entirely.

Copy link
Member

Choose a reason for hiding this comment

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

That seems impossible to me; regardless of whether you represent a number in octal or decimal in the source, the data passed to a method parameter should be the same. Can you explain why setExternalAttributesName() fails with an octal parameter? What is at work here?

Copy link
Member

Choose a reason for hiding this comment

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

Please provide a test.

Copy link
Author

Choose a reason for hiding this comment

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

It seems it's an internal bug of PHP, besides setExternalAttributesName() isn't properly documented, the only example they provided is for the unix system and while on windows the octal values doesn't change the permission as expected, I'm kinda busy to write the tests, and I'm not sure what to tests against, as extracting the zip on windows to check if the has the permission of 0644 or not won't work on Windows because that's not how windows permissions work at all.
I'm closing this, thanks.

@MirazMac MirazMac closed this Oct 7, 2019
@greg-1-anderson
Copy link
Member

Maybe someone else will want to move this forward later.

The behavior of setExternalAttributesName() should not vary based on whether octal or binary is used.

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

Successfully merging this pull request may close these issues.

2 participants