Skip to content

Commit 5cec732

Browse files
Merge pull request #8 from TheDragonCode/1.x
Fixed bug deleting files without extension
2 parents 023c9f9 + 3d6f2a8 commit 5cec732

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Diff for: src/Service/Files.php

+17
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace DragonCode\LaravelDataDumper\Service;
66

77
use DragonCode\Support\Facades\Filesystem\File;
8+
use DragonCode\Support\Facades\Helpers\Str;
89

910
class Files
1011
{
@@ -14,6 +15,10 @@ public static function delete(string $path, string $filename): void
1415
return;
1516
}
1617

18+
if (! file_exists($dir . '/' . $filename)) {
19+
$filename = static::findFile($dir, $filename);
20+
}
21+
1722
File::ensureDelete($dir . '/' . $filename);
1823
}
1924

@@ -25,4 +30,16 @@ protected static function directory(string $path): false|string
2530

2631
return realpath(base_path($path));
2732
}
33+
34+
protected static function findFile(string $path, string $filename): string
35+
{
36+
return File::names(
37+
$path,
38+
fn (string $name) => Str::contains(
39+
str_replace('\\', '/', $name),
40+
str_replace('\\', '/', $filename)
41+
),
42+
recursive: true
43+
)[0];
44+
}
2845
}

Diff for: tests/Fixtures/migrations/2024_12_12_210949_qwerty2.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
protected function fillTable(): void
1111
{
1212
circleProcess(fn (int $i) => $this->table()->insert([
13-
$this->column() => sprintf('sub/qwerty2File%s.stub', $i),
13+
$this->column() => sprintf('sub/qwerty2File%s', $i),
1414
]));
1515
}
1616
};

0 commit comments

Comments
 (0)