Skip to content

Commit

Permalink
enable subfolder
Browse files Browse the repository at this point in the history
check if in subfolder of encrypted folder

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
  • Loading branch information
tobiasKaminsky committed Jan 12, 2018
1 parent 84ff825 commit e335056
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ private void synchronizeData(ArrayList<Object> folderAndFiles) {

// if local folder is encrypted, download fresh metadata
DecryptedFolderMetadata metadata;
if (mLocalFolder.isEncrypted() && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
boolean encryptedAncestor = FileStorageUtils.checkIfInEncryptedFolder(mLocalFolder, mStorageManager);
if (encryptedAncestor && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
metadata = EncryptionUtils.downloadFolderMetadata(mLocalFolder, getClient(), mContext, mAccount);
} else {
metadata = null;
Expand All @@ -383,7 +384,7 @@ private void synchronizeData(ArrayList<Object> folderAndFiles) {
for (OCFile file : localFiles) {
String remotePath = file.getRemotePath();

if (metadata != null) {
if (metadata != null && !file.isFolder()) {
remotePath = file.getParentRemotePath() + file.getEncryptedFileName();
}
localFilesMap.put(remotePath, file);
Expand Down Expand Up @@ -467,9 +468,10 @@ private void synchronizeData(ArrayList<Object> folderAndFiles) {
} catch (NullPointerException e) {
Log_OC.e(TAG, "Metadata for file " + updatedFile.getFileId() + " not found!");
}
updatedFile.setEncrypted(true);
}

updatedFile.setEncrypted(encryptedAncestor);

updatedFiles.add(updatedFile);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ public class UploadFileOperation extends SyncOperation {
private OCUpload mUpload;
private UploadsStorageManager uploadsStorageManager;

private boolean encryptedAncestor;

public static OCFile obtainNewOCFileToUpload(String remotePath, String localPath, String mimeType) {

// MIME type
Expand Down Expand Up @@ -354,8 +356,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {
mCancellationRequested.set(false);
mUploadStarted.set(true);

uploadsStorageManager = new UploadsStorageManager(mContext.getContentResolver(),
mContext);
uploadsStorageManager = new UploadsStorageManager(mContext.getContentResolver(), mContext);

for (OCUpload ocUpload : uploadsStorageManager.getAllStoredUploads()) {
if (ocUpload.getUploadId() == getOCUploadId()) {
Expand All @@ -370,12 +371,21 @@ protected RemoteOperationResult run(OwnCloudClient client) {
remoteParentPath = remoteParentPath.endsWith(OCFile.PATH_SEPARATOR) ?
remoteParentPath : remoteParentPath + OCFile.PATH_SEPARATOR;

RemoteOperationResult result = grantFolderExistence(remoteParentPath, client);

if (!result.isSuccess()) {
return result;
}

OCFile parent = getStorageManager().getFileByPath(remoteParentPath);
mFile.setParentId(parent.getFileId());
mFile.setEncrypted(parent.isEncrypted());

// check if any parent is encrypted
encryptedAncestor = FileStorageUtils.checkIfInEncryptedFolder(parent, getStorageManager());
mFile.setEncrypted(encryptedAncestor);

// try to unlock folder with stored token, e.g. when upload needs to be resumed or app crashed
if (parent.isEncrypted() && !mFolderUnlockToken.isEmpty()) {
if (encryptedAncestor && !mFolderUnlockToken.isEmpty()) {
UnlockFileOperation unlockFileOperation = new UnlockFileOperation(parent.getLocalId(), mFolderUnlockToken);
RemoteOperationResult unlockFileOperationResult = unlockFileOperation.execute(client, true);

Expand All @@ -384,13 +394,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {
}
}

RemoteOperationResult result = grantFolderExistence(remoteParentPath, client);

if (!result.isSuccess()) {
return result;
}

if (parent.isEncrypted()) {
if (encryptedAncestor) {
Log_OC.d(TAG, "encrypted upload");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
return encryptedUpload(client, parent);
Expand Down Expand Up @@ -1332,8 +1336,7 @@ private void saveUploadedFile(OwnCloudClient client) {
// TODO from the appropriate OC server version, get data from last PUT response headers, instead
// TODO of a new PROPFIND; the latter may fail, specially for chunked uploads
String path;
OCFile parent = getStorageManager().getFileByPath(file.getParentRemotePath());
if (parent.isEncrypted()) {
if (encryptedAncestor) {
path = file.getParentRemotePath() + mFile.getEncryptedFileName();
} else {
path = getRemotePath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1180,20 +1180,7 @@ public void run() {
}
mFile = directory;

// hide create new folder within encrypted folders for now
if (mFile.isEncrypted()) {
getFabMkdir().setVisibility(View.GONE);
} else {
getFabMkdir().setVisibility(View.VISIBLE);

if (miniFabClicked) {
((TextView) getFabMkdir().getTag(com.getbase.floatingactionbutton.R.id.fab_label))
.setVisibility(View.GONE);
}
}

updateLayout();

}
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/owncloud/android/utils/FileStorageUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,4 +382,14 @@ public static boolean checkIfFileFinishedSaving(OCFile file) {

return true;
}

public static boolean checkIfInEncryptedFolder(OCFile file, FileDataStorageManager storageManager) {
while (!OCFile.ROOT_PATH.equals(file.getRemotePath())) {
if (file.isEncrypted()) {
return true;
}
file = storageManager.getFileById(file.getParentId());
}
return false;
}
}

0 comments on commit e335056

Please sign in to comment.