don't change the etags if a file gets encrypted/decrypted to avoid that the sync client downloads all files again
This commit is contained in:
parent
cabe92ef12
commit
1be11bb03d
|
@ -340,7 +340,7 @@ class Util {
|
||||||
$filePath = $directory . '/' . $this->view->getRelativePath('/' . $file);
|
$filePath = $directory . '/' . $this->view->getRelativePath('/' . $file);
|
||||||
$relPath = \OCA\Encryption\Helper::stripUserFilesPath($filePath);
|
$relPath = \OCA\Encryption\Helper::stripUserFilesPath($filePath);
|
||||||
|
|
||||||
// If the path is a directory, search
|
// If the path is a directory, search
|
||||||
// its contents
|
// its contents
|
||||||
if ($this->view->is_dir($filePath)) {
|
if ($this->view->is_dir($filePath)) {
|
||||||
|
|
||||||
|
@ -356,8 +356,8 @@ class Util {
|
||||||
|
|
||||||
$isEncryptedPath = $this->isEncryptedPath($filePath);
|
$isEncryptedPath = $this->isEncryptedPath($filePath);
|
||||||
// If the file is encrypted
|
// If the file is encrypted
|
||||||
// NOTE: If the userId is
|
// NOTE: If the userId is
|
||||||
// empty or not set, file will
|
// empty or not set, file will
|
||||||
// detected as plain
|
// detected as plain
|
||||||
// NOTE: This is inefficient;
|
// NOTE: This is inefficient;
|
||||||
// scanning every file like this
|
// scanning every file like this
|
||||||
|
@ -687,7 +687,7 @@ class Util {
|
||||||
|
|
||||||
return $successful;
|
return $successful;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Decrypt all files
|
* @brief Decrypt all files
|
||||||
* @return bool
|
* @return bool
|
||||||
|
@ -702,21 +702,24 @@ class Util {
|
||||||
|
|
||||||
$versionStatus = \OCP\App::isEnabled('files_versions');
|
$versionStatus = \OCP\App::isEnabled('files_versions');
|
||||||
\OC_App::disable('files_versions');
|
\OC_App::disable('files_versions');
|
||||||
|
|
||||||
$decryptedFiles = array();
|
$decryptedFiles = array();
|
||||||
|
|
||||||
// Encrypt unencrypted files
|
// Encrypt unencrypted files
|
||||||
foreach ($found['encrypted'] as $encryptedFile) {
|
foreach ($found['encrypted'] as $encryptedFile) {
|
||||||
|
|
||||||
|
//get file info
|
||||||
|
$fileInfo = \OC\Files\Filesystem::getFileInfo($encryptedFile['path']);
|
||||||
|
|
||||||
//relative to data/<user>/file
|
//relative to data/<user>/file
|
||||||
$relPath = Helper::stripUserFilesPath($encryptedFile['path']);
|
$relPath = Helper::stripUserFilesPath($encryptedFile['path']);
|
||||||
|
|
||||||
//relative to /data
|
//relative to /data
|
||||||
$rawPath = $encryptedFile['path'];
|
$rawPath = $encryptedFile['path'];
|
||||||
|
|
||||||
//get timestamp
|
//get timestamp
|
||||||
$timestamp = $this->view->filemtime($rawPath);
|
$timestamp = $this->view->filemtime($rawPath);
|
||||||
|
|
||||||
//enable proxy to use OC\Files\View to access the original file
|
//enable proxy to use OC\Files\View to access the original file
|
||||||
\OC_FileProxy::$enabled = true;
|
\OC_FileProxy::$enabled = true;
|
||||||
|
|
||||||
|
@ -760,14 +763,15 @@ class Util {
|
||||||
|
|
||||||
//set timestamp
|
//set timestamp
|
||||||
$this->view->touch($rawPath, $timestamp);
|
$this->view->touch($rawPath, $timestamp);
|
||||||
|
|
||||||
// Add the file to the cache
|
// Add the file to the cache
|
||||||
\OC\Files\Filesystem::putFileInfo($relPath, array(
|
\OC\Files\Filesystem::putFileInfo($relPath, array(
|
||||||
'encrypted' => false,
|
'encrypted' => false,
|
||||||
'size' => $size,
|
'size' => $size,
|
||||||
'unencrypted_size' => $size
|
'unencrypted_size' => $size,
|
||||||
|
'etag' => $fileInfo['etag']
|
||||||
));
|
));
|
||||||
|
|
||||||
$decryptedFiles[] = $relPath;
|
$decryptedFiles[] = $relPath;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -775,11 +779,11 @@ class Util {
|
||||||
if ($versionStatus) {
|
if ($versionStatus) {
|
||||||
\OC_App::enable('files_versions');
|
\OC_App::enable('files_versions');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->decryptVersions($decryptedFiles)) {
|
if (!$this->decryptVersions($decryptedFiles)) {
|
||||||
$successful = false;
|
$successful = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($successful) {
|
if ($successful) {
|
||||||
$this->view->deleteAll($this->keyfilesPath);
|
$this->view->deleteAll($this->keyfilesPath);
|
||||||
$this->view->deleteAll($this->shareKeysPath);
|
$this->view->deleteAll($this->shareKeysPath);
|
||||||
|
@ -807,24 +811,27 @@ class Util {
|
||||||
|
|
||||||
// Disable proxy to prevent file being encrypted twice
|
// Disable proxy to prevent file being encrypted twice
|
||||||
\OC_FileProxy::$enabled = false;
|
\OC_FileProxy::$enabled = false;
|
||||||
|
|
||||||
$versionStatus = \OCP\App::isEnabled('files_versions');
|
$versionStatus = \OCP\App::isEnabled('files_versions');
|
||||||
\OC_App::disable('files_versions');
|
\OC_App::disable('files_versions');
|
||||||
|
|
||||||
$encryptedFiles = array();
|
$encryptedFiles = array();
|
||||||
|
|
||||||
// Encrypt unencrypted files
|
// Encrypt unencrypted files
|
||||||
foreach ($found['plain'] as $plainFile) {
|
foreach ($found['plain'] as $plainFile) {
|
||||||
|
|
||||||
|
//get file info
|
||||||
|
$fileInfo = \OC\Files\Filesystem::getFileInfo($plainFile['path']);
|
||||||
|
|
||||||
//relative to data/<user>/file
|
//relative to data/<user>/file
|
||||||
$relPath = $plainFile['path'];
|
$relPath = $plainFile['path'];
|
||||||
|
|
||||||
//relative to /data
|
//relative to /data
|
||||||
$rawPath = '/' . $this->userId . '/files/' . $plainFile['path'];
|
$rawPath = '/' . $this->userId . '/files/' . $plainFile['path'];
|
||||||
|
|
||||||
// keep timestamp
|
// keep timestamp
|
||||||
$timestamp = $this->view->filemtime($rawPath);
|
$timestamp = $this->view->filemtime($rawPath);
|
||||||
|
|
||||||
// Open plain file handle for binary reading
|
// Open plain file handle for binary reading
|
||||||
$plainHandle = $this->view->fopen($rawPath, 'rb');
|
$plainHandle = $this->view->fopen($rawPath, 'rb');
|
||||||
|
|
||||||
|
@ -843,7 +850,7 @@ class Util {
|
||||||
$this->view->rename($relPath . '.part', $relPath);
|
$this->view->rename($relPath . '.part', $relPath);
|
||||||
|
|
||||||
$this->view->chroot($fakeRoot);
|
$this->view->chroot($fakeRoot);
|
||||||
|
|
||||||
// set timestamp
|
// set timestamp
|
||||||
$this->view->touch($rawPath, $timestamp);
|
$this->view->touch($rawPath, $timestamp);
|
||||||
|
|
||||||
|
@ -851,9 +858,10 @@ class Util {
|
||||||
\OC\Files\Filesystem::putFileInfo($relPath, array(
|
\OC\Files\Filesystem::putFileInfo($relPath, array(
|
||||||
'encrypted' => true,
|
'encrypted' => true,
|
||||||
'size' => $size,
|
'size' => $size,
|
||||||
'unencrypted_size' => $size
|
'unencrypted_size' => $size,
|
||||||
|
'etag' => $fileInfo['etag']
|
||||||
));
|
));
|
||||||
|
|
||||||
$encryptedFiles[] = $relPath;
|
$encryptedFiles[] = $relPath;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -899,9 +907,9 @@ class Util {
|
||||||
if ($versionStatus) {
|
if ($versionStatus) {
|
||||||
\OC_App::enable('files_versions');
|
\OC_App::enable('files_versions');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->encryptVersions($encryptedFiles);
|
$this->encryptVersions($encryptedFiles);
|
||||||
|
|
||||||
// If files were found, return true
|
// If files were found, return true
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1140,7 +1148,7 @@ class Util {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If recovery is enabled, add the
|
// If recovery is enabled, add the
|
||||||
// Admin UID to list of users to share to
|
// Admin UID to list of users to share to
|
||||||
if ($recoveryEnabled) {
|
if ($recoveryEnabled) {
|
||||||
// Find recoveryAdmin user ID
|
// Find recoveryAdmin user ID
|
||||||
|
@ -1727,8 +1735,8 @@ class Util {
|
||||||
$session = new \OCA\Encryption\Session($this->view);
|
$session = new \OCA\Encryption\Session($this->view);
|
||||||
|
|
||||||
$session->setPrivateKey($privateKey);
|
$session->setPrivateKey($privateKey);
|
||||||
|
|
||||||
return $session;
|
return $session;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue