mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-07-17 14:25:21 +00:00
fix(updater): manifest-based stale-file cleanup + cache clearing for v2→v3 (#659)
The v2 self-updater only overlays new files (copyFiles) and never removes files a release deleted; the one removal path (deleted_files) is not even sent by the web UI. A major upgrade (v2 → v3) removes thousands of files, so overlay-only leaves a broken hybrid, and stale bootstrap/cache config + package-discovery survive and break the new boot. Backport v3's manifest allow-list approach into this final v2 release: - Updater::cleanStaleFiles(?string $basePath): delete every file under the install not listed in the release's manifest.json, except the configured update_protected_paths. No manifest present → safe no-op (v2→v2 updates). - Updater::clearCompiledCaches(): wipe bootstrap/cache/*.php and compiled views so the freshly copied release re-reads config and re-runs package discovery. Called at the end of copyFiles() — the last point that runs as the currently-installed code before the new release boots, and necessary because bootstrap/cache is itself a protected path. - DeleteFilesController + UpdateCommand: when manifest.json is present, run cleanStaleFiles(); otherwise fall back to the legacy deleted_files list. No route or frontend change — both already call the delete step between copy and migrate. - config/invoiceshelf.php: add update_protected_paths (.env, storage, vendor, node_modules, Modules, public/storage, .git, bootstrap/cache, manifest.json). The v3 release zip already ships manifest.json (built by its make dist), so a v2 instance running this updater cleans itself up correctly on upgrade. Tested: tests/Unit/UpdaterTest.php covers stale removal, protected-path and manifest preservation, empty-dir pruning, no-manifest no-op, and invalid manifest. Full suite green.
This commit is contained in:
committed by
GitHub
parent
c9d623a0dd
commit
c1cadb7ee0
@@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
|
||||
use App\Space\Updater;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
class DeleteFilesController extends Controller
|
||||
{
|
||||
@@ -23,12 +24,17 @@ class DeleteFilesController extends Controller
|
||||
], 401);
|
||||
}
|
||||
|
||||
if (isset($request->deleted_files) && ! empty($request->deleted_files)) {
|
||||
// Backward compatibility: use the explicit deleted_files list only when the
|
||||
// release ships no manifest.json (same-line v2 updates). When a manifest is
|
||||
// present (e.g. the v3 release), clean every stale file not in the manifest.
|
||||
if (! File::exists(base_path('manifest.json'))
|
||||
&& isset($request->deleted_files)
|
||||
&& ! empty($request->deleted_files)) {
|
||||
Updater::deleteFiles($request->deleted_files);
|
||||
|
||||
return response()->json(['success' => true, 'cleaned' => 0]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
]);
|
||||
return response()->json(Updater::cleanStaleFiles());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user