Skip to content

Commit bc98d9c

Browse files
committed
PHPLIB-248: GridFS should report file mode using stat(2) bits
1 parent a6fd0be commit bc98d9c

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/GridFS/StreamWrapper.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ public function stream_stat()
145145
{
146146
$stat = $this->getStatTemplate();
147147

148-
$stat[2] = $stat['mode'] = $this->mode;
148+
$stat[2] = $stat['mode'] = $this->stream instanceof ReadableStream
149+
? 0100444 // S_IFREG & S_IRUSR & S_IRGRP & S_IROTH
150+
: 0100222; // S_IFREG & S_IWUSR & S_IWGRP & S_IWOTH
149151
$stat[7] = $stat['size'] = $this->stream->getSize();
150152

151153
return $stat;

tests/GridFS/StreamWrapperFunctionalTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ public function testReadableStreamRead()
4949
$this->assertSame('', fread($stream, 3));
5050
}
5151

52+
public function testReadableStreamStat()
53+
{
54+
$stream = $this->bucket->openDownloadStream('length-10');
55+
56+
$stat = fstat($stream);
57+
$this->assertSame(0100444, $stat[2]);
58+
$this->assertSame(0100444, $stat['mode']);
59+
}
60+
5261
public function testReadableStreamWrite()
5362
{
5463
$stream = $this->bucket->openDownloadStream('length-10');
@@ -84,6 +93,15 @@ public function testWritableStreamRead()
8493
$this->assertSame('', fread($stream, 8192));
8594
}
8695

96+
public function testWritableStreamStat()
97+
{
98+
$stream = $this->bucket->openUploadStream('filename');
99+
100+
$stat = fstat($stream);
101+
$this->assertSame(0100222, $stat[2]);
102+
$this->assertSame(0100222, $stat['mode']);
103+
}
104+
87105
public function testWritableStreamWrite()
88106
{
89107
$stream = $this->bucket->openUploadStream('filename');

0 commit comments

Comments
 (0)