Skip to content

Commit

Permalink
Fix nonexistent files not being created until written to
Browse files Browse the repository at this point in the history
  • Loading branch information
elazar committed Dec 11, 2023
1 parent 75b4674 commit 024690f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/StreamWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ public function stream_open(
$this->log('info', __METHOD__, func_get_args());
$this->path = $path;
$this->mode = $mode;
if (strpbrk($mode, 'waxc') !== false) {
$this->stream_write('');
$this->stream_flush();
}
return true;
}

Expand Down
11 changes: 11 additions & 0 deletions tests/StreamWrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@
rmdir('fly://foo');
});

it('can copy an empty file', function () {
$success = touch('fly://src');
expect($success)->toBe(true);

$success = copy('fly://src', 'fly://dst');
expect($success)->toBe(true);

$success = file_exists('fly://dst');
expect($success)->toBe(true);
});

it('handles opening a nonexistent directory', function () {
$dir = opendir('fly://foo');
expect($dir)->toBeResource();
Expand Down

0 comments on commit 024690f

Please sign in to comment.