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

[DX] Merge RectorConfig cacheDirectory() and containerCacheDirectory() to one to ease changing paths in case of non-writeable cache #4803

Closed
wants to merge 2 commits into from

Conversation

TomasVotruba
Copy link
Member

@TomasVotruba TomasVotruba commented Aug 17, 2023

The Symfony container was compiled, but Laravel one is lazy, so doesn't use any kind of dumped cache file. PHPStan handles this in its own way, so we can drop it completely.

EDIT: This option is needed for PHPStan container. Yet should be united with other cache directory option to avoid duplicated work and WTFs in rectorphp/rector#8112

Closes: rectorphp/rector#8112

@TomasVotruba TomasVotruba changed the title deprecate RectorConfig containerCacheDirectory() as no longer used by container, cleanup phpstan errors [DX] Deprecate RectorConfig containerCacheDirectory() as no longer used by container, cleanup phpstan errors Aug 17, 2023
@TomasVotruba TomasVotruba changed the title [DX] Deprecate RectorConfig containerCacheDirectory() as no longer used by container, cleanup phpstan errors [DX] Deprecate RectorConfig containerCacheDirectory() as no longer used by container Aug 17, 2023
@@ -49,7 +49,7 @@ public function __construct(

$containerFactory = new ContainerFactory(getcwd());
$this->container = $containerFactory->create(
SimpleParameterProvider::provideStringParameter(Option::CONTAINER_CACHE_DIRECTORY),
sys_get_temp_dir() . '/phpstan-container-for-rector',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

containerCacheDirectory() is used for user that doesn't have access to the sys_get_temp_dir() specific dir, and also for multi user purpose, this cause conflict, that's why it is needed, see issue:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also see original issue:

raised because of it, the default container cache dir is not writable because of no access or internal PHP bug on sys_get_temp_dir() on specific OS/platform.

Copy link
Member

@samsonasik samsonasik Aug 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see original PR that introduce:

it cover usage on shared hosting usage which user can't have access to sys_get_temp_dir() due to shared usage., that's why containerCacheDirectory() options set is needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, by define this, user will got error:

 [ERROR] The file "/var/folders/dv/m3gvpzh94t59l94qz3w2dgfr0000gn/T/phpstan-container-for-rector" does not exist.  

The create() doesn't automatically create directory target, it need to be exists before.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see ;). We can go for defaults here And alkw override by user.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean? I tried this and got error "phpstan-container-for-rector" directory not exist immediatelly, then if multi user is used, it will crash as can't be read by other user, see issue:

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added note about PHPStan container so this is known right in the configuration 👍

Copy link
Member Author

@TomasVotruba TomasVotruba Aug 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at rectorphp/rector#8112, the 2 cache directory options are pretty confusing. There should be just one method to handle both.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See what's @stefanides usage of multi user cause container crash error, using configurable container path resolve based on his experience:

rectorphp/rector#8112 (comment)

for what he experienced.

@samsonasik
Copy link
Member

@TomasVotruba please don't remove it, it will crash in the first try, as:

  1. Even normal user, user need to manually create /tmp/phpstan-container-for-rector, or it will crash:
 [ERROR] The file "/var/folders/dv/m3gvpzh94t59l94qz3w2dgfr0000gn/T/phpstan-container-for-rector" does not exist.  
  1. On shared hosting, when every user has different access, or don't have access to /tmp dir, it will cause error .

@samsonasik
Copy link
Member

samsonasik commented Aug 17, 2023

I tried locally, by this change, it doesn't work, PHPStan need to fill cache directory to : /tmp/phpstan-container-for-rector which not yet exists:

 [ERROR] The file "/var/folders/dv/m3gvpzh94t59l94qz3w2dgfr0000gn/T/phpstan-container-for-rector" does not exist.  

For user that doesn't have access to that dir, or require multi user purpose, that will blocked to be used, see issue:

@TomasVotruba TomasVotruba force-pushed the tv-deprecated-directory branch from 752dc4e to b136b1b Compare August 17, 2023 08:37
@TomasVotruba TomasVotruba force-pushed the tv-deprecated-directory branch from b136b1b to 4637080 Compare August 17, 2023 08:37
@TomasVotruba
Copy link
Member Author

Even normal user, user need to manually create /tmp/phpstan-container-for-rector, or it will crash:

We should have this test in CI. Could add simple reproducer to check this?

@TomasVotruba
Copy link
Member Author

I tried locally, by this change, it doesn't work, PHPStan need to fill cache directory to : /tmp/phpstan-container-for-rector which not yet exists:

The directory should be created then. I'll add it 👍

@TomasVotruba TomasVotruba force-pushed the tv-deprecated-directory branch from 81625f9 to 8b3c539 Compare August 17, 2023 08:44
@TomasVotruba TomasVotruba changed the title [DX] Deprecate RectorConfig containerCacheDirectory() as no longer used by container [DX] Merge RectorConfig cacheDirectory() and containerCacheDirectory() to one to ease changing paths in case of non-writeable cache Aug 17, 2023
@TomasVotruba TomasVotruba force-pushed the tv-deprecated-directory branch from 8b3c539 to 84d4fe5 Compare August 17, 2023 08:49
@samsonasik
Copy link
Member

@TomasVotruba Merge cache location is causing error:


There were 2 errors:

1) Rector\Tests\NodeTypeResolver\PerNodeTypeResolver\NameTypeResolver\NameTypeResolverTest::test with data set #0
InvalidArgumentException: Failed to create directory "/tmp/rector_cached_files/cache/PHPStan" (unknown cause).

see https://github.com/rectorphp/rector-src/actions/runs/5888776799/job/15970657037#step:5:26

@TomasVotruba
Copy link
Member Author

Looking into this. That seems like PHPStan dependency. Give me some time, I'll ask you for more feedback when ready 👍

/**
* @info Rector no longer uses compiled container, but Laravel lazy one.
* This option is for PHPStan container in case the sys_get_temp_dir() is not available for the current user.
*/
public function containerCacheDirectory(string $directoryPath): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if config cache merged, this method can be deprecated and removed on 1.0 as Option::CONTAINER_CACHE_DIRECTORY no longer be used if cache directory merged.

@samsonasik
Copy link
Member

Note to myself: after this applied, this need to be tried in local on switch on different projects with and without --clear-cache to test if cache not conflict each other.

@samsonasik
Copy link
Member

The new "unknown cause" error is equal with issue:

@TomasVotruba
Copy link
Member Author

Closing for now, as our focus is somewhere else. This should be revisited once AbstractRector is lighter

@TomasVotruba TomasVotruba deleted the tv-deprecated-directory branch September 15, 2023 09:37
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.

multiple users + [ERROR] Unable to create file ...
2 participants