From e7f0018b054bc74ffc18dd72d4bb4693953d3676 Mon Sep 17 00:00:00 2001 From: Anton Medvedev Date: Fri, 25 Nov 2016 20:39:21 +0700 Subject: [PATCH] Fix bugs with copy shared files #896 #894 --- recipe/deploy/shared.php | 19 +++++++++++-------- src/functions.php | 13 +++++++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/recipe/deploy/shared.php b/recipe/deploy/shared.php index 4f88abbe..0bec4bc8 100644 --- a/recipe/deploy/shared.php +++ b/recipe/deploy/shared.php @@ -12,19 +12,22 @@ task('deploy:shared', function () { $sharedPath = "{{deploy_path}}/shared"; foreach (get('shared_dirs') as $dir) { - $parentDir = dirname($dir); + // Check if shared dir does not exists. + if (!test("[ -d $sharedPath/$dir ]")) { + // Create shared dir if it does not exist. + run("mkdir -p $sharedPath/$dir"); - // Create shared dir if it does not exist. - run("mkdir -p $sharedPath/$dir"); - - // Copy shared dir files if they does not exist. - run("if [ -d $(echo {{release_path}}/$dir) ]; then cp -rn {{release_path}}/$dir $sharedPath/$parentDir; fi"); + // If release contains shared dir, copy that dir from release to shared. + if (test("[ -d $(echo {{release_path}}/$dir) ]")) { + run("cp -rv {{release_path}}/$dir $sharedPath/" . dirname($dir)); + } + } // Remove from source. - run("if [ -d $(echo {{release_path}}/$dir) ]; then rm -rf {{release_path}}/$dir; fi"); + run("rm -rf {{release_path}}/$dir"); // Create path to shared dir in release dir if it does not exist. - // (symlink will not create the path and will fail otherwise) + // Symlink will not create the path and will fail otherwise. run("mkdir -p `dirname {{release_path}}/$dir`"); // Symlink shared dir to release dir diff --git a/src/functions.php b/src/functions.php index d4362bb7..9fdb3ee6 100644 --- a/src/functions.php +++ b/src/functions.php @@ -363,6 +363,19 @@ function runLocally($command, $timeout = 60) return new Result($output); } +/** + * Run test command. + * Example: + * + * test('[ -d {{release_path}} ]') + * + * @param string $command + * @return bool + */ +function test($command) +{ + return run("if $command; then echo 'true'; fi")->toBool(); +} /** * Upload file or directory to current server.