1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2014 Robin Appelman <[email protected]> |
4
|
|
|
* This file is licensed under the Licensed under the MIT license: |
5
|
|
|
* http://opensource.org/licenses/MIT |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Icewind\SMB\Native; |
9
|
|
|
|
10
|
|
|
use Icewind\SMB\IFileInfo; |
11
|
|
|
|
12
|
|
|
class NativeFileInfo implements IFileInfo { |
13
|
|
|
const MODE_FILE = 0100000; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
protected $path; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $name; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var NativeShare |
27
|
|
|
*/ |
28
|
|
|
protected $share; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var array|null |
32
|
|
|
*/ |
33
|
|
|
protected $statCache; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var int |
37
|
|
|
*/ |
38
|
|
|
protected $modeCache; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param NativeShare $share |
42
|
|
|
* @param string $path |
43
|
|
|
* @param string $name |
44
|
|
|
* @param array $stat |
45
|
|
|
*/ |
46
|
104 |
|
public function __construct($share, $path, $name, $stat = null) { |
47
|
104 |
|
$this->share = $share; |
48
|
104 |
|
$this->path = $path; |
49
|
104 |
|
$this->name = $name; |
50
|
104 |
|
$this->statCache = $stat; |
51
|
104 |
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return string |
55
|
|
|
*/ |
56
|
102 |
|
public function getPath() { |
57
|
102 |
|
return $this->path; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return string |
62
|
|
|
*/ |
63
|
49 |
|
public function getName() { |
64
|
49 |
|
return $this->name; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return array |
69
|
|
|
*/ |
70
|
102 |
|
protected function stat() { |
71
|
102 |
|
if (is_null($this->statCache)) { |
72
|
102 |
|
$this->statCache = $this->share->getStat($this->getPath()); |
73
|
102 |
|
} |
74
|
102 |
|
return $this->statCache; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return int |
79
|
|
|
*/ |
80
|
29 |
|
public function getSize() { |
81
|
29 |
|
$stat = $this->stat(); |
82
|
29 |
|
return $stat['size']; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return int |
87
|
|
|
*/ |
88
|
1 |
|
public function getMTime() { |
89
|
1 |
|
$stat = $this->stat(); |
90
|
1 |
|
return $stat['mtime']; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return bool |
95
|
|
|
*/ |
96
|
101 |
|
public function isDirectory() { |
97
|
101 |
|
$stat = $this->stat(); |
98
|
101 |
|
return !($stat['mode'] & self::MODE_FILE); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return int |
103
|
|
|
*/ |
104
|
14 |
|
protected function getMode() { |
105
|
14 |
|
if (!$this->modeCache) { |
106
|
14 |
|
$attribute = $this->share->getAttribute($this->path, 'system.dos_attr.mode'); |
107
|
|
|
// parse hex string |
108
|
14 |
|
$this->modeCache = (int)hexdec(substr($attribute, 2)); |
109
|
14 |
|
} |
110
|
14 |
|
return $this->modeCache; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @return bool |
115
|
|
|
*/ |
116
|
9 |
|
public function isReadOnly() { |
117
|
9 |
|
$mode = $this->getMode(); |
118
|
9 |
|
return (bool)($mode & IFileInfo::MODE_READONLY); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return bool |
123
|
|
|
*/ |
124
|
13 |
|
public function isHidden() { |
125
|
13 |
|
$mode = $this->getMode(); |
126
|
13 |
|
return (bool)($mode & IFileInfo::MODE_HIDDEN); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @return bool |
131
|
|
|
*/ |
132
|
8 |
|
public function isSystem() { |
133
|
8 |
|
$mode = $this->getMode(); |
134
|
8 |
|
return (bool)($mode & IFileInfo::MODE_SYSTEM); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @return bool |
139
|
|
|
*/ |
140
|
8 |
|
public function isArchived() { |
141
|
8 |
|
$mode = $this->getMode(); |
142
|
8 |
|
return (bool)($mode & IFileInfo::MODE_ARCHIVE); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|