X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/6e469559c558d87d7e3cc81fc024b597e00be313..3defb175cb59ae3158f92347a8045f198e3208c7:/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 ad7df511..28a2def4 100644 --- a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java +++ b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java @@ -33,6 +33,8 @@ import android.util.Log; import com.owncloud.android.datamodel.DataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.services.FileDownloader; +import com.owncloud.android.files.services.FileObserverService; +import com.owncloud.android.utils.FileStorageUtils; import eu.alefzero.webdav.WebdavClient; import eu.alefzero.webdav.WebdavEntry; @@ -46,7 +48,7 @@ import eu.alefzero.webdav.WebdavUtils; */ public class SynchronizeFolderOperation extends RemoteOperation { - private static final String TAG = SynchronizeFolderOperation.class.getCanonicalName(); + private static final String TAG = SynchronizeFolderOperation.class.getSimpleName(); /** Remote folder to synchronize */ private String mRemotePath; @@ -130,6 +132,7 @@ public class SynchronizeFolderOperation extends RemoteOperation { 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()); @@ -137,8 +140,7 @@ public class SynchronizeFolderOperation extends RemoteOperation { 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); @@ -146,10 +148,10 @@ public class SynchronizeFolderOperation extends RemoteOperation { // removal of obsolete files mChildren = mStorageManager.getDirectoryContent(mStorageManager.getFileById(mParentId)); OCFile file; - String currentSavePath = FileDownloader.getSavePath(mAccount.name); + String currentSavePath = FileStorageUtils.getSavePath(mAccount.name); for (int i=0; i < mChildren.size(); ) { file = mChildren.get(i); - if (file.getLastSyncDate() != mCurrentSyncTime) { + if (file.getLastSyncDateForProperties() != mCurrentSyncTime) { Log.d(TAG, "removing file: " + file); mStorageManager.removeFile(file, (file.isDown() && file.getStoragePath().startsWith(currentSavePath))); mChildren.remove(i); @@ -179,7 +181,7 @@ public class SynchronizeFolderOperation extends RemoteOperation { return result; } - + public boolean isMultiStatus(int status) { return (status == HttpStatus.SC_MULTI_STATUS); } @@ -197,11 +199,27 @@ public class SynchronizeFolderOperation extends RemoteOperation { file.setFileLength(we.contentLength()); file.setMimetype(we.contentType()); file.setModificationTimestamp(we.modifiedTimesamp()); - file.setLastSyncDate(mCurrentSyncTime); + file.setLastSyncDateForProperties(mCurrentSyncTime); return file; } + /** + * Request to stop the observance of local updates for a file. + * + * @param file OCFile representing the remote file to stop to monitor for local updates + */ + private void disableObservance(OCFile file) { + Log.d(TAG, "Disabling observation of remote file" + file.getRemotePath()); + Intent intent = new Intent(mContext, FileObserverService.class); + intent.putExtra(FileObserverService.KEY_FILE_CMD, FileObserverService.CMD_ADD_DOWNLOADING_FILE); + intent.putExtra(FileObserverService.KEY_CMD_ARG_FILE, file); + intent.putExtra(FileObserverService.KEY_CMD_ARG_ACCOUNT, mAccount); + mContext.startService(intent); + + } + + /** * Requests a download to the file download service *