@Override protected RemoteOperationResult run(WebdavClient client) { RemoteOperationResult result = null; // code before in FileSyncAdapter.fetchData PropFindMethod query = null; try { Log.d(TAG, "Synchronizing " + mAccount.name + ", fetching files in " + mRemotePath); // remote request query = new PropFindMethod(client.getBaseUri() + WebdavUtils.encodePath(mRemotePath)); 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); parent.setParentId(mParentId); mStorageManager.saveFile(parent); mParentId = parent.getFileId(); } // read contents in folder List<OCFile> updatedFiles = new Vector<OCFile>(resp.getResponses().length - 1); for (int i = 1; i < resp.getResponses().length; ++i) { WebdavEntry we = new WebdavEntry(resp.getResponses()[i], client.getBaseUri().getPath()); OCFile file = fillOCFile(we); file.setParentId(mParentId); OCFile oldFile = mStorageManager.getFileByPath(file.getRemotePath()); if (oldFile != null) { if (oldFile.keepInSync() && file.getModificationTimestamp() > oldFile.getModificationTimestamp()) { disableObservance( file); // first disable observer so we won't get file upload right after download requestContentDownload(file); } file.setKeepInSync(oldFile.keepInSync()); } 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); // removal of obsolete files mChildren = mStorageManager.getDirectoryContent(mStorageManager.getFileById(mParentId)); OCFile file; String currentSavePath = FileDownloader.getSavePath(mAccount.name); for (int i = 0; i < mChildren.size(); ) { file = mChildren.get(i); if (file.getLastSyncDate() != mCurrentSyncTime) { Log.d(TAG, "removing file: " + file); mStorageManager.removeFile( file, (file.isDown() && file.getStoragePath().startsWith(currentSavePath))); mChildren.remove(i); } else { i++; } } } else { client.exhaustResponse(query.getResponseBodyAsStream()); } // prepare result object result = new RemoteOperationResult(isMultiStatus(status), status); Log.i( TAG, "Synchronizing " + mAccount.name + ", folder " + mRemotePath + ": " + result.getLogMessage()); } catch (Exception e) { result = new RemoteOperationResult(e); Log.e( TAG, "Synchronizing " + mAccount.name + ", folder " + mRemotePath + ": " + result.getLogMessage(), result.getException()); } finally { if (query != null) query.releaseConnection(); // let the connection available for other methods } return result; }