Make possible to provide a specific HTTP request object to File
This will be used in a following commit to test how the X-OC-MTime header is handled. This commit is based on the "make File::put() more testable" commit (included in 018d45cad97e0) from ownCloud by Artur Neumann. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
parent
01e346b2ae
commit
2af3d8a9b2
2 changed files with 35 additions and 12 deletions
|
@ -36,13 +36,16 @@
|
|||
|
||||
namespace OCA\DAV\Connector\Sabre;
|
||||
|
||||
use OC\AppFramework\Http\Request;
|
||||
use OC\Files\Filesystem;
|
||||
use OC\Files\View;
|
||||
use OCA\DAV\Connector\Sabre\Exception\EntityTooLarge;
|
||||
use OCA\DAV\Connector\Sabre\Exception\FileLocked;
|
||||
use OCA\DAV\Connector\Sabre\Exception\Forbidden as DAVForbiddenException;
|
||||
use OCA\DAV\Connector\Sabre\Exception\UnsupportedMediaType;
|
||||
use OCP\Encryption\Exceptions\GenericEncryptionException;
|
||||
use OCP\Files\EntityTooLargeException;
|
||||
use OCP\Files\FileInfo;
|
||||
use OCP\Files\ForbiddenException;
|
||||
use OCP\Files\InvalidContentException;
|
||||
use OCP\Files\InvalidPathException;
|
||||
|
@ -51,6 +54,7 @@ use OCP\Files\NotPermittedException;
|
|||
use OCP\Files\StorageNotAvailableException;
|
||||
use OCP\Lock\ILockingProvider;
|
||||
use OCP\Lock\LockedException;
|
||||
use OCP\Share\IManager;
|
||||
use Sabre\DAV\Exception;
|
||||
use Sabre\DAV\Exception\BadRequest;
|
||||
use Sabre\DAV\Exception\Forbidden;
|
||||
|
@ -61,6 +65,26 @@ use Sabre\DAV\Exception\NotFound;
|
|||
|
||||
class File extends Node implements IFile {
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Sets up the node, expects a full path name
|
||||
*
|
||||
* @param \OC\Files\View $view
|
||||
* @param \OCP\Files\FileInfo $info
|
||||
* @param \OCP\Share\IManager $shareManager
|
||||
* @param \OC\AppFramework\Http\Request $request
|
||||
*/
|
||||
public function __construct(View $view, FileInfo $info, IManager $shareManager = null, Request $request = null) {
|
||||
parent::__construct($view, $info, $shareManager);
|
||||
|
||||
if (isset($request)) {
|
||||
$this->request = $request;
|
||||
} else {
|
||||
$this->request = \OC::$server->getRequest();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the data
|
||||
*
|
||||
|
@ -208,9 +232,8 @@ class File extends Node implements IFile {
|
|||
}
|
||||
|
||||
// allow sync clients to send the mtime along in a header
|
||||
$request = \OC::$server->getRequest();
|
||||
if (isset($request->server['HTTP_X_OC_MTIME'])) {
|
||||
$mtime = $this->sanitizeMtime($request->server['HTTP_X_OC_MTIME']);
|
||||
if (isset($this->request->server['HTTP_X_OC_MTIME'])) {
|
||||
$mtime = $this->sanitizeMtime($this->request->server['HTTP_X_OC_MTIME']);
|
||||
if ($this->fileView->touch($this->path, $mtime)) {
|
||||
header('X-OC-MTime: accepted');
|
||||
}
|
||||
|
@ -222,8 +245,8 @@ class File extends Node implements IFile {
|
|||
|
||||
$this->refreshInfo();
|
||||
|
||||
if (isset($request->server['HTTP_OC_CHECKSUM'])) {
|
||||
$checksum = trim($request->server['HTTP_OC_CHECKSUM']);
|
||||
if (isset($this->request->server['HTTP_OC_CHECKSUM'])) {
|
||||
$checksum = trim($this->request->server['HTTP_OC_CHECKSUM']);
|
||||
$this->fileView->putFileInfo($this->path, ['checksum' => $checksum]);
|
||||
$this->refreshInfo();
|
||||
} else if ($this->getChecksum() !== null && $this->getChecksum() !== '') {
|
||||
|
@ -466,9 +489,8 @@ class File extends Node implements IFile {
|
|||
}
|
||||
|
||||
// allow sync clients to send the mtime along in a header
|
||||
$request = \OC::$server->getRequest();
|
||||
if (isset($request->server['HTTP_X_OC_MTIME'])) {
|
||||
$mtime = $this->sanitizeMtime($request->server['HTTP_X_OC_MTIME']);
|
||||
if (isset($this->request->server['HTTP_X_OC_MTIME'])) {
|
||||
$mtime = $this->sanitizeMtime($this->request->server['HTTP_X_OC_MTIME']);
|
||||
if ($targetStorage->touch($targetInternalPath, $mtime)) {
|
||||
header('X-OC-MTime: accepted');
|
||||
}
|
||||
|
@ -484,8 +506,8 @@ class File extends Node implements IFile {
|
|||
// FIXME: should call refreshInfo but can't because $this->path is not the of the final file
|
||||
$info = $this->fileView->getFileInfo($targetPath);
|
||||
|
||||
if (isset($request->server['HTTP_OC_CHECKSUM'])) {
|
||||
$checksum = trim($request->server['HTTP_OC_CHECKSUM']);
|
||||
if (isset($this->request->server['HTTP_OC_CHECKSUM'])) {
|
||||
$checksum = trim($this->request->server['HTTP_OC_CHECKSUM']);
|
||||
$this->fileView->putFileInfo($targetPath, ['checksum' => $checksum]);
|
||||
} else if ($info->getChecksum() !== null && $info->getChecksum() !== '') {
|
||||
$this->fileView->putFileInfo($this->path, ['checksum' => '']);
|
||||
|
|
|
@ -284,10 +284,11 @@ class FileTest extends \Test\TestCase {
|
|||
*
|
||||
* @param string $path path to put the file into
|
||||
* @param string $viewRoot root to use for the view
|
||||
* @param null|\OC\AppFramework\Http\Request $request the HTTP request
|
||||
*
|
||||
* @return null|string of the PUT operaiton which is usually the etag
|
||||
*/
|
||||
private function doPut($path, $viewRoot = null) {
|
||||
private function doPut($path, $viewRoot = null, \OC\AppFramework\Http\Request $request = null) {
|
||||
$view = \OC\Files\Filesystem::getView();
|
||||
if (!is_null($viewRoot)) {
|
||||
$view = new \OC\Files\View($viewRoot);
|
||||
|
@ -303,7 +304,7 @@ class FileTest extends \Test\TestCase {
|
|||
null
|
||||
);
|
||||
|
||||
$file = new \OCA\DAV\Connector\Sabre\File($view, $info);
|
||||
$file = new \OCA\DAV\Connector\Sabre\File($view, $info, null, $request);
|
||||
|
||||
// beforeMethod locks
|
||||
$view->lockFile($path, ILockingProvider::LOCK_SHARED);
|
||||
|
|
Loading…
Reference in a new issue