|
@@ -26,6 +26,7 @@ import android.text.TextUtils;
|
|
|
import android.util.Log;
|
|
|
|
|
|
import com.nextcloud.client.account.User;
|
|
|
+import com.owncloud.android.datamodel.DecryptedFolderMetadata;
|
|
|
import com.owncloud.android.datamodel.FileDataStorageManager;
|
|
|
import com.owncloud.android.datamodel.OCFile;
|
|
|
import com.owncloud.android.files.services.FileDownloader;
|
|
@@ -44,7 +45,6 @@ import com.owncloud.android.utils.MimeTypeUtil;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Vector;
|
|
@@ -246,13 +246,14 @@ public class SynchronizeFolderOperation extends SyncOperation {
|
|
|
* @param folderAndFiles Remote folder and children files in Folder
|
|
|
*/
|
|
|
private void synchronizeData(List<Object> folderAndFiles) throws OperationCancelledException {
|
|
|
+
|
|
|
+
|
|
|
// parse data from remote folder
|
|
|
OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) folderAndFiles.get(0));
|
|
|
remoteFolder.setParentId(mLocalFolder.getParentId());
|
|
|
remoteFolder.setFileId(mLocalFolder.getFileId());
|
|
|
|
|
|
- Log_OC.d(TAG, "Remote folder " + mLocalFolder.getRemotePath()
|
|
|
- + " changed - starting update of local data ");
|
|
|
+ Log_OC.d(TAG, "Remote folder " + mLocalFolder.getRemotePath() + " changed - starting update of local data ");
|
|
|
|
|
|
mFilesForDirectDownload.clear();
|
|
|
mFilesToSyncContents.clear();
|
|
@@ -262,38 +263,66 @@ public class SynchronizeFolderOperation extends SyncOperation {
|
|
|
}
|
|
|
|
|
|
FileDataStorageManager storageManager = getStorageManager();
|
|
|
- List<OCFile> updatedFiles = new ArrayList<>(folderAndFiles.size() - 1);
|
|
|
+
|
|
|
+ // if local folder is encrypted, download fresh metadata
|
|
|
+ boolean encryptedAncestor = FileStorageUtils.checkEncryptionStatus(remoteFolder, storageManager);
|
|
|
+ mLocalFolder.setEncrypted(encryptedAncestor);
|
|
|
+
|
|
|
+ // update permission
|
|
|
+ mLocalFolder.setPermissions(remoteFolder.getPermissions());
|
|
|
+
|
|
|
+ // update richWorkspace
|
|
|
+ mLocalFolder.setRichWorkspace(remoteFolder.getRichWorkspace());
|
|
|
+
|
|
|
+ DecryptedFolderMetadata metadata = RefreshFolderOperation.getDecryptedFolderMetadata(encryptedAncestor,
|
|
|
+ mLocalFolder,
|
|
|
+ getClient(),
|
|
|
+ user.toPlatformAccount(),
|
|
|
+ mContext);
|
|
|
|
|
|
// get current data about local contents of the folder to synchronize
|
|
|
- List<OCFile> localFiles = storageManager.getFolderContent(mLocalFolder, false);
|
|
|
- Map<String, OCFile> localFilesMap = new HashMap<>(localFiles.size());
|
|
|
- for (OCFile file : localFiles) {
|
|
|
- localFilesMap.put(file.getRemotePath(), file);
|
|
|
- }
|
|
|
+ Map<String, OCFile> localFilesMap =
|
|
|
+ RefreshFolderOperation.prefillLocalFilesMap(metadata,
|
|
|
+ storageManager.getFolderContent(mLocalFolder, false));
|
|
|
|
|
|
// loop to synchronize every child
|
|
|
+ List<OCFile> updatedFiles = new ArrayList<>(folderAndFiles.size() - 1);
|
|
|
OCFile remoteFile;
|
|
|
OCFile localFile;
|
|
|
OCFile updatedFile;
|
|
|
- RemoteFile r;
|
|
|
- for (int i=1; i<folderAndFiles.size(); i++) {
|
|
|
+ RemoteFile remote;
|
|
|
+
|
|
|
+ for (int i = 1; i < folderAndFiles.size(); i++) {
|
|
|
/// new OCFile instance with the data from the server
|
|
|
- r = (RemoteFile) folderAndFiles.get(i);
|
|
|
- remoteFile = FileStorageUtils.fillOCFile(r);
|
|
|
+ remote = (RemoteFile) folderAndFiles.get(i);
|
|
|
+ remoteFile = FileStorageUtils.fillOCFile(remote);
|
|
|
+
|
|
|
+ /// new OCFile instance to merge fresh data from server with local state
|
|
|
+ updatedFile = FileStorageUtils.fillOCFile(remote);
|
|
|
+ updatedFile.setParentId(mLocalFolder.getFileId());
|
|
|
|
|
|
/// retrieve local data for the read file
|
|
|
- // localFile = mStorageManager.getFileByPath(remoteFile.getRemotePath());
|
|
|
localFile = localFilesMap.remove(remoteFile.getRemotePath());
|
|
|
|
|
|
- /// new OCFile instance to merge fresh data from server with local state
|
|
|
- updatedFile = FileStorageUtils.fillOCFile(r);
|
|
|
- updatedFile.setParentId(mLocalFolder.getFileId());
|
|
|
+ // TODO better implementation is needed
|
|
|
+ if (localFile == null) {
|
|
|
+ localFile = storageManager.getFileByPath(updatedFile.getRemotePath());
|
|
|
+ }
|
|
|
|
|
|
/// add to updatedFile data about LOCAL STATE (not existing in server)
|
|
|
updateLocalStateData(remoteFile, localFile, updatedFile);
|
|
|
|
|
|
/// check and fix, if needed, local storage path
|
|
|
- searchForLocalFileInDefaultPath(updatedFile);
|
|
|
+ FileStorageUtils.searchForLocalFileInDefaultPath(updatedFile, user.toPlatformAccount());
|
|
|
+
|
|
|
+ // update file name for encrypted files
|
|
|
+ if (metadata != null) {
|
|
|
+ RefreshFolderOperation.updateFileNameForEncryptedFile(storageManager, metadata, updatedFile);
|
|
|
+ }
|
|
|
+
|
|
|
+ // we parse content, so either the folder itself or its direct parent (which we check) must be encrypted
|
|
|
+ boolean encrypted = updatedFile.isEncrypted() || mLocalFolder.isEncrypted();
|
|
|
+ updatedFile.setEncrypted(encrypted);
|
|
|
|
|
|
/// classify file to sync/download contents later
|
|
|
classifyFileForLaterSyncOrDownload(remoteFile, localFile);
|
|
@@ -301,8 +330,14 @@ public class SynchronizeFolderOperation extends SyncOperation {
|
|
|
updatedFiles.add(updatedFile);
|
|
|
}
|
|
|
|
|
|
+ if (metadata != null) {
|
|
|
+ RefreshFolderOperation.updateFileNameForEncryptedFile(storageManager, metadata, mLocalFolder);
|
|
|
+ }
|
|
|
+
|
|
|
// save updated contents in local database
|
|
|
storageManager.saveFolder(remoteFolder, updatedFiles, localFilesMap.values());
|
|
|
+ mLocalFolder.setLastSyncDateForData(System.currentTimeMillis());
|
|
|
+ storageManager.saveFile(mLocalFolder);
|
|
|
}
|
|
|
|
|
|
private void updateLocalStateData(OCFile remoteFile, OCFile localFile, OCFile updatedFile) {
|