Commit 7b4861f0 authored by catch's avatar catch

Issue #2901998 by vaplas, damiankloip, kim.pepper: File size of 0 is not set...

Issue #2901998 by vaplas, damiankloip, kim.pepper: File size of 0 is not set when file entities are saved
parent 9ef92a40
...@@ -190,7 +190,10 @@ public function preSave(EntityStorageInterface $storage) { ...@@ -190,7 +190,10 @@ public function preSave(EntityStorageInterface $storage) {
// The file itself might not exist or be available right now. // The file itself might not exist or be available right now.
$uri = $this->getFileUri(); $uri = $this->getFileUri();
if ($size = @filesize($uri)) { $size = @filesize($uri);
// Set size unless there was an error.
if ($size !== FALSE) {
$this->setSize($size); $this->setSize($size);
} }
} }
......
...@@ -81,6 +81,22 @@ public function testFileSave() { ...@@ -81,6 +81,22 @@ public function testFileSave() {
$this->assertEqual(1, count($fids)); $this->assertEqual(1, count($fids));
$this->assertEqual([$uppercase_file->id() => $uppercase_file->id()], $fids); $this->assertEqual([$uppercase_file->id() => $uppercase_file->id()], $fids);
// Save a file with zero bytes.
$file = File::create([
'uid' => 1,
'filename' => 'no-druplicon.txt',
'uri' => 'public://no-druplicon.txt',
'filemime' => 'text/plain',
'status' => FILE_STATUS_PERMANENT,
]);
file_put_contents($file->getFileUri(), '');
// Save it, inserting a new record.
$file->save();
// Check the file size was set to zero.
$this->assertSame(0, $file->getSize());
} }
} }
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