Skip to content

Conversation

@OndrejSlamecka
Copy link

This commit adds more comprehensible error reporting to the move() method in the following scenarios:

  • Say the program has insufficient permissions to create the directory dirname($dest). With this commit the move() method correctly raises mkdir(): Permission denied warning instead of warning raised by move_uploaded_file: failed to open stream: No such file or directory with previous code.
  • Or the already existing file at $dest may not be deleted with the current permissions. With this commit a correct Permission denied warning is again raised by unlink instead of warning raised by move_uploaded_file with previous code.

This commit adds more comprehensible error reporting to the `move()` method in the following scenarios:

* Say the program has insufficient permissions to create the directory `dirname($dest)`. With this commit the `move()` method correctly raises `mkdir(): Permission denied` warning instead of warning raised by `move_uploaded_file`: `failed to open stream: No such file or directory` with previous code.
* Or the already existing file at `$dest` may not be deleted with the current permissions. With this commit a correct `Permission denied` warning is again raised by `unlink` instead of warning raised by `move_uploaded_file` with previous code.
@hrach
Copy link
Contributor

hrach commented Mar 1, 2016

You solution suffers with race condition problem.

@enumag
Copy link
Contributor

enumag commented Mar 1, 2016

Then how about keeping the original code and adding if (file_exists($dest)) { throw new ... }?

@OndrejSlamecka
Copy link
Author

Good point and good suggestion, thank you. The commit above should prevent the problem at least to the level the previous code prevented such problems.

Is InvalidStateException the right one to be thrown?

@hrach
Copy link
Contributor

hrach commented Mar 1, 2016

Are you sure, that only reason why directory has not been created is the permission problem? :)

@OndrejSlamecka
Copy link
Author

Right, inode limit comes to mind. I made the text more general with the commit above.

@JanTvrdik
Copy link
Contributor

See nette/tracy#133

@dg
Copy link
Member

dg commented Jun 17, 2016

What about call mkdir only when dir doesn't exist and remove @?

@Majkl578
Copy link
Contributor

That wouldn't be atomic though.

@dg
Copy link
Member

dg commented Jun 17, 2016

This issue is about suppressing, isn't it?

@Majkl578
Copy link
Contributor

I replied to your previous comment:

call mkdir only when dir doesn't exist

@dg
Copy link
Member

dg commented Jun 25, 2016

I understand.

@dg dg closed this in 659e277 Jun 25, 2016
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.

6 participants