Skip to content

Commit bcf6162

Browse files
Make relative path work
Path in the phpbu configuration file should always be absolute or relative to the position of the config file. To make this work for teh tar source the path option is now converted to an absolute path during setup.
1 parent 6ab0725 commit bcf6162

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/Backup/Source/Tar.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33

44
use phpbu\App\Backup\Target;
55
use phpbu\App\Cli\Executable;
6+
use phpbu\App\Configuration;
67
use phpbu\App\Exception;
78
use phpbu\App\Result;
89
use phpbu\App\Util;
10+
use Symfony\Component\Finder\Tests\Iterator\FilecontentFilterIteratorTest;
911

1012
/**
1113
* Tar source class.
@@ -111,18 +113,32 @@ class Tar extends SimulatorExecutable implements Simulator
111113
*/
112114
public function setup(array $conf = [])
113115
{
116+
$this->setupPath($conf);
114117
$this->pathToTar = Util\Arr::getValue($conf, 'pathToTar', '');
115-
$this->path = Util\Arr::getValue($conf, 'path', '');
116118
$this->excludes = Util\Str::toList(Util\Arr::getValue($conf, 'exclude', ''));
117119
$this->compressProgram = Util\Arr::getValue($conf, 'compressProgram', '');
118120
$this->throttle = Util\Arr::getValue($conf, 'throttle', '');
119121
$this->forceLocal = Util\Str::toBoolean(Util\Arr::getValue($conf, 'forceLocal', ''), false);
120122
$this->ignoreFailedRead = Util\Str::toBoolean(Util\Arr::getValue($conf, 'ignoreFailedRead', ''), false);
121123
$this->removeSourceDir = Util\Str::toBoolean(Util\Arr::getValue($conf, 'removeSourceDir', ''), false);
124+
}
122125

123-
if (empty($this->path)) {
126+
/**
127+
* Setup the path to the directory that should be compressed.
128+
*
129+
* @param array $conf
130+
* @throws \phpbu\App\Exception
131+
*/
132+
protected function setupPath(array $conf)
133+
{
134+
$path = Util\Arr::getValue($conf, 'path', '');
135+
if (empty($path)) {
124136
throw new Exception('path option is mandatory');
125137
}
138+
$this->path = Util\Path::toAbsolutePath($path, Configuration::getWorkingDirectory());
139+
if (!file_exists($this->path)) {
140+
throw new Exception('could not find directory to compress');
141+
}
126142
}
127143

128144
/**

0 commit comments

Comments
 (0)