update pharext metadata
[pharext/pharext] / src / pharext / Updater.php
index 7da989db9db0c5147d83e3d0780560f881b1de21..f7972a1405c3dd32e8b0a945422ffdecfd8b2f0d 100644 (file)
@@ -4,8 +4,8 @@ namespace pharext;
 
 use Phar;
 use PharFileInfo;
-use RecursiveIteratorIterator;
 use SplFileInfo;
+use pharext\Exception;
 
 class Updater implements Command
 {
@@ -82,8 +82,14 @@ 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);
@@ -95,6 +101,8 @@ class Updater implements Command
                $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);
@@ -114,6 +122,10 @@ class Updater implements Command
                        "version" => Metadata::version(),
                        "header" => Metadata::header(),
                ] + $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) {
@@ -124,6 +136,9 @@ class Updater implements Command
                if (!copy($file->getPathname(), $temp)) {
                        throw new Exception;
                }
+               if (!chmod($temp, $file->getPerms())) {
+                       throw new Exception;
+               }
                
                $this->replacePharext($temp);