Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 853913cb authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

prevent file deletion due to concurrency issue

parent d532571a
Loading
Loading
Loading
Loading
+3 −7
Original line number Diff line number Diff line
@@ -103,7 +103,7 @@ public class FileEventListener {
     */
    private void sendSyncRequestToSynchronizationService(SyncRequest request) {
        Timber.d("Sending a SyncRequest for %s", request.getSyncedFileState().getName());
        if (serviceConnection.isBoundToSynchronizationService()) {
        if (serviceConnection.isBound()) {
            serviceConnection.getSynchronizationService().queueSyncRequest(request);
            serviceConnection.getSynchronizationService().startSynchronization();
        }else{
@@ -233,14 +233,10 @@ public class FileEventListener {
    }

    public void unbindFromSynchronizationService(){
        if (serviceConnection.isBoundToSynchronizationService())
            appContext.unbindService(serviceConnection);
        else
            Timber.w("Not bound to SynchronizationService: can't unbind.");
        serviceConnection.unBind(appContext);
    }

    public void bindToSynchronizationService(){
        final Intent SynchronizationServiceIntent = new Intent(appContext, SynchronizationService.class);
        appContext.bindService(SynchronizationServiceIntent, serviceConnection, Context.BIND_AUTO_CREATE);
        serviceConnection.bindService(appContext);
    }
}
+2 −6
Original line number Diff line number Diff line
@@ -34,9 +34,7 @@ public class LocalContentScanner extends AbstractContentScanner<File>{

    @Override
    protected void onMissingFile(SyncedFileState fileState) {
        if (!fileState.hasBeenSynchronizedOnce()) {
            return;
        }
        if (!fileState.hasBeenSynchronizedOnce()) return;

        final File file = new File(fileState.getLocalPath());

@@ -90,5 +88,3 @@ public class LocalContentScanner extends AbstractContentScanner<File>{
        return fileState.getLocalPath().equals(filePath);
    }
}
 No newline at end of file

+5 −0
Original line number Diff line number Diff line
@@ -82,6 +82,11 @@ public class RemoteContentScanner extends AbstractContentScanner<RemoteFile> {

    @Override
    protected void onMissingFile(SyncedFileState fileState) {
        if (!fileState.hasBeenSynchronizedOnce()) {
            return;
        }

        Timber.d("Add local deletion request for file: %s", fileState.getLocalPath());
        this.syncRequests.put(fileState.getId(), new SyncRequest(fileState, LOCAL_DELETE));
    }

+7 −1
Original line number Diff line number Diff line
@@ -15,8 +15,14 @@ import android.os.Parcelable;
/**
 * @author Vincent Bourgmayer
 * Describe a file state which will be Synchronized (= Synced) or which has already been synced one times
 *
 * 1. file state: no etag & LM <=0 : new local file discovered
 *    todo: shouldn't it be more case 2 below ? would break lot of codes
 * 2. filestate: no etag but LM > 0 : ???
 *    When does it happens ?, and what does it correspond to ? what side effect of such case ?
 * 3. fileState: etag but LM <= 0 : new remote file discovered
 * 4. fileState: etag & LM > 0: file synchronized once
 */

public class SyncedFileState implements Parcelable {
    public static final int NOT_SCANNABLE=0;
    public static final int ECLOUD_SCANNABLE=1;
+1 −1
Original line number Diff line number Diff line
@@ -133,7 +133,7 @@ public class UploadFileOperation extends RemoteOperation {
        //If file already up-to-date & synced
        if (syncedState.isLastEtagStored()
                && syncedState.getLocalLastModified() == file.lastModified()) {
            Timber.d("Synchronization conflict because: last modified from DB(%s) and from file (%s) are different ", syncedState.getLocalLastModified(), file.lastModified());
            Timber.d("Synchronization conflict because: last modified from DB(%s) and from file (%s) are the same ", syncedState.getLocalLastModified(), file.lastModified());
            return ResultCode.SYNC_CONFLICT;
        }

Loading