/** * */ static function pack(Dir $source, File $target) { if (!$source->exists()) { throw new PackerException('Source folder ' . $source . ' not readable.'); } if (!$target->getParent()->canWrite()) { throw new PackerException('Target file ' . $target . ' not writable.'); } $cmd = str_replace(array('{FILE}', '{TARGET}'), array($source, $target), self::$config['pack_template']); exec($cmd, $out, $res); if ($res) { $out[] = PHP_EOL . 'Exit code: ' . $res . PHP_EOL; $f = Dir::get(Config::getInstance()->root_dir, true)->getDir(self::$config['logDir'])->getFile('pack_' . basename($source) . '.log'); file_put_contents($f, implode(PHP_EOL, $out)); throw new PackerException('Error while unpacking. Return code: ' . $res . '. Log file stored at ' . $f); } }