From: Christian Weiske Date: Tue, 14 Jul 2015 05:58:32 +0000 (+0200) Subject: fix crash when renaming file X-Git-Tag: v0.6.1~2 X-Git-Url: https://git.cweiske.de/phorkie.git/commitdiff_plain/808a3a5857c77ef99605fdfdde9b31b5c02e22c6?ds=sidebyside fix crash when renaming file This bug was introduced by the modified hash handling for caching in 2cd81a7 --- diff --git a/src/phorkie/Repository.php b/src/phorkie/Repository.php index 62a6e38..013f017 100644 --- a/src/phorkie/Repository.php +++ b/src/phorkie/Repository.php @@ -113,6 +113,12 @@ class Repository $this->hash = $output; } + public function reloadHash() + { + $this->hash = null; + return $this->loadHash(); + } + /** * Populates $this->message * diff --git a/src/phorkie/Repository/Post.php b/src/phorkie/Repository/Post.php index 511a83c..7a373aa 100644 --- a/src/phorkie/Repository/Post.php +++ b/src/phorkie/Repository/Post.php @@ -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; }