Skip to content

Specify permissions using strings #1051

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

Closed
tontonsb opened this issue Aug 3, 2019 · 3 comments
Closed

Specify permissions using strings #1051

tontonsb opened this issue Aug 3, 2019 · 3 comments
Labels

Comments

@tontonsb
Copy link

tontonsb commented Aug 3, 2019

Feature Request

Q A
New Feature yes
BC Break yes

Scenario

There's a possibility to specify "visibility => permission" mapping for the local adapter. While the syntax is fine for specifying 0775 instead of 0755, a catastrophe occurs if you naively set the first octet. 1777 actually sets the permissions to 3361. To set the 1777 permissions one actually has to specify either the octal 01777 or the decimal 1023.

Summary

I propose to allow optional string syntax for permissions. The strings should be translated to permissions as naively expected - '1777' should actually set 1777 permissions.

This syntax should also be used in the codebase so the example in the code would be the one that behaves as would be expected.

How is this breaking?

'sticky' => 01777 works and would keep working. 'sticky' => 1023 works and would keep working. 'sticky' => 1777 is crazy, but would keep working as it does.

The case that breaks is where one would already be using strings. Undocumented but it works. 'sticky' => '1777' currently sets 3361, but according to my proposal this stringed directive should set permissions to 1777.

@frankdejonge
Copy link
Member

I get what you're saying, but I don't want to bump a major for this. We could ship with an added utility function that safely translates the string permissions to their octal counterparts, this way there's no BC break but people can use the tooling. It would even accept either type and convert based on the need.

@tontonsb
Copy link
Author

tontonsb commented Aug 4, 2019

Sure, it coud be as simple as

function mode($mode)
{
	if (!is_string($mode))
		return $mode;

	return octdec($modeString);
}

Or, tu support those fancy drwSrwxr-T something like this would work

function mode($modeString)
{
	if (!is_string($modeString))
		return $modeString;

	if (is_numeric($modeString))
		return octdec($modeString);
	
	$mode = 0;
	$special = 0;

	for ($i = 0; $i < strlen($modeString); $i++)
	{
		$mode = $mode << 1;
		
		if (0 == $i % 3)
		    $special = $special << 1;

		$char = $modeString[$i];
		
		if (in_array($char, ['S', 's', 'T', 't']))
			$special |= 1;

		if (in_array($char, ['-', 'S', 'T', 'd']))
			continue;

		$mode |= 1;
	}

	return $mode |= ($special << 9);
}

@stale
Copy link

stale bot commented Oct 4, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

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

No branches or pull requests

2 participants