Integration
1 year ago
Vendors
1 year ago
.htaccess
1 year ago
Destination.php
1 year ago
DestinationDiskUsage.php
1 year ago
DestinationFile.php
1 year ago
DestinationWrapper.php
1 year ago
ScanDirIterator.php
1 year ago
ScanDirIteratorFile.php
1 year ago
Tree.php
1 year ago
index.html
1 year ago
web.config
1 year ago
ScanDirIteratorFile.php
170 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\Exception\IOVanishedException; |
| 15 | |
| 16 | if (!defined( '__JETBACKUP__')) die('Direct access is not allowed'); |
| 17 | |
| 18 | class ScanDirIteratorFile { |
| 19 | |
| 20 | const IFMT = 0170000; |
| 21 | const IFDIR = 0040000; |
| 22 | const IFCHR = 0020000; |
| 23 | const IFBLK = 0060000; |
| 24 | const IFREG = 0100000; |
| 25 | const IFIFO = 0010000; |
| 26 | const IFLNK = 0120000; |
| 27 | const IFSOCK = 0140000; |
| 28 | |
| 29 | private string $_path; |
| 30 | private string $_clean_path; |
| 31 | private array $_stat; |
| 32 | private bool $_pulled=false; |
| 33 | |
| 34 | /** |
| 35 | * @param string $path |
| 36 | * |
| 37 | * @throws IOVanishedException |
| 38 | */ |
| 39 | public function __construct(string $path) { |
| 40 | $this->_path = $path; |
| 41 | clearstatcache(true, $path); |
| 42 | $stat = @lstat($path); |
| 43 | if(!$stat) throw new IOVanishedException(sprintf("The file %s has vanished", $path)); |
| 44 | $this->_stat = $stat; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * @return string |
| 49 | */ |
| 50 | public function getPath():string { return $this->_path; } |
| 51 | |
| 52 | /** |
| 53 | * @return string |
| 54 | */ |
| 55 | public function getFullPath():string { |
| 56 | if(!isset($this->_clean_path)) $this->_clean_path = preg_replace("#/+#", "/", $this->getPath()); |
| 57 | return $this->_clean_path; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @return array |
| 62 | */ |
| 63 | public function getStat():array { return $this->_stat; } |
| 64 | |
| 65 | /** |
| 66 | * @return int |
| 67 | */ |
| 68 | public function getMode():int { return (int) $this->_stat['mode']; } |
| 69 | |
| 70 | /** |
| 71 | * @return int |
| 72 | */ |
| 73 | public function getSize():int { return (int) $this->_stat['size']; } |
| 74 | |
| 75 | /** |
| 76 | * @return int |
| 77 | */ |
| 78 | public function getModifyTime():int { return (int) $this->_stat['mtime']; } |
| 79 | |
| 80 | /** |
| 81 | * @return int |
| 82 | */ |
| 83 | public function getGroupId():int { return (int) $this->_stat['gid']; } |
| 84 | |
| 85 | /** |
| 86 | * @return int |
| 87 | */ |
| 88 | public function getOwnerId():int { return (int) $this->_stat['uid']; } |
| 89 | |
| 90 | /** |
| 91 | * @return string |
| 92 | */ |
| 93 | public function getGroup():string { |
| 94 | $group = posix_getgrgid($this->getGroupId()); |
| 95 | return $group ? $group['name'] : ''; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * @return string |
| 100 | */ |
| 101 | public function getOwner():string { |
| 102 | $user = posix_getpwuid($this->getOwnerId()); |
| 103 | return $user ? $user['name'] : ''; |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * @return int |
| 108 | */ |
| 109 | public function getType():int { |
| 110 | switch(($this->getMode() & self::IFMT)) { |
| 111 | case self::IFDIR: return DestinationFile::TYPE_DIRECTORY; |
| 112 | case self::IFCHR: return DestinationFile::TYPE_CHAR; |
| 113 | case self::IFBLK: return DestinationFile::TYPE_BLOCK; |
| 114 | case self::IFREG: return DestinationFile::TYPE_FILE; |
| 115 | case self::IFIFO: return DestinationFile::TYPE_FIFO; |
| 116 | case self::IFLNK: return DestinationFile::TYPE_LINK; |
| 117 | case self::IFSOCK: return DestinationFile::TYPE_SOCKET; |
| 118 | default: return DestinationFile::TYPE_UNKNOWN; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | public function setPulled():void { $this->_pulled = true; } |
| 123 | public function isPulled():bool { return $this->_pulled; } |
| 124 | |
| 125 | /** |
| 126 | * @return string |
| 127 | */ |
| 128 | public function getLinkTarget():string { return $this->isLink() ? readlink($this->getFullPath()) : ''; } |
| 129 | |
| 130 | /** |
| 131 | * @return bool |
| 132 | */ |
| 133 | public function isDir():bool { return ($this->getMode() & self::IFMT) == self::IFDIR; } |
| 134 | |
| 135 | /** |
| 136 | * @return bool |
| 137 | */ |
| 138 | public function isLinkDir():bool { return $this->isLink() && is_dir(realpath($this->getFullPath())); } |
| 139 | |
| 140 | /** |
| 141 | * @return bool |
| 142 | */ |
| 143 | public function isFile():bool { return ($this->getMode() & self::IFMT) == self::IFREG; } |
| 144 | |
| 145 | /** |
| 146 | * @return bool |
| 147 | */ |
| 148 | public function isLink():bool { return ($this->getMode() & self::IFMT) == self::IFLNK; } |
| 149 | |
| 150 | /** |
| 151 | * @return bool |
| 152 | */ |
| 153 | public function isBlockDevice():bool { return ($this->getMode() & self::IFMT) == self::IFBLK; } |
| 154 | |
| 155 | /** |
| 156 | * @return bool |
| 157 | */ |
| 158 | public function isCharacterDevice():bool { return ($this->getMode() & self::IFMT) == self::IFCHR; } |
| 159 | |
| 160 | /** |
| 161 | * @return bool |
| 162 | */ |
| 163 | public function isFifo():bool { return ($this->getMode() & self::IFMT) == self::IFIFO; } |
| 164 | |
| 165 | /** |
| 166 | * @return bool |
| 167 | */ |
| 168 | public function isSocket():bool { return ($this->getMode() & self::IFMT) == self::IFSOCK; } |
| 169 | } |
| 170 |