use Phar;
use PharFileInfo;
-use RecursiveIteratorIterator;
use SplFileInfo;
+use pharext\Exception;
class Updater implements Command
{
}
foreach ($this->args[0] as $file) {
- if (file_exists($file)) {
- $this->updatePackage(new SplFileInfo($file));
+ $info = new SplFileInfo($file);
+
+ while ($info->isLink()) {
+ $info = new SplFileInfo($info->getLinkTarget());
+ }
+
+ if ($info->isFile()) {
+ $this->updatePackage($info);
} else {
$this->error("File '%s' does not exist\n", $file);
exit(self::EARGS);
$phar = new Phar($temp, Phar::CURRENT_AS_SELF);
$phar->startBuffering();
+ $meta = $phar->getMetadata();
+
// replace current pharext files
$core = (new Task\BundleGenerator)->run($this->verbosity());
$phar->buildFromIterator($core);
$phar->setMetadata([
"version" => Metadata::version(),
"header" => Metadata::header(),
- ] + $phar->getMetadata());
+ ] + (array) $phar->getMetadata());
+
+ $this->info("Updated pharext version from '%s' to '%s'\n",
+ isset($meta["version"]) ? $meta["version"] : "(unknown)",
+ $phar->getMetadata()["version"]);
}
private function updatePackage(SplFileInfo $file, Phar $phar = null) {
if (!copy($file->getPathname(), $temp)) {
throw new Exception;
}
+ if (!chmod($temp, $file->getPerms())) {
+ throw new Exception;
+ }
$this->replacePharext($temp);