-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
putContents doesn't truncate the file like file_put_contents #63
Comments
The |
That's not the intention, have you tried out the changes in #62? |
Yes, tried with c98de2f and still the same. |
Will look into it, have some PR planned for filesystem and will fix this with those as well |
https://secure.php.net/manual/en/function.fopen.php If you're using Eio, this might look a bit differently. But this unit test on a separate branch (splitted from the PR with added truncate unit test) shows the file is truncated before writing: (The only build passing at the time of writing this comment was PHP 5.6, the others were restarted due to typical Eio timeouts and are unrelated to the described issue.) |
@WyriHaximus @choval @CharlotteDunois any update on this? |
@developernaren I'm not sure where we left off, can you reproduce the issue? Maybe the |
@CharlotteDunois it has the exact behavior as the original code in the first comment.
|
@developernaren Do you have the same behaviour with $promise = $fs->getAdapter()->putContents($file, '11'); instead? |
@CharlotteDunois there is no |
@developernaren There is in the master branch. 00ed432 |
I am trying to use it in this framework https://driftphp.io/. I am not exactly sure how to fix use master as this is the dependency of a dependency. |
@developernaren I'll try the master branch tonite and get back to you. |
Still the same using the latest master 3133bd7, which includes 00ed432. If you use https://github.com/reactphp/filesystem/blob/master/src/Node/File.php From:
To:
I no longer use this library. Good luck. Test: #!/usr/bin/env php
<?php
require('vendor/autoload.php');
$loop = \React\EventLoop\Factory::create();
$fs = \React\Filesystem\Filesystem::create($loop);
$file = 'tmp.txt';
file_put_contents( $file, 'xx');
$promise = $fs->file( $file )->putContents( 'o' );
$promise->done(
function($r) use ($file) {
$data = file_get_contents($file);
if ($data === 'o') {
echo "GOOD!\n";
} else {
echo "Expected 'o', but got 'xx' \n";
}
},
function($e) {
echo $e->getMessage()."\n";
});
$loop->run(); |
@choval thank you so much for trying this out. really appreciate the effort. |
React\Filesystem\Node\File::putContents
@ line 158 opens without truncating optiont
. Hence, it writes the length of the content and leaves previous existing bytes.It kinda goes against the regular behaviour of
file_put_contents
, is this intended?The text was updated successfully, but these errors were encountered: