-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathLocalBuild.php
More file actions
107 lines (89 loc) · 2.96 KB
/
Copy pathLocalBuild.php
File metadata and controls
107 lines (89 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
namespace PHPCensor\Model\Build;
use Exception;
use PHPCensor\Builder;
use PHPCensor\Model\Build;
/**
* Local Build Model
*
* @package PHP Censor
* @subpackage Application
*
* @author Dan Cryer <dan@block8.co.uk>
* @author Dmitry Khomutov <poisoncorpsee@gmail.com>
*/
class LocalBuild extends TypedBuild
{
/**
* Create a working copy by cloning, copying, or similar.
*
* @param string $buildPath
*
* @return bool
*
* @throws Exception
*/
public function createWorkingCopy(Builder $builder, $buildPath)
{
$reference = $this->getProject()->getReference();
$reference = \substr($reference, -1) === '/' ? \substr($reference, 0, -1) : $reference;
$buildPath = \substr($buildPath, 0, -1);
// If there's a /config file in the reference directory, it is probably a bare repository
// which we'll extract into our build path directly.
if (\is_file($reference . '/config') &&
true === $this->handleBareRepository($builder, $reference, $buildPath)) {
return $this->handleConfig($builder, $buildPath);
}
$configHandled = $this->handleConfig($builder, $reference);
if ($configHandled === false) {
return false;
}
$buildSettings = $builder->getConfig('build_settings');
if (isset($buildSettings['prefer_symlink']) && $buildSettings['prefer_symlink'] === true) {
return $this->handleSymlink($builder, $reference, $buildPath);
} else {
$cmd = 'mkdir -p "%s" && cp -Rf %s/* "%s/"';
$builder->executeCommand($cmd, $buildPath, $reference, $buildPath);
}
return true;
}
/**
* Check if this is a "bare" git repository, and if so, unarchive it.
*
* @param string $reference
* @param string $buildPath
*
* @return bool
*/
protected function handleBareRepository(Builder $builder, $reference, $buildPath)
{
$gitConfig = \parse_ini_file($reference.'/config', true);
// If it is indeed a bare repository, then extract it into our build path:
if ($gitConfig['core']['bare']) {
$cmd = 'mkdir %2$s; git --git-dir="%1$s" archive %3$s | tar -x -C "%2$s"';
$builder->executeCommand($cmd, $reference, $buildPath, $this->getBranch());
return true;
}
return false;
}
/**
* Create a symlink if required.
*
* @param string $reference
* @param string $buildPath
*
* @return bool
*/
protected function handleSymlink(Builder $builder, $reference, $buildPath)
{
if (\is_link($buildPath) && \is_file($buildPath)) {
\unlink($buildPath);
}
$builder->log(\sprintf('Symlinking: %s to %s', $reference, $buildPath));
if (!\symlink($reference, $buildPath)) {
$builder->logFailure('Failed to symlink.');
return false;
}
return true;
}
}