Merge pull request #1962 from nextcloud/topOfEncryption

Detect top of encryption folders
This commit is contained in:
Tobias Kaminsky 2018-01-15 11:03:45 +01:00 committed by GitHub
commit 375d66761a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 4 deletions

View file

@ -371,7 +371,7 @@ public class RefreshFolderOperation extends RemoteOperation {
// if local folder is encrypted, download fresh metadata
DecryptedFolderMetadata metadata;
boolean encryptedAncestor = FileStorageUtils.checkIfInEncryptedFolder(mLocalFolder, mStorageManager);
boolean encryptedAncestor = FileStorageUtils.checkEncryptionStatus(mLocalFolder, mStorageManager);
if (encryptedAncestor && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
metadata = EncryptionUtils.downloadFolderMetadata(mLocalFolder, getClient(), mContext, mAccount);
} else {
@ -470,7 +470,8 @@ public class RefreshFolderOperation extends RemoteOperation {
}
}
updatedFile.setEncrypted(encryptedAncestor);
boolean encrypted = FileStorageUtils.checkEncryptionStatus(updatedFile, mStorageManager);
updatedFile.setEncrypted(encrypted);
updatedFiles.add(updatedFile);
}

View file

@ -381,7 +381,7 @@ public class UploadFileOperation extends SyncOperation {
mFile.setParentId(parent.getFileId());
// check if any parent is encrypted
encryptedAncestor = FileStorageUtils.checkIfInEncryptedFolder(parent, getStorageManager());
encryptedAncestor = FileStorageUtils.checkEncryptionStatus(parent, getStorageManager());
mFile.setEncrypted(encryptedAncestor);
// try to unlock folder with stored token, e.g. when upload needs to be resumed or app crashed

View file

@ -383,7 +383,18 @@ public class FileStorageUtils {
return true;
}
public static boolean checkIfInEncryptedFolder(OCFile file, FileDataStorageManager storageManager) {
/**
* Checks and returns true if file itself or ancestor is encrypted
*
* @param file file to check
* @param storageManager up to date reference to storage manager
* @return true if file itself or ancestor is encrypted
*/
public static boolean checkEncryptionStatus(OCFile file, FileDataStorageManager storageManager) {
if (file.isEncrypted()) {
return true;
}
while (!OCFile.ROOT_PATH.equals(file.getRemotePath())) {
if (file.isEncrypted()) {
return true;