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

Support fileMode fileOwnership in create migration #18676

Merged

Conversation

rhertogh
Copy link
Contributor

Q A
Is bugfix?
New feature? ✔️
Breaks BC?
Tests pass? ✔️
Fixed issues yiisoft/yii2-docker/issues/15

@rhertogh rhertogh changed the title Support file mode and owner in create migration Support fileMode fileOwnership in create migration May 23, 2021
@rhertogh rhertogh marked this pull request as ready for review May 23, 2021 18:02
@samdark
Copy link
Member

samdark commented May 23, 2021

Are you sure you've specified correct issue number?

@rhertogh
Copy link
Contributor Author

Are you sure you've specified correct issue number?

You mean the 'Fixed issues'? Yes, I had the same problem when the migration was created inside a Docker container and the file is edited on the host (mounted via WSL2 on Ubuntu) changes can't be written to the file.

@samdark samdark added this to the 2.0.43 milestone May 23, 2021
…ontroller and BaseFileHelper::changeOwnership()
@samdark samdark requested review from bizley and a team May 24, 2021 10:06
framework/CHANGELOG.md Outdated Show resolved Hide resolved
framework/console/controllers/BaseMigrateController.php Outdated Show resolved Hide resolved
@rhertogh
Copy link
Contributor Author

@samdark @bizley We could add a changeModeAndOwnership($file, $mode = null, $ownership = null) function to the BaseFileHelper. This would make the code in other places more clean and reusable. What do you think?

@bizley
Copy link
Member

bizley commented May 24, 2021

Changing mode is pretty straight forward, but maybe this could be added indeed as a bonus to this new method (so more like a changeOwnershipAndMode).

@rhertogh
Copy link
Contributor Author

@bizley

Changing mode is pretty straight forward, but maybe this could be added indeed as a bonus to this new method (so more like a changeOwnershipAndMode).

I've added the $mode parameter to changeOwnership() but left the name unchanged since $mode is optional.
The @s are also gone from the ch*() functions since changeOwnership() always raises an error on failure. This also gives a better error message. For example var_dump(chmod('test.txt','test')); outputs PHP Warning: chown(): Unable to find uid for test.
Now changeOwnership() no longer returns a value but always (except on Windows) ensures the change of ownership and/or permissions as discussed here: #18676 (comment).

@rhertogh rhertogh marked this pull request as draft May 24, 2021 18:08
@rhertogh
Copy link
Contributor Author

Working on unit test

@rhertogh rhertogh marked this pull request as ready for review May 28, 2021 18:13
@rhertogh
Copy link
Contributor Author

Unit tests are added. Some require root user to complete.

Copy link
Member

@bizley bizley left a comment

Choose a reason for hiding this comment

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

Just some code style, rest LGTM

framework/helpers/BaseFileHelper.php Outdated Show resolved Hide resolved
framework/helpers/BaseFileHelper.php Outdated Show resolved Hide resolved
framework/helpers/BaseFileHelper.php Outdated Show resolved Hide resolved
framework/helpers/BaseFileHelper.php Outdated Show resolved Hide resolved
framework/helpers/BaseFileHelper.php Outdated Show resolved Hide resolved
framework/helpers/BaseFileHelper.php Outdated Show resolved Hide resolved
framework/helpers/BaseFileHelper.php Outdated Show resolved Hide resolved
framework/helpers/BaseFileHelper.php Outdated Show resolved Hide resolved
framework/helpers/BaseFileHelper.php Outdated Show resolved Hide resolved
framework/helpers/BaseFileHelper.php Outdated Show resolved Hide resolved
Fixed code style and spelling based on feedback from @bizley

Co-authored-by: Bizley <[email protected]>
Copy link
Member

@bizley bizley left a comment

Choose a reason for hiding this comment

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

While porting this change to my own migration extension I've noticed that getmyuid() and getmygid() returning not the ids of the current user and user's group but rather the ids of the running script owner. So this needs to be changed (proposed here). Also noticed few more exception messages adjustments.

tests/framework/helpers/FileHelperTest.php Outdated Show resolved Hide resolved
tests/framework/helpers/FileHelperTest.php Outdated Show resolved Hide resolved
tests/framework/helpers/FileHelperTest.php Outdated Show resolved Hide resolved
framework/helpers/BaseFileHelper.php Outdated Show resolved Hide resolved
framework/helpers/BaseFileHelper.php Outdated Show resolved Hide resolved
rhertogh and others added 2 commits May 29, 2021 16:23
@samdark samdark merged commit 31ca0fc into yiisoft:master May 30, 2021
@samdark
Copy link
Member

samdark commented May 30, 2021

👍

markhuot pushed a commit to markhuot/yii2 that referenced this pull request Jul 27, 2021
…nership()` and properties `newFileMode`/`newFileOwnership` in `yii\console\controllers\BaseMigrateController`

Co-authored-by: Bizley <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants