Skip to content

Commit b074619

Browse files
committed
fix: get hidden/archive/system porps on file
1 parent 9dba42a commit b074619

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/Native/NativeFileInfo.php

+19-3
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ public function getMTime(): int {
8585
*
8686
* Since the unix mask doesn't contain the proper hidden/archive/system flags we have to assume them
8787
* as false (except for `hidden` where we use the unix dotfile convention)
88+
*
89+
* But on file, unix mask contain the proper hidden/archive/system flags with transfer.
90+
* hidden -> o+x, archive -> u+x, system -> g+x,
91+
* refer: https://gitlab.com/samba-team/samba/-/blob/84b5440eb4f3c10e2729e916d097f5af07150dcd/source3/libsmb/libsmb_stat.c#L67
8892
*/
8993

9094
protected function getMode(): int {
@@ -117,7 +121,11 @@ public function isReadOnly(): bool {
117121
public function isHidden(): bool {
118122
$mode = $this->getMode();
119123
if ($mode > 0x1000) {
120-
return strlen($this->name) > 0 && $this->name[0] === '.';
124+
if ($mode & 0x4000) { // is directory
125+
return strlen($this->name) > 0 && $this->name[0] === '.';
126+
} else {
127+
return (bool)($mode & 0x1); // 0x01: hidden -> o+x
128+
}
121129
} else {
122130
return (bool)($mode & IFileInfo::MODE_HIDDEN);
123131
}
@@ -126,7 +134,11 @@ public function isHidden(): bool {
126134
public function isSystem(): bool {
127135
$mode = $this->getMode();
128136
if ($mode > 0x1000) {
129-
return false;
137+
if ($mode & 0x4000) { // is directory
138+
return false;
139+
} else {
140+
return (bool)($mode & 0x8); // 0x08: system -> g+x
141+
}
130142
} else {
131143
return (bool)($mode & IFileInfo::MODE_SYSTEM);
132144
}
@@ -135,7 +147,11 @@ public function isSystem(): bool {
135147
public function isArchived(): bool {
136148
$mode = $this->getMode();
137149
if ($mode > 0x1000) {
138-
return false;
150+
if ($mode & 0x4000) { // is directory
151+
return false;
152+
} else {
153+
return (bool)($mode & 0x40); // 0x40: archive -> u+x
154+
}
139155
} else {
140156
return (bool)($mode & IFileInfo::MODE_ARCHIVE);
141157
}

0 commit comments

Comments
 (0)