$filePath = $directory . '/' . $this->view->getRelativePath('/' . $file);
$relPath = \OCA\Encryption\Helper::stripUserFilesPath($filePath);
- // If the path is a directory, search
+ // If the path is a directory, search
// its contents
if ($this->view->is_dir($filePath)) {
$isEncryptedPath = $this->isEncryptedPath($filePath);
// If the file is encrypted
- // NOTE: If the userId is
- // empty or not set, file will
+ // NOTE: If the userId is
+ // empty or not set, file will
// detected as plain
// NOTE: This is inefficient;
// scanning every file like this
return $successful;
}
-
+
/**
* @brief Decrypt all files
* @return bool
$versionStatus = \OCP\App::isEnabled('files_versions');
\OC_App::disable('files_versions');
-
+
$decryptedFiles = array();
// Encrypt unencrypted files
foreach ($found['encrypted'] as $encryptedFile) {
+ //get file info
+ $fileInfo = \OC\Files\Filesystem::getFileInfo($encryptedFile['path']);
+
//relative to data/<user>/file
$relPath = Helper::stripUserFilesPath($encryptedFile['path']);
//relative to /data
$rawPath = $encryptedFile['path'];
-
+
//get timestamp
$timestamp = $this->view->filemtime($rawPath);
-
+
//enable proxy to use OC\Files\View to access the original file
\OC_FileProxy::$enabled = true;
//set timestamp
$this->view->touch($rawPath, $timestamp);
-
+
// Add the file to the cache
\OC\Files\Filesystem::putFileInfo($relPath, array(
'encrypted' => false,
'size' => $size,
- 'unencrypted_size' => $size
+ 'unencrypted_size' => $size,
+ 'etag' => $fileInfo['etag']
));
-
+
$decryptedFiles[] = $relPath;
}
if ($versionStatus) {
\OC_App::enable('files_versions');
}
-
+
if (!$this->decryptVersions($decryptedFiles)) {
$successful = false;
}
-
+
if ($successful) {
$this->view->deleteAll($this->keyfilesPath);
$this->view->deleteAll($this->shareKeysPath);
// Disable proxy to prevent file being encrypted twice
\OC_FileProxy::$enabled = false;
-
+
$versionStatus = \OCP\App::isEnabled('files_versions');
\OC_App::disable('files_versions');
-
+
$encryptedFiles = array();
// Encrypt unencrypted files
foreach ($found['plain'] as $plainFile) {
+ //get file info
+ $fileInfo = \OC\Files\Filesystem::getFileInfo($plainFile['path']);
+
//relative to data/<user>/file
$relPath = $plainFile['path'];
-
+
//relative to /data
$rawPath = '/' . $this->userId . '/files/' . $plainFile['path'];
// keep timestamp
$timestamp = $this->view->filemtime($rawPath);
-
+
// Open plain file handle for binary reading
$plainHandle = $this->view->fopen($rawPath, 'rb');
$this->view->rename($relPath . '.part', $relPath);
$this->view->chroot($fakeRoot);
-
+
// set timestamp
$this->view->touch($rawPath, $timestamp);
\OC\Files\Filesystem::putFileInfo($relPath, array(
'encrypted' => true,
'size' => $size,
- 'unencrypted_size' => $size
+ 'unencrypted_size' => $size,
+ 'etag' => $fileInfo['etag']
));
-
+
$encryptedFiles[] = $relPath;
}
if ($versionStatus) {
\OC_App::enable('files_versions');
}
-
+
$this->encryptVersions($encryptedFiles);
-
+
// If files were found, return true
return true;
} else {
}
- // If recovery is enabled, add the
+ // If recovery is enabled, add the
// Admin UID to list of users to share to
if ($recoveryEnabled) {
// Find recoveryAdmin user ID
$session = new \OCA\Encryption\Session($this->view);
$session->setPrivateKey($privateKey);
-
+
return $session;
}
-
+
}