Commit fcdc117c authored by Jeremy Mikola's avatar Jeremy Mikola

PHPLIB-249: GridFS stat should report modified and created timestamps

parent eab912fe
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
namespace MongoDB\GridFS; namespace MongoDB\GridFS;
use MongoDB\BSON\UTCDateTime;
use Exception; use Exception;
/** /**
...@@ -152,6 +153,12 @@ class StreamWrapper ...@@ -152,6 +153,12 @@ class StreamWrapper
$file = $this->stream->getFile(); $file = $this->stream->getFile();
if (isset($file->uploadDate) && $file->uploadDate instanceof UTCDateTime) {
$timestamp = $file->uploadDate->toDateTime()->getTimestamp();
$stat[9] = $stat['mtime'] = $timestamp;
$stat[10] = $stat['ctime'] = $timestamp;
}
if (isset($file->chunkSize) && is_integer($file->chunkSize)) { if (isset($file->chunkSize) && is_integer($file->chunkSize)) {
$stat[11] = $stat['blksize'] = $file->chunkSize; $stat[11] = $stat['blksize'] = $file->chunkSize;
} }
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace MongoDB\Tests\GridFS; namespace MongoDB\Tests\GridFS;
use MongoDB\BSON\Binary; use MongoDB\BSON\Binary;
use MongoDB\BSON\UTCDateTime;
/** /**
* Functional tests for the internal StreamWrapper class. * Functional tests for the internal StreamWrapper class.
...@@ -14,7 +15,7 @@ class StreamWrapperFunctionalTest extends FunctionalTestCase ...@@ -14,7 +15,7 @@ class StreamWrapperFunctionalTest extends FunctionalTestCase
parent::setUp(); parent::setUp();
$this->filesCollection->insertMany([ $this->filesCollection->insertMany([
['_id' => 'length-10', 'length' => 10, 'chunkSize' => 4], ['_id' => 'length-10', 'length' => 10, 'chunkSize' => 4, 'uploadDate' => new UTCDateTime('1484202200000')],
]); ]);
$this->chunksCollection->insertMany([ $this->chunksCollection->insertMany([
...@@ -58,6 +59,10 @@ class StreamWrapperFunctionalTest extends FunctionalTestCase ...@@ -58,6 +59,10 @@ class StreamWrapperFunctionalTest extends FunctionalTestCase
$this->assertSame(0100444, $stat['mode']); $this->assertSame(0100444, $stat['mode']);
$this->assertSame(10, $stat[7]); $this->assertSame(10, $stat[7]);
$this->assertSame(10, $stat['size']); $this->assertSame(10, $stat['size']);
$this->assertSame(1484202200, $stat[9]);
$this->assertSame(1484202200, $stat['mtime']);
$this->assertSame(1484202200, $stat[10]);
$this->assertSame(1484202200, $stat['ctime']);
$this->assertSame(4, $stat[11]); $this->assertSame(4, $stat[11]);
$this->assertSame(4, $stat['blksize']); $this->assertSame(4, $stat['blksize']);
} }
...@@ -99,6 +104,7 @@ class StreamWrapperFunctionalTest extends FunctionalTestCase ...@@ -99,6 +104,7 @@ class StreamWrapperFunctionalTest extends FunctionalTestCase
public function testWritableStreamStat() public function testWritableStreamStat()
{ {
$currentTimestamp = time();
$stream = $this->bucket->openUploadStream('filename', ['chunkSizeBytes' => 1024]); $stream = $this->bucket->openUploadStream('filename', ['chunkSizeBytes' => 1024]);
$stat = fstat($stream); $stat = fstat($stream);
...@@ -106,6 +112,10 @@ class StreamWrapperFunctionalTest extends FunctionalTestCase ...@@ -106,6 +112,10 @@ class StreamWrapperFunctionalTest extends FunctionalTestCase
$this->assertSame(0100222, $stat['mode']); $this->assertSame(0100222, $stat['mode']);
$this->assertSame(0, $stat[7]); $this->assertSame(0, $stat[7]);
$this->assertSame(0, $stat['size']); $this->assertSame(0, $stat['size']);
$this->assertGreaterThanOrEqual($currentTimestamp, $stat[9]);
$this->assertGreaterThanOrEqual($currentTimestamp, $stat['mtime']);
$this->assertGreaterThanOrEqual($currentTimestamp, $stat[10]);
$this->assertGreaterThanOrEqual($currentTimestamp, $stat['ctime']);
$this->assertSame(1024, $stat[11]); $this->assertSame(1024, $stat[11]);
$this->assertSame(1024, $stat['blksize']); $this->assertSame(1024, $stat['blksize']);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment