Skip to content

Commit e7f0018

Browse files
committed
Fix bugs with copy shared files #896 #894
1 parent 54a29c8 commit e7f0018

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

recipe/deploy/shared.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,22 @@
1212
$sharedPath = "{{deploy_path}}/shared";
1313

1414
foreach (get('shared_dirs') as $dir) {
15-
$parentDir = dirname($dir);
15+
// Check if shared dir does not exists.
16+
if (!test("[ -d $sharedPath/$dir ]")) {
17+
// Create shared dir if it does not exist.
18+
run("mkdir -p $sharedPath/$dir");
1619

17-
// Create shared dir if it does not exist.
18-
run("mkdir -p $sharedPath/$dir");
19-
20-
// Copy shared dir files if they does not exist.
21-
run("if [ -d $(echo {{release_path}}/$dir) ]; then cp -rn {{release_path}}/$dir $sharedPath/$parentDir; fi");
20+
// If release contains shared dir, copy that dir from release to shared.
21+
if (test("[ -d $(echo {{release_path}}/$dir) ]")) {
22+
run("cp -rv {{release_path}}/$dir $sharedPath/" . dirname($dir));
23+
}
24+
}
2225

2326
// Remove from source.
24-
run("if [ -d $(echo {{release_path}}/$dir) ]; then rm -rf {{release_path}}/$dir; fi");
27+
run("rm -rf {{release_path}}/$dir");
2528

2629
// Create path to shared dir in release dir if it does not exist.
27-
// (symlink will not create the path and will fail otherwise)
30+
// Symlink will not create the path and will fail otherwise.
2831
run("mkdir -p `dirname {{release_path}}/$dir`");
2932

3033
// Symlink shared dir to release dir

src/functions.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,19 @@ function runLocally($command, $timeout = 60)
363363
return new Result($output);
364364
}
365365

366+
/**
367+
* Run test command.
368+
* Example:
369+
*
370+
* test('[ -d {{release_path}} ]')
371+
*
372+
* @param string $command
373+
* @return bool
374+
*/
375+
function test($command)
376+
{
377+
return run("if $command; then echo 'true'; fi")->toBool();
378+
}
366379

367380
/**
368381
* Upload file or directory to current server.

0 commit comments

Comments
 (0)