From 3bca0d3c14b37634793a32b1c5726270be6e1367 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Thu, 3 Nov 2022 15:55:01 +0100 Subject: [PATCH] Prevent upload of a file after it has been downloaded and prevent a NPE in FileEventListener.handleDirectoryDelete(...) --- .../e/drive/FileObservers/FileEventListener.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/FileObservers/FileEventListener.java b/app/src/main/java/foundation/e/drive/FileObservers/FileEventListener.java index b047c955..91463c3c 100644 --- a/app/src/main/java/foundation/e/drive/FileObservers/FileEventListener.java +++ b/app/src/main/java/foundation/e/drive/FileObservers/FileEventListener.java @@ -153,7 +153,10 @@ public class FileEventListener { SyncedFolder folder = DbHelper.getSyncedFolderByLocalPath(fileLocalPath, appContext); if (folder == null) { //look for parent - final String parentPath = CommonUtils.getLocalPath(directory.getParentFile()); + final File parentFile = directory.getParentFile(); + if (parentFile == null) return; + + final String parentPath = CommonUtils.getLocalPath(parentFile); final SyncedFolder parentFolder = DbHelper.getSyncedFolderByLocalPath(parentPath, appContext); if (parentFolder == null ) { //if parent is not in the DB return; @@ -200,7 +203,8 @@ public class FileEventListener { Timber.d("New File %s observed but impossible to insert it in DB", file.getName()); } } else { //File update - if (fileState.getScannable() > 1) { + final boolean isWaitingForDownload = fileState.isLastEtagStored() && fileState.getLocalLastModified() == 0L; + if (fileState.getScannable() > 1 && !isWaitingForDownload) { request = new SyncRequest(fileState, UPLOAD); } } -- GitLab