- OCFile file = fillOCFile(we);
- OCFile oldFile = mStorageManager.getFileByPath(file.getRemotePath());
- if (oldFile.getFileLength() != file.getFileLength() ||
- oldFile.getModificationTimestamp() != file.getModificationTimestamp()) {
- isConflict = Boolean.TRUE;
- }
+ OCFile serverFile = fillOCFile(we);
+
+ /// check changes in server and local file
+ boolean serverChanged = false;
+ if (serverFile.getEtag() != null) {
+ serverChanged = (!serverFile.getEtag().equals(localFile.getEtag()));
+ } else {
+ // server without etags
+ serverChanged = (serverFile.getModificationTimestamp() > localFile.getModificationTimestamp());
+ }
+ boolean localChanged = (mLocalChangeAlreadyKnown || localFile.getLocalModificationTimestamp() > localFile.getLastSyncDateForData());
+
+ /// decide action to perform depending upon changes
+ if (localChanged && serverChanged) {
+ // conflict
+ result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT);
+
+ } else if (localChanged) {
+ if (mSyncFileContents) {
+ requestForUpload(localFile);
+ // the local update of file properties will be done by the FileUploader service when the upload finishes
+ } else {
+ // NOTHING TO DO HERE: updating the properties of the file in the server without uploading the contents would be stupid;
+ // So, an instance of SynchronizeFileOperation created with syncFileContents == false is completely useless when we suspect
+ // that an upload is necessary (for instance, in FileObserverService).
+ }
+ result = new RemoteOperationResult(ResultCode.OK);
+
+ } else if (serverChanged) {
+ if (mSyncFileContents) {
+ requestForDownload(serverFile);
+ // the update of local data will be done later by the FileUploader service when the upload finishes
+ } else {
+ // TODO CHECK: is this really useful in some point in the code?
+ serverFile.setKeepInSync(localFile.keepInSync());
+ serverFile.setParentId(localFile.getParentId());
+ mStorageManager.saveFile(serverFile);
+
+ }
+ result = new RemoteOperationResult(ResultCode.OK);