Skip to content

Commit

Permalink
Merge pull request #8 from TheDragonCode/1.x
Browse files Browse the repository at this point in the history
Fixed bug deleting files without extension
  • Loading branch information
andrey-helldar authored Dec 12, 2024
2 parents 023c9f9 + 3d6f2a8 commit 5cec732
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/Service/Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace DragonCode\LaravelDataDumper\Service;

use DragonCode\Support\Facades\Filesystem\File;
use DragonCode\Support\Facades\Helpers\Str;

class Files
{
Expand All @@ -14,6 +15,10 @@ public static function delete(string $path, string $filename): void
return;
}

if (! file_exists($dir . '/' . $filename)) {
$filename = static::findFile($dir, $filename);
}

File::ensureDelete($dir . '/' . $filename);
}

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

return realpath(base_path($path));
}

protected static function findFile(string $path, string $filename): string
{
return File::names(
$path,
fn (string $name) => Str::contains(
str_replace('\\', '/', $name),
str_replace('\\', '/', $filename)
),
recursive: true
)[0];
}
}
2 changes: 1 addition & 1 deletion tests/Fixtures/migrations/2024_12_12_210949_qwerty2.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
protected function fillTable(): void
{
circleProcess(fn (int $i) => $this->table()->insert([
$this->column() => sprintf('sub/qwerty2File%s.stub', $i),
$this->column() => sprintf('sub/qwerty2File%s', $i),
]));
}
};

0 comments on commit 5cec732

Please sign in to comment.