Fix PCloud not overwriting uploaded files.

When uploading an existing file into PCloud, it appends a version number
by default (e.g. "MyDb (2).kdbx", "MyDb (3).kdbx" and so on). This
behavior is not desirable in K2PA case. The workaroundfor this is to upload
the file with a temporary name and then rename it to its final name.
This may also avoid corruption with failed uploads depending on how
PCloud handles uploads.

See https://github.com/PhilippC/keepass2android/issues/512#issuecomment-435475365
This commit is contained in:
Gilbert Gilb's
2018-11-02 23:30:59 +01:00
parent 52ba506138
commit 25d1b6b695

View File

@@ -14,6 +14,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.UUID;
import java.util.regex.Pattern;
import com.pcloud.sdk.ApiClient;
@@ -135,8 +136,10 @@ public class PCloudFileStorage extends JavaFileStorageBase
String filePath = path.substring(0, path.lastIndexOf("/") + 1);
RemoteFolder remoteFolder = this.getRemoteFolderByPath(filePath);
String tempName = "." + UUID.randomUUID().toString();
try {
this.apiClient.createFile(remoteFolder, filename, dataSource).execute();
RemoteFile remoteFile = this.apiClient.createFile(remoteFolder, tempName, dataSource).execute();
this.apiClient.rename(remoteFile, filename).execute();
} catch (ApiError e) {
throw convertApiError(e);
}