summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorBjörn Schießle <schiessle@owncloud.com>2014-02-28 09:57:58 +0100
committerBjörn Schießle <schiessle@owncloud.com>2014-02-28 09:57:58 +0100
commit61bc76fdd6fea722d8f77dd48ae66c294a1fe322 (patch)
treefafa7fb07fada664d60fff33fac7df9b8ce27f90 /apps
parentfefd7248585e2831adfb1ae9d40c49e94529e36d (diff)
parent4ace1a273d705a21736f92ba3a38f08d8465bca0 (diff)
downloadnextcloud-server-61bc76fdd6fea722d8f77dd48ae66c294a1fe322.tar.gz
nextcloud-server-61bc76fdd6fea722d8f77dd48ae66c294a1fe322.zip
Merge pull request #7454 from owncloud/enc_remember_fopen_mode
[enc] remember original fopen access type in pre-proxy
Diffstat (limited to 'apps')
-rw-r--r--apps/files_encryption/lib/proxy.php32
-rw-r--r--apps/files_encryption/lib/stream.php3
2 files changed, 29 insertions, 6 deletions
diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php
index 6b1e4b7745b..a2d42c22c13 100644
--- a/apps/files_encryption/lib/proxy.php
+++ b/apps/files_encryption/lib/proxy.php
@@ -38,6 +38,7 @@ class Proxy extends \OC_FileProxy {
private static $blackList = null; //mimetypes blacklisted from encryption
private static $unencryptedSizes = array(); // remember unencrypted size
+ private static $fopenMode = array(); // remember the fopen mode
/**
* Check if a file requires encryption
@@ -214,6 +215,16 @@ class Proxy extends \OC_FileProxy {
}
/**
+ * @brief remember initial fopen mode because sometimes it gets changed during the request
+ * @param string $path path
+ * @param string $mode type of access
+ */
+ public function preFopen($path, $mode) {
+ self::$fopenMode[$path] = $mode;
+ }
+
+
+ /**
* @param $path
* @param $result
* @return resource
@@ -240,7 +251,15 @@ class Proxy extends \OC_FileProxy {
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
- $meta = stream_get_meta_data($result);
+ // if we remember the mode from the pre proxy we re-use it
+ // oterwise we fall back to stream_get_meta_data()
+ if (isset(self::$fopenMode[$path])) {
+ $mode = self::$fopenMode[$path];
+ unset(self::$fopenMode[$path]);
+ } else {
+ $meta = stream_get_meta_data($result);
+ $mode = $meta['mode'];
+ }
$view = new \OC_FilesystemView('');
@@ -258,14 +277,15 @@ class Proxy extends \OC_FileProxy {
// Open the file using the crypto stream wrapper
// protocol and let it do the decryption work instead
- $result = fopen('crypt://' . $path, $meta['mode']);
+ $result = fopen('crypt://' . $path, $mode);
} elseif (
- self::shouldEncrypt($path)
- and $meta['mode'] !== 'r'
- and $meta['mode'] !== 'rb'
+ self::shouldEncrypt($path)
+ and $mode !== 'r'
+ and $mode !== 'rb'
+
) {
- $result = fopen('crypt://' . $path, $meta['mode']);
+ $result = fopen('crypt://' . $path, $mode);
}
// Re-enable the proxy
diff --git a/apps/files_encryption/lib/stream.php b/apps/files_encryption/lib/stream.php
index 88eacc6f136..58ac03373a7 100644
--- a/apps/files_encryption/lib/stream.php
+++ b/apps/files_encryption/lib/stream.php
@@ -167,6 +167,9 @@ class Stream {
} else {
$this->meta = stream_get_meta_data($this->handle);
+ // sometimes fopen changes the mode, e.g. for a url "r" convert to "r+"
+ // but we need to remember the original access type
+ $this->meta['mode'] = $mode;
}