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
path: root/apps
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2013-11-15 19:53:23 +0400
committerVincent Petry <pvince81@owncloud.com>2013-11-15 19:53:23 +0400
commit6355af162cf1c68aaf00eaf1d19b8b5fba7e84a0 (patch)
tree2f63bb63a507a7a9f82c72e7ba21d5f382f5cd67 /apps
parentfa44c699f717e115638884b442874168badda5f7 (diff)
parentf36ee69855384f0a42e745efad337a2155909f9a (diff)
Merge pull request #5880 from owncloud/replace_etmp_files
write encryption tmp files to the cache folder
Diffstat (limited to 'apps')
-rwxr-xr-xapps/files_encryption/lib/helper.php51
-rw-r--r--apps/files_encryption/lib/proxy.php12
-rw-r--r--apps/files_encryption/lib/stream.php2
-rw-r--r--apps/files_encryption/tests/helper.php15
4 files changed, 64 insertions, 16 deletions
diff --git a/apps/files_encryption/lib/helper.php b/apps/files_encryption/lib/helper.php
index 314ac577b2f..0ac6fcf403a 100755
--- a/apps/files_encryption/lib/helper.php
+++ b/apps/files_encryption/lib/helper.php
@@ -165,7 +165,7 @@ class Helper {
public static function isPartialFilePath($path) {
$extension = pathinfo($path, PATHINFO_EXTENSION);
- if ( $extension === 'part' || $extension === 'etmp') {
+ if ( $extension === 'part') {
return true;
} else {
return false;
@@ -183,7 +183,7 @@ class Helper {
public static function stripPartialFileExtension($path) {
$extension = pathinfo($path, PATHINFO_EXTENSION);
- if ( $extension === 'part' || $extension === 'etmp') {
+ if ( $extension === 'part') {
$newLength = strlen($path) - 5; // 5 = strlen(".part") = strlen(".etmp")
$fPath = substr($path, 0, $newLength);
@@ -256,24 +256,53 @@ class Helper {
}
/**
- * @brief get path to the correspondig file in data/user/files
+ * @brief get path to the correspondig file in data/user/files if path points
+ * to a version or to a file in cache
* @param string $path path to a version or a file in the trash
* @return string path to correspondig file relative to data/user/files
*/
public static function getPathToRealFile($path) {
$trimmed = ltrim($path, '/');
$split = explode('/', $trimmed);
-
- if (count($split) < 3 || $split[1] !== "files_versions") {
- return false;
+ $result = false;
+
+ if (count($split) >= 3 && ($split[1] === "files_versions" || $split[1] === 'cache')) {
+ $sliced = array_slice($split, 2);
+ $result = implode('/', $sliced);
+ if ($split[1] === "files_versions") {
+ // we skip user/files
+ $sliced = array_slice($split, 2);
+ $relPath = implode('/', $sliced);
+ //remove the last .v
+ $result = substr($relPath, 0, strrpos($relPath, '.v'));
+ }
+ if ($split[1] === "cache") {
+ // we skip /user/cache/transactionId
+ $sliced = array_slice($split, 3);
+ $result = implode('/', $sliced);
+ //prepare the folders
+ self::mkdirr($path, new \OC\Files\View('/'));
+ }
}
- $sliced = array_slice($split, 2);
- $realPath = implode('/', $sliced);
- //remove the last .v
- $realPath = substr($realPath, 0, strrpos($realPath, '.v'));
+ return $result;
+ }
- return $realPath;
+ /**
+ * @brief create directory recursively
+ * @param string $path
+ * @param \OC\Files\View $view
+ */
+ public static function mkdirr($path, $view) {
+ $dirname = \OC_Filesystem::normalizePath(dirname($path));
+ $dirParts = explode('/', $dirname);
+ $dir = "";
+ foreach ($dirParts as $part) {
+ $dir = $dir . '/' . $part;
+ if (!$view->file_exists($dir)) {
+ $view->mkdir($dir);
+ }
+ }
}
/**
diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php
index e2bc8f6b163..54c3b9caa15 100644
--- a/apps/files_encryption/lib/proxy.php
+++ b/apps/files_encryption/lib/proxy.php
@@ -90,7 +90,13 @@ class Proxy extends \OC_FileProxy {
return true;
}
- $handle = fopen('crypt://' . $path . '.etmp', 'w');
+ // create random cache folder
+ $cacheFolder = rand();
+ $path_slices = explode('/', \OC_Filesystem::normalizePath($path));
+ $path_slices[2] = "cache/".$cacheFolder;
+ $tmpPath = implode('/', $path_slices);
+
+ $handle = fopen('crypt://' . $tmpPath, 'w');
if (is_resource($handle)) {
// write data to stream
@@ -104,10 +110,10 @@ class Proxy extends \OC_FileProxy {
\OC_FileProxy::$enabled = false;
// get encrypted content
- $data = $view->file_get_contents($path . '.etmp');
+ $data = $view->file_get_contents($tmpPath);
// remove our temp file
- $view->unlink($path . '.etmp');
+ $view->deleteAll('/' . \OCP\User::getUser() . '/cache/' . $cacheFolder);
// re-enable proxy - our work is done
\OC_FileProxy::$enabled = $proxyStatus;
diff --git a/apps/files_encryption/lib/stream.php b/apps/files_encryption/lib/stream.php
index 5ce5caf80ce..8c81bb82bef 100644
--- a/apps/files_encryption/lib/stream.php
+++ b/apps/files_encryption/lib/stream.php
@@ -108,7 +108,7 @@ class Stream {
}
if($this->relPath === false) {
- \OCP\Util::writeLog('Encryption library', 'failed to open file "' . $this->rawPath . '" expecting a path to user/files or to user/files_versions', \OCP\Util::ERROR);
+ \OCP\Util::writeLog('Encryption library', 'failed to open file "' . $this->rawPath . '" expecting a path to "files", "files_versions" or "cache"', \OCP\Util::ERROR);
return false;
}
diff --git a/apps/files_encryption/tests/helper.php b/apps/files_encryption/tests/helper.php
index 067fc763a95..cd2be70a8fe 100644
--- a/apps/files_encryption/tests/helper.php
+++ b/apps/files_encryption/tests/helper.php
@@ -51,4 +51,17 @@ class Test_Encryption_Helper extends \PHPUnit_Framework_TestCase {
$this->assertEquals('testfile.txt', Encryption\Helper::stripPartialFileExtension($filename));
}
-} \ No newline at end of file
+ function testGetPathToRealFile() {
+
+ // the relative path to /user/files/ that's what we want to get from getPathToRealFile()
+ $relativePath = "foo/bar/test.txt";
+
+ // test paths
+ $versionPath = "/user/files_versions/foo/bar/test.txt.v456756835";
+ $cachePath = "/user/cache/transferid636483/foo/bar/test.txt";
+
+ $this->assertEquals($relativePath, Encryption\Helper::getPathToRealFile($versionPath));
+ $this->assertEquals($relativePath, Encryption\Helper::getPathToRealFile($cachePath));
+ }
+
+}