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

phinx init results in directory is not writable when path contains OneDrive #2343

Open
MichaelMrt opened this issue Feb 25, 2025 · 1 comment

Comments

@MichaelMrt
Copy link

Problem

I tried to follow the Installation guide from the docs and couldn't get past
vendor/bin/phinx init

The Issue I got is:

In Init.php line 146:

  The directory "C:\path\to\myrepo" is not writable  


init [-f|--format FORMAT] [--] [<path>]

What I tried

After looking at line 146:
if (!is_writable($dirname)) {

I separately tested the is_writable() method in php
php -r "echo is_writable('C:\\path\\to\\myrepo') ? 'Writable' : 'Not writable';"
and the result was Not writable.

Then I tested creating a file and writing into it with php
php -r "if(file_put_contents('C:\\path\\to\\myrepo\\phpwritten.txt','test')) { echo 'Success'; } else { echo 'Error';
and it worked.

After some testing I found out the Onedrive part is making the is_writable() method return false.
C:\Users\myuser\OneDrive - company\myrepo

Workaround

After using a path without OneDrive in it everything worked.
Also removing line 146 lead to a successful creation of the phinx.php file

Maybe there is a way to fix this or add a note in the docs like in #116 ?

@MasterOdin
Copy link
Member

MasterOdin commented Mar 1, 2025

Thanks for the report. I think the solution here is to remove the check and then just rely on file_put_contents failing for really deciding if something isn't writable or not, maybe doing something like:

        if (file_put_contents($path, $contents) === false) {
            throw new RuntimeException(!is_writable($dirname) ? sprintf(
                'The directory "%s" is not writable',
                $dirname
            ) : sprintf(
                 'The file "%s" could not be written to',
                $path
            ));
        }

I doubt there should ever be a case where file_put_contents(...) works while !is_writable($dirname) where we're fine still doing the write regardless. I think having the error message around !is_writable($dirname) is still useful though, hence the ternary within the conditional.

If you want to make a PR, happy to look it over, otherwise I'll try to get something done next week sometime.

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

No branches or pull requests

2 participants