fix crash when renaming file
authorChristian Weiske <cweiske@cweiske.de>
Tue, 14 Jul 2015 05:58:32 +0000 (07:58 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Tue, 14 Jul 2015 05:58:32 +0000 (07:58 +0200)
This bug was introduced by the modified hash handling for caching in 2cd81a7

src/phorkie/Repository.php
src/phorkie/Repository/Post.php

index 62a6e38..013f017 100644 (file)
@@ -113,6 +113,12 @@ class Repository
         $this->hash = $output;
     }
 
+    public function reloadHash()
+    {
+        $this->hash = null;
+        return $this->loadHash();
+    }
+
     /**
      * Populates $this->message
      *
index 511a83c..7a373aa 100644 (file)
@@ -58,8 +58,8 @@ class Repository_Post
                 continue;
             }
 
-            $orignalName = Tools::sanitizeFilename($arFile['original_name']);
-            $name        = Tools::sanitizeFilename($arFile['name']);
+            $originalName = Tools::sanitizeFilename($arFile['original_name']);
+            $name         = Tools::sanitizeFilename($arFile['name']);
 
             if ($arFile['type'] == '_auto_') {
                 //FIXME: upload
@@ -79,7 +79,7 @@ class Repository_Post
 
             $bNew = false;
             $bDelete = false;
-            if (!isset($orignalName) || $orignalName == '') {
+            if (!isset($originalName) || $originalName == '') {
                 //new file
                 $bNew = true;
                 if (strpos($name, '.') === false) {
@@ -87,27 +87,30 @@ class Repository_Post
                     $name .= '.' . $arFile['type'];
                 }
                 $this->newfileName = $name;
-            } else if (!$this->repo->hasFile($orignalName)) {
+            } else if (!$this->repo->hasFile($originalName)) {
                 //unknown file
                 //FIXME: Show error message
                 continue;
             } else if (isset($arFile['delete']) && $arFile['delete'] == 1) {
                 $bDelete = true;
-            } else if ($orignalName != $name) {
+            } else if ($originalName != $name) {
                 if (strpos($name, '/') === false) {
                     //ignore names with a slash in it, would be new directory
                     //FIXME: what to do with overwrites?
                     $vc->getCommand('mv')
-                        ->addArgument($orignalName)
+                        ->addArgument($originalName)
                         ->addArgument($name)
                         ->execute();
                     $bCommit = true;
                 } else {
-                    $name = $orignalName;
+                    $name = $originalName;
                 }
             }
 
             $file = $this->repo->getFileByName($name, false);
+            if ($originalName !== '') {
+                $originalFile = $this->repo->getFileByName($originalName, false);
+            }
             if ($bDelete) {
                 $command = $vc->getCommand('rm')
                     ->addArgument($file->getFilename())
@@ -123,8 +126,8 @@ class Repository_Post
                     ->execute();
                 $bCommit = true;
             } else if ($bNew
-                || (isset($arFile['content'])
-                    && $file->getContent() != $arFile['content']
+                || (isset($arFile['content']) && isset($originalFile)
+                    && $originalFile->getContent() != $arFile['content']
                 )
             ) {
                 $dir = dirname($file->getFullPath());
@@ -166,6 +169,9 @@ class Repository_Post
             //the post-update hook should do that IMO, but does not somehow
             $vc->getCommand('update-server-info')->execute();
 
+            //we changed the hash by committing, so reload it
+            $this->repo->reloadHash();
+
             $bChanged = true;
         }