Skip to content

Commit 15b190d

Browse files
author
Julian Kast
committed
Added logic to check if file is no longer on head unit when deleting sdlFiles in operation
1 parent b46f82c commit 15b190d

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

base/src/main/java/com/smartdevicelink/managers/file/BaseFileManager.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ abstract class BaseFileManager extends BaseSubManager {
7070
private HashMap<String, Integer> failedFileUploadsCount;
7171
private final int maxFileUploadAttempts;
7272
private final int maxArtworkUploadAttempts;
73-
String fileManagerCannotOverwriteError = "Cannot overwrite remote file. The remote file system already has a file of this name, and the file manager is set to not automatically overwrite files.";
73+
final String fileManagerCannotOverwriteError = "Cannot overwrite remote file. The remote file system already has a file of this name, and the file manager is set to not automatically overwrite files.";
7474

7575

7676
/**
@@ -196,13 +196,7 @@ public void onComplete(boolean success, int bytesAvailable, Collection<String> f
196196
}
197197

198198
private void deleteRemoteFileWithNamePrivate(@NonNull final String fileName, final FileManagerCompletionListener listener) {
199-
if (!mutableRemoteFileNames.contains(fileName) && listener != null) {
200-
String errorMessage = "No such remote file is currently known";
201-
listener.onComplete(false, bytesAvailable, mutableRemoteFileNames, errorMessage);
202-
return;
203-
}
204-
205-
DeleteFileOperation operation = new DeleteFileOperation(internalInterface, fileName, new FileManagerCompletionListener() {
199+
DeleteFileOperation operation = new DeleteFileOperation(internalInterface, fileName, mutableRemoteFileNames, new FileManagerCompletionListener() {
206200
@Override
207201
public void onComplete(boolean success, int bytesAvailable, Collection<String> fileNames, String errorMessage) {
208202
if (success) {

base/src/main/java/com/smartdevicelink/managers/file/DeleteFileOperation.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@
3838
import com.smartdevicelink.proxy.rpc.DeleteFile;
3939
import com.smartdevicelink.proxy.rpc.DeleteFileResponse;
4040
import com.smartdevicelink.proxy.rpc.listeners.OnRPCResponseListener;
41+
import com.smartdevicelink.util.DebugTool;
4142

4243
import java.lang.ref.WeakReference;
44+
import java.util.Set;
4345

4446
/**
4547
* Created by Bilal Alsharifi on 12/1/20.
@@ -49,12 +51,14 @@ class DeleteFileOperation extends Task {
4951
private final WeakReference<ISdl> internalInterface;
5052
private String fileName;
5153
private FileManagerCompletionListener completionListener;
54+
private Set<String> mutableRemoteFileNames;
5255

53-
DeleteFileOperation(ISdl internalInterface, String fileName, FileManagerCompletionListener completionListener) {
56+
DeleteFileOperation(ISdl internalInterface, String fileName, Set<String> mutableRemoteFileNames, FileManagerCompletionListener completionListener) {
5457
super("DeleteFileOperation");
5558
this.internalInterface = new WeakReference<>(internalInterface);
5659
this.fileName = fileName;
5760
this.completionListener = completionListener;
61+
this.mutableRemoteFileNames = mutableRemoteFileNames;
5862
}
5963

6064
@Override
@@ -66,6 +70,13 @@ private void start() {
6670
if (getState() == Task.CANCELED) {
6771
return;
6872
}
73+
if (!mutableRemoteFileNames.contains(fileName) && completionListener != null) {
74+
String errorMessage = "File to delete is no longer on the head unit, aborting operation";
75+
// Returning BaseFileManager.SPACE_AVAILABLE_MAX_VALUE for bytesAvaialble as a placeHolder, it will not get updated in BaseFileManager as long as success returned is false.
76+
completionListener.onComplete(false, BaseFileManager.SPACE_AVAILABLE_MAX_VALUE, mutableRemoteFileNames, errorMessage);
77+
onFinished();
78+
return;
79+
}
6980

7081
deleteFile();
7182
}
@@ -77,12 +88,15 @@ private void deleteFile() {
7788
public void onResponse(int correlationId, RPCResponse response) {
7889
DeleteFileResponse deleteFileResponse = (DeleteFileResponse) response;
7990
boolean success = deleteFileResponse.getSuccess();
91+
String errorMessage = success ? null : response.getInfo() + ": " + response.getResultCode();
92+
if (errorMessage != null) {
93+
DebugTool.logInfo(TAG, "Error deleting file: " + errorMessage);
94+
}
8095

8196
// If spaceAvailable is null, set it to the max value
8297
int bytesAvailable = deleteFileResponse.getSpaceAvailable() != null ? deleteFileResponse.getSpaceAvailable() : BaseFileManager.SPACE_AVAILABLE_MAX_VALUE;
8398

8499
if (completionListener != null) {
85-
String errorMessage = success ? null : response.getInfo() + ": " + response.getResultCode();
86100
completionListener.onComplete(success, bytesAvailable, null, errorMessage);
87101
}
88102

0 commit comments

Comments
 (0)