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

multiple users + [ERROR] Unable to create file ... #8112

Closed
stefanides opened this issue Aug 3, 2023 · 5 comments
Closed

multiple users + [ERROR] Unable to create file ... #8112

stefanides opened this issue Aug 3, 2023 · 5 comments
Assignees

Comments

@stefanides
Copy link

Bug Report

Subject Details
Rector version Rector 0.17.1

Minimal PHP Code Causing Issue

Using rector with multiple users on the same machine (not reproducible on https://getrector.org/demo/)

Expected Behaviour

Rector can be used by multiple users concurently on the same machine

Description

Hi, I am facing the same/similar like issue #8103 - when multiple users are using rector on the same machine, the cache files are shared on global /tmp/ path allowing to create files there only to the first user. Others then see "Unable to create file..." because of wrong permissions on the "globally shared" location.

Some cache paths can be configured, e.g.
$rectorConfig->cacheDirectory(__DIR__ . '/tmp/rector_cached_files');

php8.2 -d sys_temp_dir=./tmp ./vendor/bin/rector ...

but even with this the aplication still wants write to /tmp/cache/PHPStan, /tmp/cache/nette.configurator and maybe more. Is there an (undocumented) way how to change ALL cache paths to some local directory or is it a bug that cache location cannot be changed to anything else than /tmp?

@stefanides stefanides added the bug label Aug 3, 2023
@samsonasik
Copy link
Member

Hi, for run by multiple user, I gues you can configure the rector.php to set the temp dir by username in the config:

return static function (RectorConfig $rectorConfig): void {
// ...
    $user = getenv('USERNAME') ?: getenv('USER');

    $rectorConfig->cacheDirectory(sys_get_temp_dir() . '/' . $user .  '/rector_cached_files');
    $rectorConfig->containerCacheDirectory(sys_get_temp_dir() . '/' . $user);
// ...
};

@stefanides
Copy link
Author

@samsonasik thanks for quick reply :)
$rectorConfig->containerCacheDirectory() does the trick, config -d sys_temp_dir=./tmp is then not needed, $rectorConfig->cacheDirectory() is still required.

Then I see as a bug this method is mentioned nowhere in the documentation (https://www.google.com/search?q=rector+"containerCacheDirectory") and probably the default value should be something else than the same path for each user? (also other apps use username or some id in /tmp paths like mc, systemd, mozilla, npm...)

@TomasVotruba
Copy link
Member

@stefanides Thanks for reporting. There should be indeed 1 option to set cache for Rector and let it handle internally, as other tools do.

I'm narrowing methods down in rectorphp/rector-src#4803 to cacheDirectory()

@TomasVotruba TomasVotruba self-assigned this Aug 17, 2023
@TomasVotruba
Copy link
Member

Closing as stale to avoid piling possible solved issue. Thanks for understanding 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants