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

Make RemoveStorageSymlinksAction able to delete broken symlinks #1323

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

lukinovec
Copy link
Contributor

@lukinovec lukinovec commented Feb 27, 2025

I noticed that RemoveStorageSymlinksAction only deletes symlinks if they're not broken (= if they're pointnig to an existing directory). To verify this:

config([
    'tenancy.bootstrappers' => [
        FilesystemTenancyBootstrapper::class,
    ],
    'tenancy.filesystem.suffix_base' => 'tenant-',
]);

$tenant = Tenant::create();
$tenantKey = $tenant->getTenantKey();

tenancy()->initialize($tenant);

(new CreateStorageSymlinksAction)($tenant);

file_exists($publicPath); // true

// Make the symlink invalid by deleting the tenant storage directory
File::deleteDirectory(storage_path());

(new RemoveStorageSymlinksAction)($tenant);

$publicPath = public_path("public-$tenantKey");

file_exists($publicPath); // false
is_link($publicPath); // true, the broken symlink still exists

This PR changes the symlinkExists() function in DealsWithTenantSymlinks to return is_link($link) instead of file_exists($link) && is_link($link) (check if the link exists instead of checking if it exists ands is valid). This change makes RemoveStorageSymlinksAction able to delete broken symlinks. Added a regression test for that ('removing the tenant symlinks works even if the symlinks are invalid' in ActionTest).

This PR also moves the commented RemoveStorageSymlinks job in the TenancyServiceProvider stub from the TenantDeleted event's job pipeline to DeletingTenant -- before the commented RemoveTenantStorage listener. This is a bit better default, since deleting the symlinks before deleting the tenant storage makes more sense (though with the symlinkExists() change, the order shouldn't really matter).

Copy link

codecov bot commented Feb 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.74%. Comparing base (8960a83) to head (5f10c05).

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #1323   +/-   ##
=========================================
  Coverage     84.74%   84.74%           
+ Complexity     1071     1070    -1     
=========================================
  Files           177      177           
  Lines          3101     3101           
=========================================
  Hits           2628     2628           
  Misses          473      473           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lukinovec lukinovec marked this pull request as ready for review February 27, 2025 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant