/** * @param string $archiveFile * @param string $targetDir * @param OutputInterface $output */ public function extractArchive($archiveFile, $targetDir, OutputInterface $output) { if ($output->getVerbosity() < OutputInterface::VERBOSITY_VERY_VERBOSE) { $output->write(sprintf('Extracting <comment>%s</comment> to <comment>%s</comment>...', $archiveFile, $targetDir)); } $processHelper = $this->getHelperSet()->get('process'); /* @var $processHelper ProcessHelper */ $tempDir = $this->getTempDir($archiveFile); $extractProcess = Util::getExtractProcess($archiveFile); if (!$extractProcess) { throw new \RuntimeException(sprintf('Archive type of %s cannot be handled', $archiveFile)); } $extractProcess->setWorkingDirectory($tempDir); $processHelper->mustRun($output, $extractProcess); $commonPrefix = PathUtil::commonPrefix(Finder::create()->ignoreDotFiles(false)->ignoreVCS(false)->directories()->in($tempDir)); FsUtil::rename($commonPrefix, $targetDir); foreach (Finder::create()->ignoreDotFiles(false)->ignoreVCS(false)->directories()->in($tempDir) as $files) { FsUtil::rmdir($files); } if ($output->getVerbosity() < OutputInterface::VERBOSITY_VERY_VERBOSE) { $output->writeln('<info>OK</info>'); } }
public function write() { if (file_exists($this->getConfigFile()->getPathname())) { $backupDir = $this->getClicDirectory() . '/settings-backup/' . sha1($this->getConfigFile()->getPathname()); if (!is_dir($backupDir)) { FsUtil::mkdir($backupDir, true); } $backupFile = $backupDir . '/' . time(); FsUtil::rename($this->getConfigFile()->getPathname(), $backupFile); if (file_exists($backupDir . '/prev')) { FsUtil::unlink($backupDir . '/prev'); } FsUtil::symlink($backupFile, $backupDir . '/prev'); } parent::write(); }