From b8c81fab0ea13fe7dc1706ad8782d3d683455470 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 20 Dec 2017 13:19:16 +0100 Subject: [PATCH] use try/finally to make sure working-path restore on Exceptions (#1463) * use try/finally to make sure working-path restore on Exceptions * Update functions.php * Update CHANGELOG.md * Update CHANGELOG.md * fixed CS --- CHANGELOG.md | 3 +++ src/functions.php | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa40bbd4..6b6e4227 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ ## master [v6.0.5...master](https://github.com/deployphp/deployer/compare/v6.0.5...master) +### Fixed +- fix within() to also restore the working-path when the given callback throws a Exception [#1463] ## v6.0.5 [v6.0.4...v6.0.5](https://github.com/deployphp/deployer/compare/v6.0.4...v6.0.5) @@ -337,6 +339,7 @@ - Fixed remove of shared dir on first deploy +[#1463]: https://github.com/deployphp/deployer/pull/1463 [#1455]: https://github.com/deployphp/deployer/pull/1455 [#1452]: https://github.com/deployphp/deployer/pull/1452 [#1426]: https://github.com/deployphp/deployer/pull/1426 diff --git a/src/functions.php b/src/functions.php index 448834dc..cc84b18c 100644 --- a/src/functions.php +++ b/src/functions.php @@ -258,9 +258,12 @@ function cd($path) function within($path, $callback) { $lastWorkingPath = get('working_path', ''); - set('working_path', parse($path)); - $callback(); - set('working_path', $lastWorkingPath); + try { + set('working_path', parse($path)); + $callback(); + } finally { + set('working_path', $lastWorkingPath); + } } /**