From 7d6f1c72f79d71b019504a9ba8c046828653bf62 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 8 Dec 2022 20:21:27 +0100 Subject: [PATCH 1/3] prevent remote deletion after local deletion due to fileObserver It also prevent Upload after a download due fileObserver --- app/src/main/java/foundation/e/drive/models/SyncWrapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/drive/models/SyncWrapper.java b/app/src/main/java/foundation/e/drive/models/SyncWrapper.java index 40b3e3db..6cae2050 100644 --- a/app/src/main/java/foundation/e/drive/models/SyncWrapper.java +++ b/app/src/main/java/foundation/e/drive/models/SyncWrapper.java @@ -83,7 +83,7 @@ public class SyncWrapper { public boolean equals(Object obj) { if (obj instanceof SyncRequest) { final SyncRequest objRequest = (SyncRequest) obj; - return (objRequest.equals(this.request) && objRequest.getOperationType() == this.request.getOperationType()); + return (objRequest.equals(this.request)); } return super.equals(obj); } -- GitLab From 95af410ee365b7e8fb3494cde8af39002db3f2fd Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 8 Dec 2022 20:31:08 +0100 Subject: [PATCH 2/3] prevent NPE due to previous commit --- .../services/SynchronizationService.java | 33 ++++++++----------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/services/SynchronizationService.java b/app/src/main/java/foundation/e/drive/services/SynchronizationService.java index ed0f2ab9..dae551d0 100644 --- a/app/src/main/java/foundation/e/drive/services/SynchronizationService.java +++ b/app/src/main/java/foundation/e/drive/services/SynchronizationService.java @@ -247,25 +247,9 @@ public class SynchronizationService extends Service implements OnRemoteOperation @Override public void onRemoteOperationFinish(RemoteOperation callerOperation, RemoteOperationResult result) { Timber.i("onRemoteOperationFinish()"); - SyncWrapper callerWrapper = null; - for (Map.Entry keyValue : startedSync.entrySet()) { - if (keyValue.getValue().getRemoteOperation().equals(callerOperation)) { - callerWrapper = keyValue.getValue(); - callerWrapper.setRunning(false); - startWorker(keyValue.getKey()); - break; - } - } - - if (callerWrapper != null) { - updateFailureCounter(callerWrapper.getRequest(), result.isSuccess()); - } - - if (callerOperation instanceof RemoveFileOperation) { - if ( result.isSuccess() ) { - DbHelper.manageSyncedFileStateDB( ( ( RemoveFileOperation ) callerOperation ).getSyncedFileState(), - "DELETE", this); - } + if (callerOperation instanceof RemoveFileOperation && result.isSuccess()) { + DbHelper.manageSyncedFileStateDB( ((RemoveFileOperation) callerOperation).getSyncedFileState(), + "DELETE", this); } else { final String operationClassName = callerOperation.getClass().getSimpleName(); switch (result.getCode()) { @@ -309,6 +293,17 @@ public class SynchronizationService extends Service implements OnRemoteOperation break; } } + + for (Map.Entry keyValue : startedSync.entrySet()) { + final SyncWrapper wrapper = keyValue.getValue(); + final RemoteOperation wrapperOperation= wrapper.getRemoteOperation(); + if (wrapperOperation != null && wrapperOperation.equals(callerOperation)) { + wrapper.setRunning(false); + updateFailureCounter(wrapper.getRequest(), result.isSuccess()); + startWorker(keyValue.getKey()); + break; + } + } } private void updateFailureCounter(SyncRequest request, boolean success) { -- GitLab From 6f3b25afe36a08b7f55587969c10192e5677d092 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Mon, 12 Dec 2022 08:27:08 +0000 Subject: [PATCH 3/3] Apply 2 suggestion(s) to 1 file(s) --- .../e/drive/services/SynchronizationService.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/services/SynchronizationService.java b/app/src/main/java/foundation/e/drive/services/SynchronizationService.java index dae551d0..77aa340e 100644 --- a/app/src/main/java/foundation/e/drive/services/SynchronizationService.java +++ b/app/src/main/java/foundation/e/drive/services/SynchronizationService.java @@ -248,8 +248,13 @@ public class SynchronizationService extends Service implements OnRemoteOperation public void onRemoteOperationFinish(RemoteOperation callerOperation, RemoteOperationResult result) { Timber.i("onRemoteOperationFinish()"); if (callerOperation instanceof RemoveFileOperation && result.isSuccess()) { - DbHelper.manageSyncedFileStateDB( ((RemoveFileOperation) callerOperation).getSyncedFileState(), - "DELETE", this); + DbHelper + .manageSyncedFileStateDB( + ((RemoveFileOperation) callerOperation) + .getSyncedFileState(), + "DELETE", + this + ); } else { final String operationClassName = callerOperation.getClass().getSimpleName(); switch (result.getCode()) { @@ -296,7 +301,7 @@ public class SynchronizationService extends Service implements OnRemoteOperation for (Map.Entry keyValue : startedSync.entrySet()) { final SyncWrapper wrapper = keyValue.getValue(); - final RemoteOperation wrapperOperation= wrapper.getRemoteOperation(); + final RemoteOperation wrapperOperation = wrapper.getRemoteOperation(); if (wrapperOperation != null && wrapperOperation.equals(callerOperation)) { wrapper.setRunning(false); updateFailureCounter(wrapper.getRequest(), result.isSuccess()); -- GitLab