From: David A. Velasco Date: Fri, 18 Oct 2013 10:28:09 +0000 (+0200) Subject: Merge branch 'develop' into refresh_folder_contents_when_browsed_into X-Git-Tag: oc-android-1.5.5~155^2~12 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/7c9d9e7b3a56229f97cf1bf193f61d4aedd09806?ds=inline;hp=--cc Merge branch 'develop' into refresh_folder_contents_when_browsed_into --- 7c9d9e7b3a56229f97cf1bf193f61d4aedd09806 diff --cc src/com/owncloud/android/operations/SynchronizeFolderOperation.java index 2c8cfe4b,f4065477..91047cee --- a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java +++ b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java @@@ -28,7 -28,9 +28,8 @@@ import java.util.List import java.util.Map; import java.util.Vector; -import org.apache.commons.httpclient.Header; import org.apache.http.HttpStatus; + import org.apache.jackrabbit.webdav.DavConstants; import org.apache.jackrabbit.webdav.MultiStatus; import org.apache.jackrabbit.webdav.client.methods.PropFindMethod; @@@ -160,27 -129,111 +161,29 @@@ public class SynchronizeFolderOperatio mFailsInFavouritesFound = 0; mConflictsFound = 0; mForgottenLocalFiles.clear(); - - // code before in FileSyncAdapter.fetchData + String remotePath = null; PropFindMethod query = null; try { - Log_OC.d(TAG, "Synchronizing " + mAccount.name + ", fetching files in " + mRemotePath); - + remotePath = mLocalFolder.getRemotePath(); + Log_OC.d(TAG, "Synchronizing " + mAccount.name + remotePath); + // remote request - query = new PropFindMethod(client.getBaseUri() + WebdavUtils.encodePath(remotePath)); - query = new PropFindMethod(client.getBaseUri() + WebdavUtils.encodePath(mRemotePath), ++ query = new PropFindMethod(client.getBaseUri() + WebdavUtils.encodePath(remotePath), + DavConstants.PROPFIND_ALL_PROP, + DavConstants.DEPTH_1); int status = client.executeMethod(query); - - // check and process response - /// TODO take into account all the possible status per child-resource - if (isMultiStatus(status)) { - MultiStatus resp = query.getResponseBodyAsMultiStatus(); - - // synchronize properties of the parent folder, if necessary - if (mParentId == DataStorageManager.ROOT_PARENT_ID) { - WebdavEntry we = new WebdavEntry(resp.getResponses()[0], client.getBaseUri().getPath()); - OCFile parent = fillOCFile(we); - mStorageManager.saveFile(parent); - mParentId = parent.getFileId(); - } - - // read contents in folder - List updatedFiles = new Vector(resp.getResponses().length - 1); - List filesToSyncContents = new Vector(); - for (int i = 1; i < resp.getResponses().length; ++i) { - /// new OCFile instance with the data from the server - WebdavEntry we = new WebdavEntry(resp.getResponses()[i], client.getBaseUri().getPath()); - OCFile file = fillOCFile(we); - - /// set data about local state, keeping unchanged former data if existing - file.setLastSyncDateForProperties(mCurrentSyncTime); - OCFile oldFile = mStorageManager.getFileByPath(file.getRemotePath()); - if (oldFile != null) { - file.setKeepInSync(oldFile.keepInSync()); - file.setLastSyncDateForData(oldFile.getLastSyncDateForData()); - file.setModificationTimestampAtLastSyncForData(oldFile.getModificationTimestampAtLastSyncForData()); // must be kept unchanged when the file contents are not updated - checkAndFixForeignStoragePath(oldFile); - file.setStoragePath(oldFile.getStoragePath()); - } - /// scan default location if local copy of file is not linked in OCFile instance - if (file.getStoragePath() == null && !file.isDirectory()) { - File f = new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, file)); - if (f.exists()) { - file.setStoragePath(f.getAbsolutePath()); - file.setLastSyncDateForData(f.lastModified()); - } - } - - /// prepare content synchronization for kept-in-sync files - if (file.keepInSync()) { - SynchronizeFileOperation operation = new SynchronizeFileOperation( oldFile, - file, - mStorageManager, - mAccount, - true, - false, - mContext - ); - filesToSyncContents.add(operation); - } - - updatedFiles.add(file); - } - - // save updated contents in local database; all at once, trying to get a best performance in database update (not a big deal, indeed) - mStorageManager.saveFiles(updatedFiles); - - // request for the synchronization of files AFTER saving last properties - SynchronizeFileOperation op = null; - RemoteOperationResult contentsResult = null; - for (int i=0; i < filesToSyncContents.size(); i++) { - op = filesToSyncContents.get(i); - contentsResult = op.execute(client); // returns without waiting for upload or download finishes - if (!contentsResult.isSuccess()) { - if (contentsResult.getCode() == ResultCode.SYNC_CONFLICT) { - mConflictsFound++; - } else { - mFailsInFavouritesFound++; - if (contentsResult.getException() != null) { - Log_OC.e(TAG, "Error while synchronizing favourites : " + contentsResult.getLogMessage(), contentsResult.getException()); - } else { - Log_OC.e(TAG, "Error while synchronizing favourites : " + contentsResult.getLogMessage()); - } - } - } // won't let these fails break the synchronization process - } - - - // removal of obsolete files - mChildren = mStorageManager.getDirectoryContent(mStorageManager.getFileById(mParentId)); - OCFile file; - String currentSavePath = FileStorageUtils.getSavePath(mAccount.name); - for (int i=0; i < mChildren.size(); ) { - file = mChildren.get(i); - if (file.getLastSyncDateForProperties() != mCurrentSyncTime) { - Log_OC.d(TAG, "removing file: " + file); - mStorageManager.removeFile(file, (file.isDown() && file.getStoragePath().startsWith(currentSavePath))); - mChildren.remove(i); + // check and process response + if (isMultiStatus(status)) { + boolean folderChanged = synchronizeData(query.getResponseBodyAsMultiStatus(), client); + if (folderChanged) { + if (mConflictsFound > 0 || mFailsInFavouritesFound > 0) { + result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT); // should be different result, but will do the job } else { - i++; + result = new RemoteOperationResult(true, status, query.getResponseHeaders()); } + } else { + result = new RemoteOperationResult(ResultCode.OK_NO_CHANGES_ON_DIR); } } else {