Skip to content

Commit

Permalink
fix get dos attr
Browse files Browse the repository at this point in the history
  • Loading branch information
j3l11234 committed Jul 1, 2021
1 parent 9dba42a commit 0544ce3
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/Native/NativeFileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ public function getMTime(): int {
* older versions return the dos permissions mask as defined in `IFileInfo::MODE_*` while
* newer versions return the equivalent unix permission mask.
*
* Since the unix mask doesn't contain the proper hidden/archive/system flags we have to assume them
* as false (except for `hidden` where we use the unix dotfile convention)
* unix mask contain the proper hidden/archive/system flags with transfer.
* hidden -> o+x, archive -> u+x, system -> g+x,
* refer: https://gitlab.com/samba-team/samba/-/blob/84b5440eb4f3c10e2729e916d097f5af07150dcd/source3/libsmb/libsmb_stat.c#L67
*/

protected function getMode(): int {
Expand Down Expand Up @@ -117,7 +118,7 @@ public function isReadOnly(): bool {
public function isHidden(): bool {
$mode = $this->getMode();
if ($mode > 0x1000) {
return strlen($this->name) > 0 && $this->name[0] === '.';
return (bool)($mode & 0x1); // 0x01: hidden -> o+x
} else {
return (bool)($mode & IFileInfo::MODE_HIDDEN);
}
Expand All @@ -126,7 +127,7 @@ public function isHidden(): bool {
public function isSystem(): bool {
$mode = $this->getMode();
if ($mode > 0x1000) {
return false;
return (bool)($mode & 0x8); // 0x08: system -> g+x
} else {
return (bool)($mode & IFileInfo::MODE_SYSTEM);
}
Expand All @@ -135,7 +136,7 @@ public function isSystem(): bool {
public function isArchived(): bool {
$mode = $this->getMode();
if ($mode > 0x1000) {
return false;
return (bool)($mode & 0x40); // 0x40: archive -> u+x
} else {
return (bool)($mode & IFileInfo::MODE_ARCHIVE);
}
Expand Down

0 comments on commit 0544ce3

Please sign in to comment.