-
Notifications
You must be signed in to change notification settings - Fork 19
fix Notice: Undefined index: 0777 in Stat->mergeMeta #19
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -139,6 +139,38 @@ protected function getWithMetadata($path, array $ignore) | |||||||||
return $metadata; | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Normalize a permissions string. | ||||||||||
* | ||||||||||
* @param string $permissions | ||||||||||
* | ||||||||||
* @return int | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
*/ | ||||||||||
protected function normalizePermissions($permissions) | ||||||||||
{ | ||||||||||
if (is_numeric($permissions)) { | ||||||||||
return $permissions & 0777; | ||||||||||
} | ||||||||||
|
||||||||||
// remove the type identifier | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
$permissions = substr($permissions, 1); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This will work with or without the initial I considered padding with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like the original code is closer to what the comment says it's trying to do, but indeed Padding would make it mildly safer to use with the code below it, and if you're using
Suggested change
The comment could be updated to: // Extract the permission groups. The trickiest thing is how vague the file metadata is with Flysystem, but I suppose it has to be (for v1.x at least 😉). |
||||||||||
|
||||||||||
// map the string rights to the numeric counterparts | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
$map = ['-' => '0', 'r' => '4', 'w' => '2', 'x' => '1']; | ||||||||||
$permissions = strtr($permissions, $map); | ||||||||||
|
||||||||||
// split up the permission groups | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
$parts = str_split($permissions, 3); | ||||||||||
|
||||||||||
// convert the groups | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
$mapper = function ($part) { | ||||||||||
return array_sum(str_split($part)); | ||||||||||
}; | ||||||||||
|
||||||||||
// converts to decimal number | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
return octdec(implode('', array_map($mapper, $parts))); | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Merges the available metadata from Filesystem::getMetadata(). | ||||||||||
* | ||||||||||
|
@@ -154,7 +186,11 @@ protected function mergeMeta(array $metadata) | |||||||||
$ret['gid'] = $this->uid->getGid(); | ||||||||||
|
||||||||||
$ret['mode'] = $metadata['type'] === 'dir' ? 040000 : 0100000; | ||||||||||
$ret['mode'] += $this->permissions[$metadata['type']][$metadata['visibility']]; | ||||||||||
$visibility = $metadata['visibility']; | ||||||||||
if ($visibility != AdapterInterface::VISIBILITY_PUBLIC && $visibility != AdapterInterface::VISIBILITY_PRIVATE) { | ||||||||||
$visibility = $this->normalizePermissions($visibility) & 0044 ? AdapterInterface::VISIBILITY_PUBLIC : AdapterInterface::VISIBILITY_PRIVATE; | ||||||||||
} | ||||||||||
$ret['mode'] += $this->permissions[$metadata['type']][$visibility]; | ||||||||||
|
||||||||||
if (isset($metadata['size'])) { | ||||||||||
$ret['size'] = (int) $metadata['size']; | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.