Skip to content

Commit

Permalink
Empty directories are now being backed up (#1008)
Browse files Browse the repository at this point in the history
* Empty directories are now being backed up

* Updated tests and style
  • Loading branch information
theoxygen authored and freekmurze committed Dec 12, 2019
1 parent 4901940 commit 2ac1388
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Tasks/Backup/BackupJob.php
Expand Up @@ -202,13 +202,13 @@ protected function directoriesUsedByBackupJob(): array

protected function createZipContainingEveryFileInManifest(Manifest $manifest)
{
consoleOutput()->info("Zipping {$manifest->count()} files...");
consoleOutput()->info("Zipping {$manifest->count()} files and directories...");

$pathToZip = $this->temporaryDirectory->path(config('backup.backup.destination.filename_prefix').$this->filename);

$zip = Zip::createForManifest($manifest, $pathToZip);

consoleOutput()->info("Created zip containing {$zip->count()} files. Size is {$zip->humanReadableSize()}");
consoleOutput()->info("Created zip containing {$zip->count()} files and directories. Size is {$zip->humanReadableSize()}");

$this->sendNotification(new BackupZipWasCreated($pathToZip));

Expand Down
3 changes: 1 addition & 2 deletions src/Tasks/Backup/FileSelection.php
Expand Up @@ -69,8 +69,7 @@ public function selectedFiles()

$finder = (new Finder())
->ignoreDotFiles(false)
->ignoreVCS(false)
->files();
->ignoreVCS(false);

if ($this->shouldFollowLinks) {
$finder->followLinks();
Expand Down
6 changes: 5 additions & 1 deletion src/Tasks/Backup/Zip.php
Expand Up @@ -100,7 +100,11 @@ public function add($files, string $nameInZip = null): self
}

foreach ($files as $file) {
if (file_exists($file)) {
if (is_dir($file)) {
$this->zipFile->addEmptyDir($file);
}

if (is_file($file)) {
$this->zipFile->addFile($file, ltrim($nameInZip, DIRECTORY_SEPARATOR)).PHP_EOL;
}
$this->fileCount++;
Expand Down
9 changes: 9 additions & 0 deletions tests/FileSelectionTest.php
Expand Up @@ -29,10 +29,14 @@ public function it_can_select_all_the_files_in_a_directory_and_subdirectories()
$testFiles = $this->getTestFiles([
'.dotfile',
'1Mb.file',
'directory1',
'directory1/directory1',
'directory1/directory1/file1.txt',
'directory1/directory1/file2.txt',
'directory1/file1.txt',
'directory1/file2.txt',
'directory2',
'directory2/directory1',
'directory2/directory1/file1.txt',
'file1.txt',
'file2.txt',
Expand All @@ -52,6 +56,8 @@ public function it_can_exclude_files_from_a_given_subdirectory()
$testFiles = $this->getTestFiles([
'.dotfile',
'1Mb.file',
'directory2',
'directory2/directory1',
'directory2/directory1/file1.txt',
'file1.txt',
'file2.txt',
Expand All @@ -71,8 +77,10 @@ public function it_can_exclude_files_with_wildcards_from_a_given_subdirectory()
$testFiles = $this->getTestFiles([
'.dotfile',
'1Mb.file',
'directory1',
'directory1/file1.txt',
'directory1/file2.txt',
'directory2',
'file1.txt',
'file2.txt',
'file3.txt',
Expand Down Expand Up @@ -113,6 +121,7 @@ public function it_can_exclude_files_from_multiple_directories()
$testFiles = $this->getTestFiles([
'.dotfile',
'1Mb.file',
'directory1',
'directory1/file1.txt',
'directory1/file2.txt',
'file1.txt',
Expand Down

0 comments on commit 2ac1388

Please sign in to comment.