X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/dc06df15c8c9b54b845f06cb4253a1b8af7d8f75..0723ae4b096db5cf75a4a94e0900c4110e54a5b6:/src/com/owncloud/android/operations/SynchronizeFolderOperation.java diff --git a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java index 2fc9d28b..ff387c0f 100644 --- a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java +++ b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java @@ -30,9 +30,6 @@ import java.util.Map; import java.util.Vector; import org.apache.http.HttpStatus; -import org.apache.jackrabbit.webdav.DavConstants; -import org.apache.jackrabbit.webdav.client.methods.PropFindMethod; - import android.accounts.Account; import android.content.Context; import android.content.Intent; @@ -40,11 +37,10 @@ import android.content.Intent; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.oc_framework.network.webdav.WebdavClient; -import com.owncloud.android.oc_framework.network.webdav.WebdavEntry; -import com.owncloud.android.oc_framework.network.webdav.WebdavUtils; import com.owncloud.android.oc_framework.operations.RemoteOperation; import com.owncloud.android.oc_framework.operations.RemoteOperationResult; import com.owncloud.android.oc_framework.operations.RemoteOperationResult.ResultCode; +import com.owncloud.android.oc_framework.operations.remote.ReadRemoteFileOperation; import com.owncloud.android.oc_framework.operations.remote.ReadRemoteFolderOperation; import com.owncloud.android.oc_framework.operations.RemoteFile; import com.owncloud.android.syncadapter.FileSyncService; @@ -188,48 +184,27 @@ public class SynchronizeFolderOperation extends RemoteOperation { mRemoteFolderChanged = false; RemoteOperationResult result = null; String remotePath = null; - PropFindMethod query = null; - - try { + remotePath = mLocalFolder.getRemotePath(); Log_OC.d(TAG, "Checking changes in " + mAccount.name + remotePath); // remote request - query = new PropFindMethod(client.getBaseUri() + WebdavUtils.encodePath(remotePath), - DavConstants.PROPFIND_ALL_PROP, - DavConstants.DEPTH_0); - int status = client.executeMethod(query); - - // check and process response - if (isMultiStatus(status)) { - // parse data from remote folder - WebdavEntry we = new WebdavEntry(query.getResponseBodyAsMultiStatus().getResponses()[0], client.getBaseUri().getPath()); - OCFile remoteFolder = fillOCFile(we); - - // check if remote and local folder are different - mRemoteFolderChanged = !(remoteFolder.getEtag().equalsIgnoreCase(mLocalFolder.getEtag())); - - result = new RemoteOperationResult(ResultCode.OK); + ReadRemoteFileOperation operation = new ReadRemoteFileOperation(remotePath); + result = operation.execute(client); + if (result.isSuccess()){ + OCFile remoteFolder = FileStorageUtils.fillOCFile(result.getData().get(0)); + // check if remote and local folder are different + mRemoteFolderChanged = !(remoteFolder.getEtag().equalsIgnoreCase(mLocalFolder.getEtag())); + + result = new RemoteOperationResult(ResultCode.OK); + + Log_OC.i(TAG, "Checked " + mAccount.name + remotePath + " : " + (mRemoteFolderChanged ? "changed" : "not changed")); } else { // check failed - client.exhaustResponse(query.getResponseBodyAsStream()); - if (status == HttpStatus.SC_NOT_FOUND) { + if (result.getCode() == ResultCode.FILE_NOT_FOUND) { removeLocalFolder(); } - result = new RemoteOperationResult(false, status, query.getResponseHeaders()); - } - - } catch (Exception e) { - result = new RemoteOperationResult(e); - - - } finally { - if (query != null) - query.releaseConnection(); // let the connection available for other methods - if (result.isSuccess()) { - Log_OC.i(TAG, "Checked " + mAccount.name + remotePath + " : " + (mRemoteFolderChanged ? "changed" : "not changed")); - } else { if (result.isException()) { Log_OC.e(TAG, "Checked " + mAccount.name + remotePath + " : " + result.getLogMessage(), result.getException()); } else { @@ -237,7 +212,6 @@ public class SynchronizeFolderOperation extends RemoteOperation { } } - } return result; } @@ -249,9 +223,7 @@ public class SynchronizeFolderOperation extends RemoteOperation { Log_OC.d(TAG, "Synchronizing " + mAccount.name + remotePath); if (result.isSuccess()) { - RemoteFile folder = result.getFile(); - ArrayList files = result.getData(); - synchronizeData(folder, files, client); + synchronizeData(result.getData(), client); if (mConflictsFound > 0 || mFailsInFavouritesFound > 0) { result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT); // should be different result, but will do the job } @@ -278,26 +250,24 @@ public class SynchronizeFolderOperation extends RemoteOperation { * * Grants that mChildren is updated with fresh data after execution. * - * @param folder Remote Folder to synchronize - * - * @param files Remote Files in Folder + * @param folderAndFiles Remote folder and children files in Folder * * @param client Client instance to the remote server where the data were * retrieved. * @return 'True' when any change was made in the local data, 'false' otherwise. */ - private void synchronizeData(RemoteFile folder, ArrayList files, WebdavClient client) { + private void synchronizeData(ArrayList folderAndFiles, WebdavClient client) { // get 'fresh data' from the database mLocalFolder = mStorageManager.getFileByPath(mLocalFolder.getRemotePath()); // parse data from remote folder - OCFile remoteFolder = fillOCFile(folder); + OCFile remoteFolder = fillOCFile(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 "); - List updatedFiles = new Vector(files.size()); + List updatedFiles = new Vector(folderAndFiles.size() - 1); List filesToSyncContents = new Vector(); // get current data about local contents of the folder to synchronize @@ -309,9 +279,9 @@ public class SynchronizeFolderOperation extends RemoteOperation { // loop to update every child OCFile remoteFile = null, localFile = null; - for (RemoteFile file: files) { + for (int i=1; i