Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'apps/workflowengine/lib/Check')
-rw-r--r--apps/workflowengine/lib/Check/AbstractStringCheck.php3
-rw-r--r--apps/workflowengine/lib/Check/FileMimeType.php105
-rw-r--r--apps/workflowengine/lib/Check/FileName.php3
-rw-r--r--apps/workflowengine/lib/Check/FileSize.php3
-rw-r--r--apps/workflowengine/lib/Check/FileSystemTags.php3
-rw-r--r--apps/workflowengine/lib/Check/RequestRemoteAddress.php3
-rw-r--r--apps/workflowengine/lib/Check/RequestTime.php3
-rw-r--r--apps/workflowengine/lib/Check/UserGroupMembership.php3
8 files changed, 35 insertions, 91 deletions
diff --git a/apps/workflowengine/lib/Check/AbstractStringCheck.php b/apps/workflowengine/lib/Check/AbstractStringCheck.php
index 0fd728e3496..8ea987c1e52 100644
--- a/apps/workflowengine/lib/Check/AbstractStringCheck.php
+++ b/apps/workflowengine/lib/Check/AbstractStringCheck.php
@@ -44,8 +44,9 @@ abstract class AbstractStringCheck implements ICheck {
/**
* @param IStorage $storage
* @param string $path
+ * @param bool $isDir
*/
- public function setFileInfo(IStorage $storage, $path) {
+ public function setFileInfo(IStorage $storage, $path, $isDir = false) {
// Nothing changes here with a different path
}
diff --git a/apps/workflowengine/lib/Check/FileMimeType.php b/apps/workflowengine/lib/Check/FileMimeType.php
index 8f2f8c9e1d4..b3955fbd38b 100644
--- a/apps/workflowengine/lib/Check/FileMimeType.php
+++ b/apps/workflowengine/lib/Check/FileMimeType.php
@@ -58,13 +58,19 @@ class FileMimeType extends AbstractStringCheck {
/**
* @param IStorage $storage
* @param string $path
+ * @param bool $isDir
*/
- public function setFileInfo(IStorage $storage, $path) {
+ public function setFileInfo(IStorage $storage, $path, $isDir = false) {
$this->storage = $storage;
$this->path = $path;
if (!isset($this->mimeType[$this->storage->getId()][$this->path])
|| $this->mimeType[$this->storage->getId()][$this->path] === '') {
- $this->mimeType[$this->storage->getId()][$this->path] = null;
+
+ if ($isDir) {
+ $this->mimeType[$this->storage->getId()][$this->path] = 'httpd/unix-directory';
+ } else {
+ $this->mimeType[$this->storage->getId()][$this->path] = null;
+ }
}
}
@@ -103,93 +109,24 @@ class FileMimeType extends AbstractStringCheck {
return $this->cacheAndReturnMimeType($this->storage->getId(), $this->path, 'httpd/unix-directory');
}
- if ($this->isWebDAVRequest()) {
- // Creating a folder
- if ($this->request->getMethod() === 'MKCOL') {
- return $this->cacheAndReturnMimeType($this->storage->getId(), $this->path, 'httpd/unix-directory');
- }
-
- if ($this->request->getMethod() === 'PUT' || $this->request->getMethod() === 'MOVE') {
- if ($this->request->getMethod() === 'MOVE') {
- $mimeType = $this->mimeTypeDetector->detectPath($this->path);
- } else {
- $path = $this->request->getPathInfo();
- $mimeType = $this->mimeTypeDetector->detectPath($path);
- }
- return $this->cacheAndReturnMimeType($this->storage->getId(), $this->path, $mimeType);
- }
- } else if ($this->isPublicWebDAVRequest()) {
- if ($this->request->getMethod() === 'PUT') {
- $path = $this->request->getPathInfo();
- if (strpos($path, '/webdav/') === 0) {
- $path = substr($path, strlen('/webdav'));
- }
- $path = $this->path . $path;
- $mimeType = $this->mimeTypeDetector->detectPath($path);
- return $this->cacheAndReturnMimeType($this->storage->getId(), $path, $mimeType);
- }
+ if ($this->storage->file_exists($this->path)) {
+ $path = $this->storage->getLocalFile($this->path);
+ $mimeType = $this->mimeTypeDetector->detectContent($path);
+ return $this->cacheAndReturnMimeType($this->storage->getId(), $this->path, $mimeType);
}
- if (in_array($this->request->getMethod(), ['POST', 'PUT'])) {
- $files = $this->request->getUploadedFile('files');
- if (isset($files['type'][0])) {
- $mimeType = $files['type'][0];
- if ($mimeType === 'application/octet-stream') {
- // Maybe not...
- $mimeTypeTest = $this->mimeTypeDetector->detectPath($files['name'][0]);
- if ($mimeTypeTest !== 'application/octet-stream' && $mimeTypeTest !== false) {
- $mimeType = $mimeTypeTest;
- } else {
- $mimeTypeTest = $this->mimeTypeDetector->detect($files['tmp_name'][0]);
- if ($mimeTypeTest !== 'application/octet-stream' && $mimeTypeTest !== false) {
- $mimeType = $mimeTypeTest;
- }
- }
- }
- return $this->cacheAndReturnMimeType($this->storage->getId(), $this->path, $mimeType);
+ if ($this->isWebDAVRequest() || $this->isPublicWebDAVRequest()) {
+ // Creating a folder
+ if ($this->request->getMethod() === 'MKCOL') {
+ return 'httpd/unix-directory';
}
}
- $mimeType = $this->storage->getMimeType($this->path);
- if ($mimeType === 'application/octet-stream') {
- $mimeType = $this->detectMimetypeFromPath();
- }
-
- return $this->cacheAndReturnMimeType($this->storage->getId(), $this->path, $mimeType);
- }
-
- /**
- * @return string
- */
- protected function detectMimetypeFromPath() {
- $mimeType = $this->mimeTypeDetector->detectPath($this->path);
- if ($mimeType !== 'application/octet-stream' && $mimeType !== false) {
- return $mimeType;
- }
-
- if ($this->storage->instanceOfStorage('\OC\Files\Storage\Local')
- || $this->storage->instanceOfStorage('\OC\Files\Storage\Home')
- || $this->storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage')) {
- $localFile = $this->storage->getLocalFile($this->path);
- if ($localFile !== false) {
- $mimeType = $this->mimeTypeDetector->detect($localFile);
- if ($mimeType !== false) {
- return $mimeType;
- }
- }
-
- return 'application/octet-stream';
- } else {
- $handle = $this->storage->fopen($this->path, 'r');
- $data = fread($handle, 8024);
- fclose($handle);
- $mimeType = $this->mimeTypeDetector->detectString($data);
- if ($mimeType !== false) {
- return $mimeType;
- }
-
- return 'application/octet-stream';
- }
+ // We do not cache this, as the file did not exist yet.
+ // In case it does in the future, we will check with detectContent()
+ // again to get the real mimetype of the content, rather than
+ // guessing it from the path.
+ return $this->mimeTypeDetector->detectPath($this->path);
}
/**
diff --git a/apps/workflowengine/lib/Check/FileName.php b/apps/workflowengine/lib/Check/FileName.php
index f775227f71c..4cb402f73d9 100644
--- a/apps/workflowengine/lib/Check/FileName.php
+++ b/apps/workflowengine/lib/Check/FileName.php
@@ -49,8 +49,9 @@ class FileName extends AbstractStringCheck {
/**
* @param IStorage $storage
* @param string $path
+ * @param bool $isDir
*/
- public function setFileInfo(IStorage $storage, $path) {
+ public function setFileInfo(IStorage $storage, $path, $isDir = false) {
$this->storage = $storage;
$this->path = $path;
}
diff --git a/apps/workflowengine/lib/Check/FileSize.php b/apps/workflowengine/lib/Check/FileSize.php
index 7e48f0f6038..76470c73f61 100644
--- a/apps/workflowengine/lib/Check/FileSize.php
+++ b/apps/workflowengine/lib/Check/FileSize.php
@@ -51,8 +51,9 @@ class FileSize implements ICheck {
/**
* @param IStorage $storage
* @param string $path
+ * @param bool $isDir
*/
- public function setFileInfo(IStorage $storage, $path) {
+ public function setFileInfo(IStorage $storage, $path, $isDir = false) {
}
/**
diff --git a/apps/workflowengine/lib/Check/FileSystemTags.php b/apps/workflowengine/lib/Check/FileSystemTags.php
index 4a2b87fd53e..1def0d65aad 100644
--- a/apps/workflowengine/lib/Check/FileSystemTags.php
+++ b/apps/workflowengine/lib/Check/FileSystemTags.php
@@ -68,8 +68,9 @@ class FileSystemTags implements ICheck {
/**
* @param IStorage $storage
* @param string $path
+ * @param bool $isDir
*/
- public function setFileInfo(IStorage $storage, $path) {
+ public function setFileInfo(IStorage $storage, $path, $isDir = false) {
$this->storage = $storage;
$this->path = $path;
}
diff --git a/apps/workflowengine/lib/Check/RequestRemoteAddress.php b/apps/workflowengine/lib/Check/RequestRemoteAddress.php
index 6fa4cfc8800..11b0c6d234d 100644
--- a/apps/workflowengine/lib/Check/RequestRemoteAddress.php
+++ b/apps/workflowengine/lib/Check/RequestRemoteAddress.php
@@ -47,8 +47,9 @@ class RequestRemoteAddress implements ICheck {
/**
* @param IStorage $storage
* @param string $path
+ * @param bool $isDir
*/
- public function setFileInfo(IStorage $storage, $path) {
+ public function setFileInfo(IStorage $storage, $path, $isDir = false) {
// A different path doesn't change time, so nothing to do here.
}
diff --git a/apps/workflowengine/lib/Check/RequestTime.php b/apps/workflowengine/lib/Check/RequestTime.php
index 2aa79e77673..d596b4d52d5 100644
--- a/apps/workflowengine/lib/Check/RequestTime.php
+++ b/apps/workflowengine/lib/Check/RequestTime.php
@@ -52,8 +52,9 @@ class RequestTime implements ICheck {
/**
* @param IStorage $storage
* @param string $path
+ * @param bool $isDir
*/
- public function setFileInfo(IStorage $storage, $path) {
+ public function setFileInfo(IStorage $storage, $path, $isDir = false) {
// A different path doesn't change time, so nothing to do here.
}
diff --git a/apps/workflowengine/lib/Check/UserGroupMembership.php b/apps/workflowengine/lib/Check/UserGroupMembership.php
index fd6ba00d092..32f4a2c9f64 100644
--- a/apps/workflowengine/lib/Check/UserGroupMembership.php
+++ b/apps/workflowengine/lib/Check/UserGroupMembership.php
@@ -60,8 +60,9 @@ class UserGroupMembership implements ICheck {
/**
* @param IStorage $storage
* @param string $path
+ * @param bool $isDir
*/
- public function setFileInfo(IStorage $storage, $path) {
+ public function setFileInfo(IStorage $storage, $path, $isDir = false) {
// A different path doesn't change group memberships, so nothing to do here.
}