Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Commit 8bc0806

Browse files
committed
Resolve #69
1 parent ab8fcf2 commit 8bc0806

File tree

4 files changed

+45
-8
lines changed

4 files changed

+45
-8
lines changed

src/AbstractRepositoryType.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace Codedge\Updater;
66

77
use Codedge\Updater\Events\HasWrongPermissions;
8-
use File;
8+
use Illuminate\Support\Facades\File;
99
use GuzzleHttp\Client;
1010
use Symfony\Component\Finder\Finder;
1111

@@ -217,4 +217,17 @@ public function hasAccessToken(): bool
217217
{
218218
return ! empty($this->accessToken);
219219
}
220+
221+
/**
222+
* Check if files in one array (i. e. directory) are also exist in a second one.
223+
*
224+
* @param array $directory
225+
* @param array $excludedDirs
226+
*
227+
* @return bool
228+
*/
229+
public function isDirectoryExcluded(array $directory, array $excludedDirs): bool
230+
{
231+
return count(array_intersect($directory, $excludedDirs)) ? true : false;
232+
}
220233
}

src/SourceRepositoryTypes/GithubRepositoryType.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Codedge\Updater\Events\UpdateAvailable;
1010
use Codedge\Updater\Events\UpdateFailed;
1111
use Codedge\Updater\Events\UpdateSucceeded;
12-
use File;
12+
use Illuminate\Support\Facades\File;
1313
use GuzzleHttp\Client;
1414
use Storage;
1515
use Symfony\Component\Finder\Finder;
@@ -138,15 +138,16 @@ public function update($version = '') : bool
138138
// Move all directories first
139139
collect((new Finder())->in($sourcePath)->exclude($this->config['exclude_folders'])->directories()->sort(function ($a, $b) {
140140
return strlen($b->getRealpath()) - strlen($a->getRealpath());
141-
}))->each(function ($directory) { /** @var \SplFileInfo $directory */
142-
if (count(array_intersect(File::directories(
143-
$directory->getRealPath()), $this->config['exclude_folders']) == 0)
141+
}))->each(function (/** @var \SplFileInfo $directory */ $directory) {
142+
if (!$this->isDirectoryExcluded(
143+
File::directories($directory->getRealPath()), $this->config['exclude_folders'])
144144
) {
145145
File::copyDirectory(
146146
$directory->getRealPath(),
147147
base_path($directory->getRelativePath()).'/'.$directory->getBasename()
148148
);
149149
}
150+
150151
File::deleteDirectory($directory->getRealPath());
151152
});
152153

src/SourceRepositoryTypes/HttpRepositoryType.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Codedge\Updater\Events\UpdateAvailable;
1010
use Codedge\Updater\Events\UpdateFailed;
1111
use Codedge\Updater\Events\UpdateSucceeded;
12-
use File;
12+
use Illuminate\Support\Facades\File;
1313
use GuzzleHttp\Client;
1414
use Illuminate\Database\Eloquent\Collection;
1515
use Psr\Http\Message\ResponseInterface;
@@ -153,13 +153,15 @@ public function update($version = '') : bool
153153
collect((new Finder())->in($sourcePath)->exclude($this->config['exclude_folders'])->directories()->sort(function ($a, $b) {
154154
return strlen($b->getRealpath()) - strlen($a->getRealpath());
155155
}))->each(function ($directory) { /** @var \SplFileInfo $directory */
156-
if (count(array_intersect(File::directories(
157-
$directory->getRealPath()), $this->config['exclude_folders'])) == 0) {
156+
if (!$this->isDirectoryExcluded(
157+
File::directories($directory->getRealPath()), $this->config['exclude_folders'])
158+
) {
158159
File::copyDirectory(
159160
$directory->getRealPath(),
160161
base_path($directory->getRelativePath()).'/'.$directory->getBasename()
161162
);
162163
}
164+
163165
File::deleteDirectory($directory->getRealPath());
164166
});
165167

tests/AbstractRepositoryTypeTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Codedge\Updater\Tests;
44

5+
use Codedge\Updater\AbstractRepositoryType;
6+
57
class AbstractRepositoryTypeTest extends TestCase
68
{
79
/**
@@ -18,6 +20,25 @@ public function testCreateReleaseFolder($storagePath, $releaseName)
1820
$this->assertFileNotExists($dir, 'Release folder ['.$dir.'] does not exist.');
1921
}
2022

23+
public function testFilesAllExcluded()
24+
{
25+
/** @var AbstractRepositoryType $mock */
26+
$mock = $this->getMockBuilder(AbstractRepositoryType::class)->getMock();
27+
$mock->method('isDirectoryExcluded')->willReturn(true);
28+
$this->assertTrue($mock->isDirectoryExcluded(['a', 'b'], ['a']));
29+
$this->assertTrue($mock->isDirectoryExcluded(['a', 'b'], ['a', 'b']));
30+
$this->assertTrue($mock->isDirectoryExcluded(['a', 'b'], ['a', 'b', 'c']));
31+
}
32+
33+
public function testFilesNotAllExcluded()
34+
{
35+
/** @var AbstractRepositoryType $mock */
36+
$mock = $this->getMockBuilder(AbstractRepositoryType::class)->getMock();
37+
$mock->method('isDirectoryExcluded')->willReturn(false);
38+
$this->assertFalse($mock->isDirectoryExcluded(['a', 'b', 'c'], ['c']));
39+
$this->assertFalse($mock->isDirectoryExcluded(['a', 'b', 'c'], ['a', 'c']));
40+
}
41+
2142
public function pathProvider()
2243
{
2344
return [

0 commit comments

Comments
 (0)