Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ghostbust dead symlinks #579

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions app/Console/Commands/Ghostbuster.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ public function handle()
if ($url == 'index.html') {
continue;
}
$c = Photo::where('url', '=', $url)->count();
if ($c == 0) {

$isDeadSymlink = is_link($path . '/' . $url) && !file_exists(readlink($path . '/' . $url));

$photos = Photo::where('url', '=', $url)->get();
if (count($photos) === 0 || $isDeadSymlink) {
$photoName = explode('.', $url);

$to_delete = [];
Expand Down Expand Up @@ -102,7 +105,7 @@ public function handle()
if ($delete > 0) {
$total++;
if ($dryrun) {
$this->line(str_pad($del, 50) . $this->col->red(' will be removed') . '.');
$this->line(str_pad($del, 50) . $this->col->red(' file will be removed') . '.');
} else {
if ($delete == 1) {
Storage::delete($del);
Expand All @@ -114,6 +117,22 @@ public function handle()
}
}
}

if ($isDeadSymlink) {
foreach ($photos as $photo) {
if ($dryrun) {
$this->line(str_pad($photo->url, 50) . $this->col->red(' photo will be removed') . '.');
} else {
// Laravel apparently doesn't thing dead symlinks 'exist', so manually remove the original here.
ildyria marked this conversation as resolved.
Show resolved Hide resolved
unlink("$path/$url");
ildyria marked this conversation as resolved.
Show resolved Hide resolved

$photo->predelete();
$photo->delete();

$this->line($this->col->red('removed photo: ') . $photo->url);
}
}
}
}
}
$this->line('');
Expand Down