Skip to content

Commit c6b8da2

Browse files
Merge pull request #242 from moebrowne
Inherit Permissions When Creating Directories
2 parents 8d7d045 + 9cad7fb commit c6b8da2

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/Backup/Source/Mysqldump.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,28 @@ protected function setupSourceData(array $conf)
271271
public function backup(Target $target, Result $result) : Status
272272
{
273273
// create the writable dump directory for tables files
274-
if ($this->filePerTable && !is_dir($this->getDumpTarget($target))) {
274+
$dumpTarget = $this->getDumpTarget($target);
275+
if ($this->filePerTable && !is_dir($dumpTarget)) {
276+
$fileMode = 0777;
277+
278+
if (PHP_OS !== 'WINNT') {
279+
// get the permissions of the first directory that exists
280+
$pathSegments = explode(DIRECTORY_SEPARATOR, $dumpTarget);
281+
282+
do {
283+
$filename = implode(DIRECTORY_SEPARATOR, $pathSegments);
284+
285+
if (is_dir($filename) === false) {
286+
continue;
287+
}
288+
289+
$fileMode = substr(fileperms($filename), -4);
290+
break;
291+
} while (array_pop($pathSegments) !== null);
292+
}
293+
275294
$old = umask(0);
276-
mkdir($this->getDumpTarget($target), 0777, true);
295+
mkdir($dumpTarget, $fileMode, true);
277296
umask($old);
278297
}
279298

0 commit comments

Comments
 (0)