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

[BUG]: FilesystemInterface prefix (if file is selected instead of path) #4301

Closed
Kanti opened this issue Sep 6, 2024 · 3 comments · Fixed by rectorphp/rector-src#6293
Closed
Labels

Comments

@Kanti
Copy link
Contributor

Kanti commented Sep 6, 2024

Minimal PHP Code Causing Issue

given:
file in /app/src/extensions/aus_project/ext_tables.php with content:

<?php
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages('tx_ausproject_domain_model_slide,tx_ausproject_domain_model_teaser');

running rector process --debug src/extensions/aus_project/ext_tables.php in /app directory.

Producess:

[ERROR] Could not process "src/extensions/aus_project/ext_tables.php" file, due to:
         "System error: "Unable to create a directory at /src/extensions/aus_project/Configuration/TCA/Overrides.
         mkdir(): Permission denied"

         Stack trace:
         #0 vendor/league/flysystem/src/Local/LocalFilesystemAdapter.php(297):
         League\Flysystem\UnableToCreateDirectory::atLocation('/src/extensions...', 'mkdir(): Permis...')
         #1 vendor/league/flysystem/src/Local/LocalFilesystemAdapter.php(116):
         League\Flysystem\Local\LocalFilesystemAdapter->ensureDirectoryExists('/src/extensions...', 448)
         #2 vendor/league/flysystem/src/Local/LocalFilesystemAdapter.php(102):
         League\Flysystem\Local\LocalFilesystemAdapter->writeToFile('src/extensions/...', '<?php\n\n// Inclu...',
         Object(League\Flysystem\Config))
         #3 vendor/league/flysystem/src/Filesystem.php(41):
         League\Flysystem\Local\LocalFilesystemAdapter->write('src/extensions/...', '<?php\n\n// Inclu...',
         Object(League\Flysystem\Config))
         #4 vendor/ssch/typo3-rector/src/Filesystem/FlysystemFilesystem.php(24):
         League\Flysystem\Filesystem->write('src/extensions/...', '<?php\n\n// Inclu...')
         #5
         vendor/ssch/typo3-rector/rules/CodeQuality/General/MoveExtensionManagementUtilityAddStaticFileIntoTCAOverridesR
         ector.php(121): Ssch\TYPO3Rector\Filesystem\FlysystemFilesystem->write('src/extensions/...', '<?php\n\n//
         Inclu...')
         #6 vendor/rector/rector/src/Rector/AbstractRector.php(136):
         Ssch\TYPO3Rector\CodeQuality\General\MoveExtensionManagementUtilityAddStaticFileIntoTCAOverridesRector->refact
         or(Object(PhpParser\Node\Stmt\Expression))
         #7 vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(176):
         Rector\Rector\AbstractRector->enterNode(Object(PhpParser\Node\Stmt\Expression))
         #8 vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(105):
         PhpParser\NodeTraverser->traverseArray(Array)
         #9 vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(133):
         PhpParser\NodeTraverser->traverseNode(Object(PhpParser\Node\Expr\Closure))
         #10 vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(196):
         PhpParser\NodeTraverser->traverseNode(Object(PhpParser\Node\Arg))
         #11 vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(105):
         PhpParser\NodeTraverser->traverseArray(Array)

this bug is only cased if the rector config as Paths specified directly to a PHP file.
eg through the cli: rector process src/extension/test_extension/ext_tables.php
or by a config line like this: in the rector.php

$rectorConfig->paths(
    array_filter(explode("\n", (string)shell_exec("git ls-files | xargs ls -d 2>/dev/null | grep -E '\.(php)$'")))
);

Applied rules

MoveExtensionManagementUtilityAddStaticFileIntoTCAOverridesRector but this should affect every Rector rule that writes files the same way.

Expected Behaviour

But should try to create files in /app/src/...

Package Version

<2.6.1 && > 2.6.4

PHP Version

TYPO3 Version

Notes

Related Issues:

@Kanti
Copy link
Contributor Author

Kanti commented Sep 6, 2024

Problem with the getcwd() solution:

If you run the rector command from a different folder than your rector.php file, than it will try to create the files in the wrong location. Relative to the current working directory instead of relative to the project root :/

@Kanti
Copy link
Contributor Author

Kanti commented Sep 6, 2024

vendor/rector/rector/src/Rector/AbstractRector.php:121.
Here the $file is different if you specify a filename instead of a directory.
With a directory, $file is an absolute path.
With a file, $file is a relative path.

Maybe this is more a bug in rector/rector.

I'll investigate more.

@Kanti
Copy link
Contributor Author

Kanti commented Sep 9, 2024

This is now fixed with the rector release https://github.com/rectorphp/rector/tree/1.2.5

@Kanti Kanti closed this as completed Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant