- if (!oldFile.fileExists()) {
- // just a name coincidence
- file.setStoragePath(oldFile.getStoragePath());
-
- } else {
- // conflict resolved with 'Keep both' by the user
- File localFile = new File(oldFile.getStoragePath());
- File newLocalFile = new File(FileStorageUtils.getDefaultSavePathFor(mCurrentUpload.getAccount().name, file));
- boolean renameSuccessed = localFile.renameTo(newLocalFile);
- if (renameSuccessed) {
- file.setStoragePath(newLocalFile.getAbsolutePath());
-
- } else {
- // poor solution
- Log.d(TAG, "DAMN IT: local rename failed after uploading a file with a new name already existing both in the remote account and the local database (should be due to a conflict solved with 'keep both'");
- file.setStoragePath(null);
- // not so fine:
- // - local file will be kept there as 'trash' until is download (and overwritten) again from the server;
- // - user will see as 'not down' a file that was just upload
- // BUT:
- // - no loss of data happened
- // - when the user downloads again the renamed and original file from the server, local file names and contents will be correctly synchronized with names and contents in server
- }