Integration
1 year ago
Vendors
1 month ago
.htaccess
1 year ago
Destination.php
1 month ago
DestinationDiskUsage.php
1 year ago
DestinationFile.php
1 year ago
DestinationWrapper.php
1 year ago
ScanDirIterator.php
1 year ago
ScanDirIteratorFile.php
8 months ago
Tree.php
1 year ago
index.html
1 year ago
web.config
1 year 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 |