fix: use static sets, user proper name

This commit is contained in:
Manuel Jenny 2021-03-26 14:16:17 +01:00
parent 728d5262ab
commit d227c5c0fd
No known key found for this signature in database
GPG Key ID: 1C80FE62B2BEAA18
2 changed files with 31 additions and 7 deletions

View File

@ -1,5 +1,8 @@
package org.cryptomator.data.cloud.pcloud;
import java.util.Arrays;
import java.util.HashSet;
public class PCloudApiError {
public enum PCloudApiErrorCodes {
@ -51,6 +54,26 @@ public class PCloudApiError {
}
}
public static final HashSet<Integer> ignoreExistsSet = new HashSet<>(
Arrays.asList(
PCloudApiErrorCodes.COMPONENT_OF_PARENT_DIRECTORY_DOES_NOT_EXIST.getValue(),
PCloudApiErrorCodes.FILE_NOT_FOUND.getValue(),
PCloudApiErrorCodes.FILE_OR_FOLDER_NOT_FOUND.getValue(),
PCloudApiErrorCodes.DIRECTORY_DOES_NOT_EXIST.getValue(),
PCloudApiErrorCodes.INVALID_FILE_OR_FOLDER_NAME.getValue()
)
);
public static final HashSet<Integer> ignoreMoveSet = new HashSet<>(
Arrays.asList(
PCloudApiErrorCodes.FILE_OR_FOLDER_ALREADY_EXISTS.getValue(),
PCloudApiErrorCodes.COMPONENT_OF_PARENT_DIRECTORY_DOES_NOT_EXIST.getValue(),
PCloudApiErrorCodes.FILE_NOT_FOUND.getValue(),
PCloudApiErrorCodes.FILE_OR_FOLDER_NOT_FOUND.getValue(),
PCloudApiErrorCodes.DIRECTORY_DOES_NOT_EXIST.getValue()
)
);
public static boolean isCloudNodeAlreadyExistsException(int errorCode) {
return errorCode == PCloudApiErrorCodes.FILE_OR_FOLDER_ALREADY_EXISTS.getValue();
}

View File

@ -117,12 +117,7 @@ class PCloudImpl {
}
return true;
} catch (ApiError ex) {
Set<Integer> ignoredErrorCodes = new HashSet<>();
ignoredErrorCodes.add(PCloudApiError.PCloudApiErrorCodes.DIRECTORY_DOES_NOT_EXIST.getValue());
ignoredErrorCodes.add(PCloudApiError.PCloudApiErrorCodes.COMPONENT_OF_PARENT_DIRECTORY_DOES_NOT_EXIST.getValue());
ignoredErrorCodes.add(PCloudApiError.PCloudApiErrorCodes.INVALID_FILE_OR_FOLDER_NAME.getValue());
ignoredErrorCodes.add(PCloudApiError.PCloudApiErrorCodes.FILE_OR_FOLDER_NOT_FOUND.getValue());
handleApiError(ex, ignoredErrorCodes, node.getName());
handleApiError(ex, PCloudApiError.ignoreExistsSet, node.getName());
return false;
}
}
@ -174,7 +169,13 @@ class PCloudImpl {
return PCloudNodeFactory.from(target.getParent(), client().moveFile(source.getPath(), target.getPath()).execute());
}
} catch(ApiError ex) {
handleApiError(ex, source.getName() + " / " + target.getName());
if (PCloudApiError.isCloudNodeAlreadyExistsException(ex.errorCode())) {
throw new CloudNodeAlreadyExistsException(target.getName());
} else if (PCloudApiError.isNoSuchCloudFileException(ex.errorCode())) {
throw new NoSuchCloudFileException(source.getName());
} else {
handleApiError(ex, PCloudApiError.ignoreMoveSet, null);
}
throw new FatalBackendException(ex);
}
}