Merge pull request #306 from mjenny/bugfix/pcloud-root-folder

fix(pCloud): issue #305 NullReference
This commit is contained in:
Julian Raufelder 2021-04-23 15:29:14 +00:00 committed by GitHub
commit 282fc8ecb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -109,7 +109,9 @@ class PCloudImpl {
public boolean exists(PCloudNode node) throws IOException, BackendException {
try {
if (node instanceof PCloudFolder) {
if (node instanceof RootPCloudFolder) {
client().loadFolder("/").execute();
} else if (node instanceof PCloudFolder) {
client().loadFolder(node.getPath()).execute();
} else {
client().loadFile(node.getPath()).execute();
@ -124,8 +126,13 @@ class PCloudImpl {
public List<PCloudNode> list(PCloudFolder folder) throws IOException, BackendException {
List<PCloudNode> result = new ArrayList<>();
String path = folder.getPath();
if (folder instanceof RootPCloudFolder) {
path = "/";
}
try {
RemoteFolder listFolderResult = client().listFolder(folder.getPath()).execute();
RemoteFolder listFolderResult = client().listFolder(path).execute();
List<RemoteEntry> entryMetadata = listFolderResult.children();
for (RemoteEntry metadata : entryMetadata) {
result.add(PCloudNodeFactory.from(folder, metadata));