Get mode from stat

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2020-01-12 14:39:28 +01:00
parent 0ed473f52f
commit 7feb10b3cb
No known key found for this signature in database
GPG Key ID: 4C614C6ED2CDE6DF
1 changed files with 11 additions and 5 deletions

View File

@ -40,6 +40,8 @@ class NativeFileInfo implements IFileInfo {
*/ */
protected $modeCache; protected $modeCache;
protected $dosAttrUnavailable = false;
/** /**
* @param NativeShare $share * @param NativeShare $share
* @param string $path * @param string $path
@ -113,13 +115,17 @@ class NativeFileInfo implements IFileInfo {
*/ */
protected function getMode() { protected function getMode() {
if (!$this->modeCache) { if (!$this->modeCache) {
$stat = $this->stat(); try {
if (isset($stat['mode'])) { $attribute = $this->share->getAttribute($this->path, 'system.dos_attr.modea');
$this->modeCache = ($stat['mode']);
} else {
$attribute = $this->share->getAttribute($this->path, 'system.dos_attr.mode');
// parse hex string // parse hex string
$this->modeCache = (int)hexdec(substr($attribute, 2)); $this->modeCache = (int)hexdec(substr($attribute, 2));
} catch (\Exception $e) {
// getxattr should actually just return false here, so not sure why we are getting an error 104 from smbclient_state_errno
$this->dosAttrUnavailable = true;
$this->modeCache = ($this->stat()['mode'] & 0040000) ? IFileInfo::MODE_DIRECTORY : 0;
if (!($this->stat()['mode'] & 0200)) {
$this->modeCache ^= IFileInfo::MODE_READONLY;
}
} }
} }
return $this->modeCache; return $this->modeCache;