Detect correctly if an attachment file is not existing.

This commit is contained in:
Jan Böhmer 2019-10-03 14:27:20 +02:00
parent d3162a0d75
commit 6799ac90e5

View file

@ -88,8 +88,12 @@ class AttachmentHelper
return null; return null;
} }
$path = $attachment->getPath(); $path = $this->pathResolver->placeholderToRealPath($attachment->getPath());
$path = $this->pathResolver->placeholderToRealPath($path);
//realpath does not work with null as argument
if ($path === null) {
return null;
}
return realpath($path); return realpath($path);
} }
@ -112,7 +116,7 @@ class AttachmentHelper
/** /**
* Returns the filesize of the attachments in bytes. * Returns the filesize of the attachments in bytes.
* For external attachments, null is returned. * For external attachments or not existing attachments, null is returned.
* *
* @param Attachment $attachment The filesize for which the filesize should be calculated. * @param Attachment $attachment The filesize for which the filesize should be calculated.
* @return int|null * @return int|null
@ -123,7 +127,12 @@ class AttachmentHelper
return null; return null;
} }
return filesize($this->toAbsoluteFilePath($attachment)); if (!$this->isFileExisting($attachment)) {
return null;
}
$tmp = filesize($this->toAbsoluteFilePath($attachment));
return $tmp !== false ? $tmp : null;
} }
/** /**