From c8a13f644ebbc5840d0e632cf86e5ae46856f7f0 Mon Sep 17 00:00:00 2001
From: Roeland Jago Douma <roeland@famdouma.nl>
Date: Mon, 24 Oct 2016 21:44:12 +0200
Subject: [PATCH] Only enable files_drop plugin when we actuall do files_drop

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
---
 apps/dav/appinfo/v1/publicwebdav.php          |  5 +++++
 .../dav/lib/Files/Sharing/FilesDropPlugin.php | 20 +++++++++++++++----
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/apps/dav/appinfo/v1/publicwebdav.php b/apps/dav/appinfo/v1/publicwebdav.php
index 2177a4b3ed0..670eadd5ea9 100644
--- a/apps/dav/appinfo/v1/publicwebdav.php
+++ b/apps/dav/appinfo/v1/publicwebdav.php
@@ -88,6 +88,11 @@ $server = $serverFactory->createServer($baseuri, $requestUri, $authBackend, func
 	$fileInfo = $ownerView->getFileInfo($path);
 	$linkCheckPlugin->setFileInfo($fileInfo);
 
+	// If not readble (files_drop) enable the filesdrop plugin
+	if (!$isReadable) {
+		$filesDropPlugin->enable();
+	}
+
 	$view = new \OC\Files\View($ownerView->getAbsolutePath($path));
 	$filesDropPlugin->setView($view);
 
diff --git a/apps/dav/lib/Files/Sharing/FilesDropPlugin.php b/apps/dav/lib/Files/Sharing/FilesDropPlugin.php
index bc00ea0771b..ccfa452cb68 100644
--- a/apps/dav/lib/Files/Sharing/FilesDropPlugin.php
+++ b/apps/dav/lib/Files/Sharing/FilesDropPlugin.php
@@ -32,11 +32,12 @@ use Sabre\HTTP\ResponseInterface;
  */
 class FilesDropPlugin extends ServerPlugin {
 
-	/**
-	 * @var View
-	 */
+	/** @var View */
 	private $view;
 
+	/** @var bool */
+	private $enabled = false;
+
 	/**
 	 * @param View $view
 	 */
@@ -44,6 +45,11 @@ class FilesDropPlugin extends ServerPlugin {
 		$this->view = $view;
 	}
 
+	public function enable() {
+		$this->enabled = true;
+	}
+
+
 	/**
 	 * This initializes the plugin.
 	 *
@@ -52,10 +58,16 @@ class FilesDropPlugin extends ServerPlugin {
 	 * @return void
 	 */
 	public function initialize(\Sabre\DAV\Server $server) {
-		$server->on('beforeMethod', [$this, 'beforeMethod']);
+		$server->on('beforeMethod:PUT', [$this, 'beforeMethod']);
+		$this->enabled = false;
 	}
 
 	public function beforeMethod(RequestInterface $request, ResponseInterface $response){
+
+		if (!$this->enabled) {
+			return;
+		}
+
 		$path = $request->getPath();
 
 		if ($this->view->file_exists($path)) {
-- 
GitLab