/** * Extract files from the archive * * @return true on success */ function extract_files() { $pwd = getcwd(); chdir($this->options['basedir']); if ($fp = $this->open_archive()) { if ($this->options['inmemory'] == 1) { $this->files = array(); } while ($block = fread($fp, 512)) { $temp = unpack("a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100temp/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp", $block); $file = array('name' => $temp['prefix'] . $temp['name'], 'stat' => array(2 => $temp['mode'], 4 => octdec($temp['uid']), 5 => octdec($temp['gid']), 7 => octdec($temp['size']), 9 => octdec($temp['mtime'])), 'checksum' => octdec($temp['checksum']), 'type' => $temp['type'], 'magic' => $temp['magic']); if ($file['checksum'] == 0x0) { break; } else { /*if ($file['magic'] != "ustar") { $this->raiseError("This script does not support extracting this type of tar file."); break; }*/ $block = substr_replace($block, " ", 148, 8); } $checksum = 0; for ($i = 0; $i < 512; $i++) { $checksum += ord(io::substr($block, $i, 1)); } if ($file['checksum'] != $checksum) { $this->raiseError("Could not extract from {$this->options['name']}, it is corrupt."); } if ($this->options['inmemory'] == 1) { $file['data'] = @fread($fp, $file['stat'][7]); @fread($fp, 512 - $file['stat'][7] % 512 == 512 ? 0 : 512 - $file['stat'][7] % 512); unset($file['checksum'], $file['magic']); $this->files[] = $file; } else { if ($file['type'] == 5) { if (!is_dir($file['name'])) { /*if ($this->options['forceWriting']) { chmod($file['name'], 1777); }*/ if (!$this->options['dontUseFilePerms']) { @mkdir($file['name'], $file['stat'][2]); //pr($file['name'].' : '.$file['stat'][4]); //pr($file['name'].' : '.$file['stat'][5]); @chown($file['name'], $file['stat'][4]); @chgrp($file['name'], $file['stat'][5]); } else { @mkdir($file['name']); } } } else { if ($this->options['overwrite'] == 0 && file_exists($file['name'])) { $this->raiseError("{$file['name']} already exists."); } else { //check if destination dir exists $dirname = dirname($file['name']); if (!is_dir($dirname)) { CMS_file::makeDir($dirname); } if ($new = @fopen($file['name'], "wb")) { @fwrite($new, @fread($fp, $file['stat'][7])); @fread($fp, 512 - $file['stat'][7] % 512 == 512 ? 0 : 512 - $file['stat'][7] % 512); @fclose($new); //pr($file['name'].' : '.$file['stat'][2]); if (!$this->options['dontUseFilePerms']) { @chmod($file['name'], $file['stat'][2]); @chown($file['name'], $file['stat'][4]); @chgrp($file['name'], $file['stat'][5]); } /*if ($this->options['forceWriting']) { chmod($file['name'], 0777); }*/ } else { $this->raiseError("Could not open {$file['name']} for writing."); } } } } unset($file); } } else { $this->raiseError("Could not open file {$this->options['name']}"); } chdir($pwd); return true; }
//remove old dir if (!$errorCopy) { if (!CMS_file::deltree(PATH_REALROOT_FS . '/automne_bin', true)) { $actionsTodo .= '- Delete directory ' . PATH_REALROOT_WR . '/automne_bin <br/>'; } else { $actionsDone .= '- Deleted directory ' . PATH_REALROOT_WR . '/automne_bin <br/>'; } } else { $actionsTodo .= '- Delete directory ' . PATH_REALROOT_WR . '/automne_bin <br/>'; } } // Move /sql (only files which not already exists) if (is_dir(PATH_REALROOT_FS . '/sql')) { //create new directory if (!is_dir(PATH_MAIN_FS . "/sql")) { if (!CMS_file::makeDir(PATH_MAIN_FS . "/sql")) { $actionsTodo .= '- Create directory ' . PATH_MAIN_WR . '/sql <br/>'; } else { $actionsDone .= '- Created directory ' . PATH_MAIN_WR . '/sql <br/>'; } } //copy all files from old directory to new one if they do not already exists $errorCopy = false; try { foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(PATH_REALROOT_FS . '/sql'), RecursiveIteratorIterator::SELF_FIRST) as $file) { if ($file->isFile() && $file->getFilename() != ".htaccess") { $to = str_replace(PATH_REALROOT_FS . '/sql', '', $file->getPathname()); if (!file_exists(PATH_MAIN_FS . '/sql' . $to)) { if (!CMS_file::copyTo($file->getPathname(), PATH_MAIN_FS . '/sql' . $to)) { $errorCopy = true; $actionsTodo .= '- Copy file from ' . $file->getPathname() . ' to ' . PATH_MAIN_FS . '/sql' . $to . ' <br/>';
/** * Create the folder of an alias * * @return boolean true on success, false on failure * @access private */ private function _createFolder() { if (!$this->getAlias()) { $this->raiseError("Must have an alias name to create directory"); return false; } if (!CMS_file::makeDir($this->getPath(true, PATH_RELATIVETO_FILESYSTEM))) { $this->raiseError("Cannot create directory " . $this->getPath(true, PATH_RELATIVETO_FILESYSTEM)); return false; } return true; }
/** * Gets the pages directory. It's derived from the label * * @param string $relativeTo Can be PATH_RELATIVETO_WEBROOT for relative to website root, or PATH_RELATIVETO_FILESYSTEM for relative to filesystem root * @return string The pages directory. * @access public */ function getPagesPath($relativeTo) { if ($this->_codename) { if (SensitiveIO::isInSet($relativeTo, array(PATH_RELATIVETO_WEBROOT, PATH_RELATIVETO_FILESYSTEM))) { $relative = $relativeTo == PATH_RELATIVETO_WEBROOT ? PATH_PAGES_WR : PATH_PAGES_FS; if ($this->_isMain) { if (!is_dir(PATH_PAGES_FS)) { if (!CMS_file::makeDir(PATH_PAGES_FS)) { $this->raiseError('Can\'t create pages dir : ' . PATH_PAGES_FS); } } return $relative; } else { if (!is_dir(PATH_PAGES_FS . "/" . io::sanitizeAsciiString($this->_codename))) { if (!CMS_file::makeDir(PATH_PAGES_FS . "/" . io::sanitizeAsciiString($this->_codename))) { $this->raiseError('Can\'t create pages dir : ' . PATH_PAGES_FS . '/' . io::sanitizeAsciiString($this->_codename)); } } return $relative . '/' . io::sanitizeAsciiString($this->_codename); } } else { $this->raiseError("Can't give pages path relative to anything other than WR or FS"); return false; } } else { return false; } }
/** * function moveTo * Try to move a file (and create all parents if needed) * @param string $from, the full filename of the file to move * @param string $to, the full filename of the file moved * @return boolean true on success, false on failure * @static */ function moveTo($from, $to) { $from = realpath($from); if (@is_file($from)) { //check if parent directory exist else create it if (!@is_dir(dirname($to))) { CMS_file::makeDir(dirname($to)); } //move the file (ie : rename it) $return = @rename($from, $to); if ($return) { CMS_file::chmodFile(FILES_CHMOD, $to); } return $return; } return false; }