PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 3.1.18.8
JetBackup – Backup, Restore & Migrate v3.1.18.8
3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / src / JetBackup / Destination / ScanDirIteratorFile.php
backup / src / JetBackup / Destination Last commit date
Integration 5 months ago Vendors 5 months ago .htaccess 5 months ago Destination.php 5 months ago DestinationDiskUsage.php 5 months ago DestinationFile.php 5 months ago DestinationWrapper.php 5 months ago ScanDirIterator.php 5 months ago ScanDirIteratorFile.php 5 months ago Tree.php 5 months ago index.html 5 months ago web.config 5 months ago
ScanDirIteratorFile.php
171 lines
1 <?php
2 /*
3 *
4 * JetBackup @ package
5 * Created By Idan Ben-Ezra
6 *
7 * Copyrights @ JetApps
8 * https://www.jetapps.com
9 *
10 **/
11 namespace JetBackup\Destination;
12
13 use JetBackup\Destination\Integration\DestinationFile;
14 use JetBackup\Entities\Util;
15 use JetBackup\Exception\IOVanishedException;
16
17 if (!defined( '__JETBACKUP__')) die('Direct access is not allowed');
18
19 class ScanDirIteratorFile {
20
21 const IFMT = 0170000;
22 const IFDIR = 0040000;
23 const IFCHR = 0020000;
24 const IFBLK = 0060000;
25 const IFREG = 0100000;
26 const IFIFO = 0010000;
27 const IFLNK = 0120000;
28 const IFSOCK = 0140000;
29
30 private string $_path;
31 private string $_clean_path;
32 private array $_stat;
33 private bool $_pulled=false;
34
35 /**
36 * @param string $path
37 *
38 * @throws IOVanishedException
39 */
40 public function __construct(string $path) {
41 $this->_path = $path;
42 clearstatcache(true, $path);
43 $stat = @lstat($path);
44 if(!$stat) throw new IOVanishedException(sprintf("The file %s has vanished", $path));
45 $this->_stat = $stat;
46 }
47
48 /**
49 * @return string
50 */
51 public function getPath():string { return $this->_path; }
52
53 /**
54 * @return string
55 */
56 public function getFullPath():string {
57 if(!isset($this->_clean_path)) $this->_clean_path = preg_replace("#/+#", "/", $this->getPath());
58 return $this->_clean_path;
59 }
60
61 /**
62 * @return array
63 */
64 public function getStat():array { return $this->_stat; }
65
66 /**
67 * @return int
68 */
69 public function getMode():int { return (int) $this->_stat['mode']; }
70
71 /**
72 * @return int
73 */
74 public function getSize():int { return (int) $this->_stat['size']; }
75
76 /**
77 * @return int
78 */
79 public function getModifyTime():int { return (int) $this->_stat['mtime']; }
80
81 /**
82 * @return int
83 */
84 public function getGroupId():int { return (int) $this->_stat['gid']; }
85
86 /**
87 * @return int
88 */
89 public function getOwnerId():int { return (int) $this->_stat['uid']; }
90
91 /**
92 * @return string
93 */
94 public function getGroup():string {
95 $group = Util::getgrgid($this->getGroupId());
96 return $group ? $group['name'] : '';
97 }
98
99 /**
100 * @return string
101 */
102 public function getOwner():string {
103 $user = Util::getpwuid($this->getOwnerId());
104 return $user ? $user['name'] : '';
105 }
106
107 /**
108 * @return int
109 */
110 public function getType():int {
111 switch(($this->getMode() & self::IFMT)) {
112 case self::IFDIR: return DestinationFile::TYPE_DIRECTORY;
113 case self::IFCHR: return DestinationFile::TYPE_CHAR;
114 case self::IFBLK: return DestinationFile::TYPE_BLOCK;
115 case self::IFREG: return DestinationFile::TYPE_FILE;
116 case self::IFIFO: return DestinationFile::TYPE_FIFO;
117 case self::IFLNK: return DestinationFile::TYPE_LINK;
118 case self::IFSOCK: return DestinationFile::TYPE_SOCKET;
119 default: return DestinationFile::TYPE_UNKNOWN;
120 }
121 }
122
123 public function setPulled():void { $this->_pulled = true; }
124 public function isPulled():bool { return $this->_pulled; }
125
126 /**
127 * @return string
128 */
129 public function getLinkTarget():string { return $this->isLink() ? readlink($this->getFullPath()) : ''; }
130
131 /**
132 * @return bool
133 */
134 public function isDir():bool { return ($this->getMode() & self::IFMT) == self::IFDIR; }
135
136 /**
137 * @return bool
138 */
139 public function isLinkDir():bool { return $this->isLink() && is_dir(realpath($this->getFullPath())); }
140
141 /**
142 * @return bool
143 */
144 public function isFile():bool { return ($this->getMode() & self::IFMT) == self::IFREG; }
145
146 /**
147 * @return bool
148 */
149 public function isLink():bool { return ($this->getMode() & self::IFMT) == self::IFLNK; }
150
151 /**
152 * @return bool
153 */
154 public function isBlockDevice():bool { return ($this->getMode() & self::IFMT) == self::IFBLK; }
155
156 /**
157 * @return bool
158 */
159 public function isCharacterDevice():bool { return ($this->getMode() & self::IFMT) == self::IFCHR; }
160
161 /**
162 * @return bool
163 */
164 public function isFifo():bool { return ($this->getMode() & self::IFMT) == self::IFIFO; }
165
166 /**
167 * @return bool
168 */
169 public function isSocket():bool { return ($this->getMode() & self::IFMT) == self::IFSOCK; }
170 }
171