mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 17:24:07 +02:00
Introduce FileInfo objects for the result of dir and add readable and hidden attributes to files
This commit is contained in:
parent
b2edd174f1
commit
1c11289d36
7 changed files with 452 additions and 53 deletions
122
src/NativeFileInfo.php
Normal file
122
src/NativeFileInfo.php
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
|
||||
* This file is licensed under the Licensed under the MIT license:
|
||||
* http://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Icewind\SMB;
|
||||
|
||||
class NativeFileInfo implements IFileInfo {
|
||||
const MODE_FILE = 0100000;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $path;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* @var \Icewind\SMB\NativeShare
|
||||
*/
|
||||
protected $share;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $statCache;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $modeCache;
|
||||
|
||||
/**
|
||||
* @param \Icewind\SMB\NativeShare $share
|
||||
* @param string $path
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($share, $path, $name) {
|
||||
$this->share = $share;
|
||||
$this->path = $path;
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPath() {
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function stat() {
|
||||
if (!$this->statCache) {
|
||||
$this->statCache = $this->share->stat($this->getPath());
|
||||
}
|
||||
return $this->statCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getSize() {
|
||||
$stat = $this->stat();
|
||||
return $stat['size'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getMTime() {
|
||||
$stat = $this->stat();
|
||||
return $stat['mtime'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isDirectory() {
|
||||
$stat = $this->stat();
|
||||
return !($stat['mode'] & self::MODE_FILE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
protected function getMode() {
|
||||
if (!$this->modeCache) {
|
||||
$this->modeCache = $this->share->getAttribute($this->path, 'system.dos_attr.mode');
|
||||
}
|
||||
return $this->modeCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isReadOnly() {
|
||||
$mode = $this->getMode();
|
||||
return (bool)($mode & FileInfo::MODE_READONLY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isHidden() {
|
||||
$mode = $this->getMode();
|
||||
return (bool)($mode & FileInfo::MODE_HIDDEN);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue