/** * * @param string absolute path to config file */ function __construct(Dir $path) { if (!$path->exists()) { throw new RepositoryListException('Given path(' . $path . ') not exists.'); } $this->path = $path; $this->list = $path->getFile('list.txt'); $this->createContext(); }
/** * Распаковывает $archive в указаную папку * */ static function unpackFile(File $archive, Dir $target, $filename) { if (!$archive->canRead()) { throw new PackerException('File archive ' . $archive . ' not readable.'); } if (!$target->canWrite()) { throw new PackerException('Target folder ' . $target . ' not writable.'); } $cmd = str_replace(array('{ARCHIVE}', '{DIR}', '{FILE}'), array($archive, $target, $filename), self::$config['unpack_file_template']); exec($cmd, $out, $res); if ($res) { $out[] = PHP_EOL . 'Exit code: ' . $res . PHP_EOL . 'Command: ' . $cmd . PHP_EOL; $f = Dir::get(Config::getInstance()->root_dir, true)->getDir(self::$config['logDir'])->getFile('unpackFile_' . basename($archive) . '.log'); file_put_contents($f, implode(PHP_EOL, $out)); throw new PackerException('Error while unpacking. Return code: ' . $res . '. Log file stored at ' . $f); } return $target->getFile($filename); }
/** * Откат задачи * * @param Dir $dir директория в которой были сохранены откаты */ static function undeploy($dir) { $f = $dir->getFile('message'); $f->exists() ? io::out(file_get_contents($f)) : null; }