fix: simplifications

- Change all `CloudNode` to `PCloudNode`
- Check `replace` before `exists()`
- Move definition of relocationEntry below exception
- Change `CloudFile` to `PCloudFile`
This commit is contained in:
Manuel Jenny 2021-03-17 15:40:54 +01:00
parent b6cebf16fb
commit 90c7c14471
No known key found for this signature in database
GPG Key ID: 1C80FE62B2BEAA18
2 changed files with 9 additions and 8 deletions

View File

@ -96,7 +96,7 @@ class PCloudCloudContentRepository extends InterceptingCloudContentRepository<PC
}
@Override
public List<CloudNode> list(PCloudFolder folder) throws BackendException {
public List<PCloudNode> list(PCloudFolder folder) throws BackendException {
try {
return cloud.list(folder);
} catch (ApiError | IOException e) {

View File

@ -165,8 +165,8 @@ class PCloudImpl {
}
}
public List<CloudNode> list(PCloudFolder folder) throws ApiError, IOException {
List<CloudNode> result = new ArrayList<>();
public List<PCloudNode> list(PCloudFolder folder) throws ApiError, IOException {
List<PCloudNode> result = new ArrayList<>();
Long folderId = folder.getId();
RemoteFolder listFolderResult;
@ -201,12 +201,13 @@ class PCloudImpl {
PCloudCloudNodeFactory.folder(folder.getParent(), createdFolder));
}
public CloudNode move(PCloudNode source, PCloudNode target) throws ApiError, BackendException, IOException {
RemoteEntry relocationResult;
public PCloudNode move(PCloudNode source, PCloudNode target) throws ApiError, BackendException, IOException {
if (exists(target)) {
throw new CloudNodeAlreadyExistsException(target.getName());
}
RemoteEntry relocationResult;
if (source instanceof PCloudFolder) {
relocationResult = client().moveFolder(source.getId(), target.getParent().getId()).execute();
if (!relocationResult.name().equals(target.getName())) {
@ -225,7 +226,7 @@ class PCloudImpl {
public PCloudFile write(PCloudFile file, DataSource data, final ProgressAware<UploadState> progressAware, boolean replace, long size)
throws ApiError, BackendException, IOException {
if (exists(file) && !replace) {
if (!replace && exists(file)) {
throw new CloudNodeAlreadyExistsException("CloudNode already exists and replace is false");
}
@ -278,10 +279,10 @@ class PCloudImpl {
.execute();
}
public void read(CloudFile file, OutputStream data, final ProgressAware<DownloadState> progressAware) throws ApiError, IOException {
public void read(PCloudFile file, OutputStream data, final ProgressAware<DownloadState> progressAware) throws ApiError, IOException {
progressAware.onProgress(Progress.started(DownloadState.download(file)));
Long fileId = ((PCloudFile)file).getId();
Long fileId = file.getId();
if (fileId == null) {
fileId = idCache.get(file.getPath()).getId();
}