File tree 2 files changed +21
-4
lines changed
2 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -172,10 +172,10 @@ private function push(string $data): Promise
172
172
}
173
173
} else {
174
174
StatCache::clear ($ this ->path );
175
- $ newPosition = $ this ->position + $ length ;
176
- $ delta = $ newPosition - $ this ->position ;
177
- $ this -> position = ( $ this ->mode [ 0 ] === " a " ) ? $ this ->position : $ newPosition ;
178
- $ this -> size += $ delta ;
175
+ $ this ->position += $ length ;
176
+ if ( $ this -> position > $ this ->size ) {
177
+ $ this ->size = $ this ->position ;
178
+ }
179
179
$ deferred ->resolve ($ length );
180
180
}
181
181
};
Original file line number Diff line number Diff line change @@ -79,6 +79,23 @@ public function testWriteAfterEnd()
79
79
});
80
80
}
81
81
82
+ public function testWriteInAppendMode ()
83
+ {
84
+ $ this ->execute (function () {
85
+ $ path = Fixture::path () . "/write " ;
86
+ /** @var \Amp\File\Handle $handle */
87
+ $ handle = yield File \open ($ path , "a+ " );
88
+ $ this ->assertSame (0 , $ handle ->tell ());
89
+ yield $ handle ->write ("bar " );
90
+ yield $ handle ->write ("foo " );
91
+ yield $ handle ->write ("baz " );
92
+ $ this ->assertSame (9 , $ handle ->tell ());
93
+ yield $ handle ->seek (0 );
94
+ $ this ->assertSame (0 , $ handle ->tell ());
95
+ $ this ->assertSame ("barfoobaz " , yield $ handle ->read ());
96
+ });
97
+ }
98
+
82
99
public function testReadingToEof ()
83
100
{
84
101
$ this ->execute (function () {
You can’t perform that action at this time.
0 commit comments