From b074619fff11f8e74853912ccd02cd26b4d7d414 Mon Sep 17 00:00:00 2001 From: j3l11234 <297259024@qq.com> Date: Sat, 3 Jul 2021 18:22:55 +0000 Subject: [PATCH] fix: get hidden/archive/system porps on file --- src/Native/NativeFileInfo.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Native/NativeFileInfo.php b/src/Native/NativeFileInfo.php index 539bb72..3406244 100644 --- a/src/Native/NativeFileInfo.php +++ b/src/Native/NativeFileInfo.php @@ -85,6 +85,10 @@ public function getMTime(): int { * * 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) + * + * But on file, 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 { @@ -117,7 +121,11 @@ public function isReadOnly(): bool { public function isHidden(): bool { $mode = $this->getMode(); if ($mode > 0x1000) { - return strlen($this->name) > 0 && $this->name[0] === '.'; + if ($mode & 0x4000) { // is directory + return strlen($this->name) > 0 && $this->name[0] === '.'; + } else { + return (bool)($mode & 0x1); // 0x01: hidden -> o+x + } } else { return (bool)($mode & IFileInfo::MODE_HIDDEN); } @@ -126,7 +134,11 @@ public function isHidden(): bool { public function isSystem(): bool { $mode = $this->getMode(); if ($mode > 0x1000) { - return false; + if ($mode & 0x4000) { // is directory + return false; + } else { + return (bool)($mode & 0x8); // 0x08: system -> g+x + } } else { return (bool)($mode & IFileInfo::MODE_SYSTEM); } @@ -135,7 +147,11 @@ public function isSystem(): bool { public function isArchived(): bool { $mode = $this->getMode(); if ($mode > 0x1000) { - return false; + if ($mode & 0x4000) { // is directory + return false; + } else { + return (bool)($mode & 0x40); // 0x40: archive -> u+x + } } else { return (bool)($mode & IFileInfo::MODE_ARCHIVE); }