refactor: modify AppServiceProvider to silently handle symlink creation failures and improve user guidance for storage link management
This commit is contained in:
@@ -181,8 +181,7 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
@unlink($publicStoragePath);
|
@unlink($publicStoragePath);
|
||||||
} elseif (is_dir($publicStoragePath)) {
|
} elseif (is_dir($publicStoragePath)) {
|
||||||
// If it's a directory, we can't safely remove it automatically
|
// If it's a directory, we can't safely remove it automatically
|
||||||
// Log a warning instead
|
// Skip silently - the user is aware of this situation
|
||||||
\Log::warning('Storage symlink cannot be created: public/storage exists as a directory. Please remove it manually and run: php artisan storage:link');
|
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
@unlink($publicStoragePath);
|
@unlink($publicStoragePath);
|
||||||
@@ -212,19 +211,16 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
str_replace('/', '\\', $target)
|
str_replace('/', '\\', $target)
|
||||||
);
|
);
|
||||||
@exec($command, $output, $return);
|
@exec($command, $output, $return);
|
||||||
if ($return !== 0) {
|
// Silently ignore if symlink creation fails on Windows
|
||||||
\Log::warning('Storage symlink creation failed on Windows. Please run: php artisan storage:link');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
\Log::warning('Storage symlink cannot be created on Windows. Please run: php artisan storage:link');
|
|
||||||
}
|
}
|
||||||
|
// Skip silently if exec is not available on Windows
|
||||||
} else {
|
} else {
|
||||||
// Unix/Linux - create symlink
|
// Unix/Linux - create symlink
|
||||||
symlink($target, $link);
|
symlink($target, $link);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
\Log::warning('Storage symlink creation failed: ' . $e->getMessage() . '. Please run: php artisan storage:link');
|
// Silently ignore symlink creation failures
|
||||||
}
|
}
|
||||||
} elseif (is_link($publicStoragePath)) {
|
} elseif (is_link($publicStoragePath)) {
|
||||||
// Check if symlink is broken (points to non-existent target)
|
// Check if symlink is broken (points to non-existent target)
|
||||||
|
|||||||
Reference in New Issue
Block a user