Skip to content

Commit cb71348

Browse files
tobiasKaminskyAndyScherzinger
authored andcommitted
add missing upload error messages
better handle temp file Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
1 parent 9927a64 commit cb71348

5 files changed

Lines changed: 87 additions & 60 deletions

File tree

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ dependencies {
210210
// dependencies for app building
211211
implementation 'androidx.multidex:multidex:2.0.1'
212212
// implementation project('nextcloud-android-library')
213-
genericImplementation 'com.github.nextcloud:android-library:master-SNAPSHOT'
214-
gplayImplementation 'com.github.nextcloud:android-library:master-SNAPSHOT'
215-
versionDevImplementation 'com.github.nextcloud:android-library:master-SNAPSHOT'
213+
genericImplementation 'com.github.nextcloud:android-library:newResultCode-SNAPSHOT'
214+
gplayImplementation 'com.github.nextcloud:android-library:newResultCode-SNAPSHOT'
215+
versionDevImplementation 'com.github.nextcloud:android-library:newResultCode-SNAPSHOT'
216216
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
217217
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
218218
implementation 'com.google.android.material:material:1.0.0'

src/main/java/com/owncloud/android/db/UploadResult.java

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* ownCloud Android client application
33
*
44
* @author masensio
@@ -29,7 +29,7 @@ public enum UploadResult {
2929
FOLDER_ERROR(3),
3030
CONFLICT_ERROR(4),
3131
FILE_ERROR(5),
32-
PRIVILEDGES_ERROR(6),
32+
PRIVILEGES_ERROR(6),
3333
CANCELLED(7),
3434
FILE_NOT_FOUND(8),
3535
DELAYED_FOR_WIFI(9),
@@ -39,7 +39,12 @@ public enum UploadResult {
3939
LOCK_FAILED(13),
4040
DELAYED_IN_POWER_SAVE_MODE(14),
4141
SSL_RECOVERABLE_PEER_UNVERIFIED(15),
42-
VIRUS_DETECTED(16);
42+
VIRUS_DETECTED(16),
43+
LOCAL_STORAGE_FULL(17),
44+
OLD_ANDROID_API(18),
45+
SYNC_CONFLICT(19),
46+
CANNOT_CREATE_FILE(20),
47+
LOCAL_STORAGE_NOT_COPIED(21);
4348

4449
private final int value;
4550

@@ -68,7 +73,7 @@ public static UploadResult fromValue(int value) {
6873
case 5:
6974
return FILE_ERROR;
7075
case 6:
71-
return PRIVILEDGES_ERROR;
76+
return PRIVILEGES_ERROR;
7277
case 7:
7378
return CANCELLED;
7479
case 8:
@@ -89,8 +94,18 @@ public static UploadResult fromValue(int value) {
8994
return SSL_RECOVERABLE_PEER_UNVERIFIED;
9095
case 16:
9196
return VIRUS_DETECTED;
97+
case 17:
98+
return LOCAL_STORAGE_FULL;
99+
case 18:
100+
return OLD_ANDROID_API;
101+
case 19:
102+
return SYNC_CONFLICT;
103+
case 20:
104+
return CANNOT_CREATE_FILE;
105+
case 21:
106+
return LOCAL_STORAGE_NOT_COPIED;
92107
}
93-
return null;
108+
return UNKNOWN;
94109
}
95110

96111
public static UploadResult fromOperationResult(RemoteOperationResult result) {
@@ -115,9 +130,15 @@ public static UploadResult fromOperationResult(RemoteOperationResult result) {
115130
case CONFLICT:
116131
return CONFLICT_ERROR;
117132
case LOCAL_STORAGE_NOT_COPIED:
118-
return FILE_ERROR;
133+
return LOCAL_STORAGE_NOT_COPIED;
134+
case LOCAL_STORAGE_FULL:
135+
return LOCAL_STORAGE_FULL;
136+
case OLD_ANDROID_API:
137+
return OLD_ANDROID_API;
138+
case SYNC_CONFLICT:
139+
return SYNC_CONFLICT;
119140
case FORBIDDEN:
120-
return PRIVILEDGES_ERROR;
141+
return PRIVILEGES_ERROR;
121142
case CANCELLED:
122143
return CANCELLED;
123144
case DELAYED_FOR_WIFI:
@@ -139,6 +160,8 @@ public static UploadResult fromOperationResult(RemoteOperationResult result) {
139160
return LOCK_FAILED;
140161
case VIRUS_DETECTED:
141162
return VIRUS_DETECTED;
163+
case CANNOT_CREATE_FILE:
164+
return CANNOT_CREATE_FILE;
142165
default:
143166
return UNKNOWN;
144167
}

src/main/java/com/owncloud/android/operations/UploadFileOperation.java

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
import java.nio.channels.OverlappingFileLockException;
8484
import java.util.HashMap;
8585
import java.util.HashSet;
86-
import java.util.Iterator;
8786
import java.util.Set;
8887
import java.util.UUID;
8988
import java.util.concurrent.atomic.AtomicBoolean;
@@ -502,7 +501,7 @@ private RemoteOperationResult encryptedUpload(OwnCloudClient client, OCFile pare
502501
expectedFile = new File(expectedPath);
503502

504503
result = copyFile(originalFile, expectedPath);
505-
if (result != null) {
504+
if (!result.isSuccess()) {
506505
return result;
507506
}
508507

@@ -551,7 +550,7 @@ private RemoteOperationResult encryptedUpload(OwnCloudClient client, OCFile pare
551550
Files.deleteIfExists(Paths.get(temporalPath));
552551
result = copy(originalFile, temporalFile);
553552

554-
if (result == null) {
553+
if (result.isSuccess()) {
555554
if (temporalFile.length() == originalFile.length()) {
556555
channel = new RandomAccessFile(temporalFile.getAbsolutePath(), "rw").getChannel();
557556
fileLock = channel.tryLock();
@@ -586,9 +585,8 @@ private RemoteOperationResult encryptedUpload(OwnCloudClient client, OCFile pare
586585
mFile.getEtagInConflict(), timeStamp);
587586
}
588587

589-
Iterator<OnDatatransferProgressListener> listener = mDataTransferListeners.iterator();
590-
while (listener.hasNext()) {
591-
mUploadOperation.addDatatransferProgressListener(listener.next());
588+
for (OnDatatransferProgressListener mDataTransferListener : mDataTransferListeners) {
589+
mUploadOperation.addDatatransferProgressListener(mDataTransferListener);
592590
}
593591

594592
if (mCancellationRequested.get()) {
@@ -755,7 +753,7 @@ private RemoteOperationResult normalUpload(OwnCloudClient client) {
755753
File originalFile = new File(mOriginalStoragePath);
756754
File expectedFile = null;
757755
FileLock fileLock = null;
758-
long size = 0;
756+
long size;
759757

760758
try {
761759
// check conditions
@@ -772,7 +770,7 @@ private RemoteOperationResult normalUpload(OwnCloudClient client) {
772770
expectedFile = new File(expectedPath);
773771

774772
result = copyFile(originalFile, expectedPath);
775-
if (result != null) {
773+
if (!result.isSuccess()) {
776774
return result;
777775
}
778776

@@ -795,7 +793,7 @@ private RemoteOperationResult normalUpload(OwnCloudClient client) {
795793
Files.deleteIfExists(Paths.get(temporalPath));
796794
result = copy(originalFile, temporalFile);
797795

798-
if (result == null) {
796+
if (result.isSuccess()) {
799797
if (temporalFile.length() == originalFile.length()) {
800798
channel = new RandomAccessFile(temporalFile.getAbsolutePath(), "rw").getChannel();
801799
fileLock = channel.tryLock();
@@ -807,7 +805,7 @@ private RemoteOperationResult normalUpload(OwnCloudClient client) {
807805

808806
try {
809807
size = channel.size();
810-
} catch (IOException e1) {
808+
} catch (Exception e1) {
811809
size = new File(mFile.getStoragePath()).length();
812810
}
813811

@@ -828,16 +826,15 @@ private RemoteOperationResult normalUpload(OwnCloudClient client) {
828826
mFile.getRemotePath(), mFile.getMimeType(), mFile.getEtagInConflict(), timeStamp);
829827
}
830828

831-
Iterator<OnDatatransferProgressListener> listener = mDataTransferListeners.iterator();
832-
while (listener.hasNext()) {
833-
mUploadOperation.addDatatransferProgressListener(listener.next());
829+
for (OnDatatransferProgressListener mDataTransferListener : mDataTransferListeners) {
830+
mUploadOperation.addDatatransferProgressListener(mDataTransferListener);
834831
}
835832

836833
if (mCancellationRequested.get()) {
837834
throw new OperationCancelledException();
838835
}
839836

840-
if (result == null || result.isSuccess() && mUploadOperation != null) {
837+
if (result.isSuccess() && mUploadOperation != null) {
841838
result = mUploadOperation.execute(client, mFile.isEncrypted());
842839

843840
/// move local temporal file or original file to its corresponding
@@ -908,22 +905,20 @@ private RemoteOperationResult normalUpload(OwnCloudClient client) {
908905

909906
private RemoteOperationResult copyFile(File originalFile, String expectedPath) throws OperationCancelledException,
910907
IOException {
911-
RemoteOperationResult result = null;
912-
913908
if (mLocalBehaviour == FileUploader.LOCAL_BEHAVIOUR_COPY && !mOriginalStoragePath.equals(expectedPath)) {
914909
String temporalPath = FileStorageUtils.getInternalTemporalPath(mAccount.name, mContext) +
915910
mFile.getRemotePath();
916911
mFile.setStoragePath(temporalPath);
917912
File temporalFile = new File(temporalPath);
918913

919-
result = copy(originalFile, temporalFile);
914+
return copy(originalFile, temporalFile);
920915
}
921916

922917
if (mCancellationRequested.get()) {
923918
throw new OperationCancelledException();
924919
}
925920

926-
return result;
921+
return new RemoteOperationResult(ResultCode.OK);
927922
}
928923

929924
private void checkNameCollision(OwnCloudClient client, DecryptedFolderMetadata metadata, boolean encrypted)
@@ -1017,7 +1012,7 @@ private RemoteOperationResult grantFolderExistence(String pathToGrant, OwnCloudC
10171012
if (parentDir != null) {
10181013
result = new RemoteOperationResult(ResultCode.OK);
10191014
} else {
1020-
result = new RemoteOperationResult(ResultCode.UNKNOWN_ERROR);
1015+
result = new RemoteOperationResult(ResultCode.CANNOT_CREATE_FILE);
10211016
}
10221017
}
10231018
return result;
@@ -1168,25 +1163,19 @@ public boolean isUploadInProgress() {
11681163
private RemoteOperationResult copy(File sourceFile, File targetFile) throws IOException {
11691164
Log_OC.d(TAG, "Copying local file");
11701165

1171-
RemoteOperationResult result = null;
1172-
11731166
if (FileStorageUtils.getUsableSpace() < sourceFile.length()) {
1174-
result = new RemoteOperationResult(ResultCode.LOCAL_STORAGE_FULL);
1175-
return result; // error condition when the file should be copied
1176-
1167+
return new RemoteOperationResult(ResultCode.LOCAL_STORAGE_FULL); // error when the file should be copied
11771168
} else {
11781169
Log_OC.d(TAG, "Creating temporal folder");
11791170
File temporalParent = targetFile.getParentFile();
1180-
temporalParent.mkdirs();
1181-
if (!temporalParent.isDirectory()) {
1182-
throw new IOException(
1183-
"Unexpected error: parent directory could not be created");
1171+
1172+
if (!temporalParent.mkdirs() && !temporalParent.isDirectory()) {
1173+
return new RemoteOperationResult(ResultCode.CANNOT_CREATE_FILE);
11841174
}
1175+
11851176
Log_OC.d(TAG, "Creating temporal file");
1186-
targetFile.createNewFile();
1187-
if (!targetFile.isFile()) {
1188-
throw new IOException(
1189-
"Unexpected error: target file could not be created");
1177+
if (!targetFile.createNewFile() && !targetFile.isFile()) {
1178+
return new RemoteOperationResult(ResultCode.CANNOT_CREATE_FILE);
11901179
}
11911180

11921181
Log_OC.d(TAG, "Copying file contents");
@@ -1214,14 +1203,10 @@ private RemoteOperationResult copy(File sourceFile, File targetFile) throws IOEx
12141203
} // else: weird but possible situation, nothing to copy
12151204

12161205
if (mCancellationRequested.get()) {
1217-
result = new RemoteOperationResult(new OperationCancelledException());
1218-
return result;
1206+
return new RemoteOperationResult(new OperationCancelledException());
12191207
}
1220-
12211208
} catch (Exception e) {
1222-
result = new RemoteOperationResult(ResultCode.LOCAL_STORAGE_NOT_COPIED);
1223-
return result;
1224-
1209+
return new RemoteOperationResult(ResultCode.LOCAL_STORAGE_NOT_COPIED);
12251210
} finally {
12261211
try {
12271212
if (in != null) {
@@ -1241,19 +1226,17 @@ private RemoteOperationResult copy(File sourceFile, File targetFile) throws IOEx
12411226
}
12421227
}
12431228
}
1244-
return result;
1229+
return new RemoteOperationResult(ResultCode.OK);
12451230
}
12461231

12471232

12481233
/**
12491234
* TODO rewrite with homogeneous fail handling, remove dependency on {@link RemoteOperationResult},
12501235
* TODO use Exceptions instead
1251-
* <p>
12521236
* TODO refactor both this and 'copy' in a single method
12531237
*
12541238
* @param sourceFile Source file to move.
12551239
* @param targetFile Target location to move the file.
1256-
* @return {@link RemoteOperationResult} result from remote operation
12571240
* @throws IOException exception if file cannot be read/wrote
12581241
*/
12591242
private void move(File sourceFile, File targetFile) throws IOException {

src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
import java.util.Comparator;
5959

6060
import androidx.annotation.NonNull;
61-
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
6261

6362
/**
6463
* This Adapter populates a ListView with following types of uploads: pending,active, completed. Filtering possible.
@@ -436,7 +435,7 @@ private String getUploadFailedStatusText(UploadResult result) {
436435
case FILE_ERROR:
437436
status = mParentActivity.getString(R.string.uploads_view_upload_status_failed_file_error);
438437
break;
439-
case PRIVILEDGES_ERROR:
438+
case PRIVILEGES_ERROR:
440439
status = mParentActivity.getString(R.string.uploads_view_upload_status_failed_permission_error);
441440
break;
442441
case NETWORK_CONNECTION:
@@ -466,23 +465,40 @@ private String getUploadFailedStatusText(UploadResult result) {
466465
status = mParentActivity.getString(R.string.maintenance_mode);
467466
break;
468467
case SSL_RECOVERABLE_PEER_UNVERIFIED:
469-
status =
470-
mParentActivity.getString(
468+
status = mParentActivity.getString(
471469
R.string.uploads_view_upload_status_failed_ssl_certificate_not_trusted
472470
);
473471
break;
474472
case UNKNOWN:
475473
status = mParentActivity.getString(R.string.uploads_view_upload_status_unknown_fail);
476474
break;
475+
case LOCK_FAILED:
476+
status = mParentActivity.getString(R.string.upload_lock_failed);
477+
break;
477478
case DELAYED_IN_POWER_SAVE_MODE:
478479
status = mParentActivity.getString(
479480
R.string.uploads_view_upload_status_waiting_exit_power_save_mode);
480481
break;
481482
case VIRUS_DETECTED:
482483
status = mParentActivity.getString(R.string.uploads_view_upload_status_virus_detected);
483484
break;
485+
case LOCAL_STORAGE_FULL:
486+
status = mParentActivity.getString(R.string.upload_local_storage_full);
487+
break;
488+
case OLD_ANDROID_API:
489+
status = mParentActivity.getString(R.string.upload_old_android);
490+
break;
491+
case SYNC_CONFLICT:
492+
status = mParentActivity.getString(R.string.upload_sync_conflict);
493+
break;
494+
case CANNOT_CREATE_FILE:
495+
status = mParentActivity.getString(R.string.upload_cannot_create_file);
496+
break;
497+
case LOCAL_STORAGE_NOT_COPIED:
498+
status = mParentActivity.getString(R.string.upload_local_storage_not_copied);
499+
break;
484500
default:
485-
status = "New fail result but no description for the user";
501+
status = mParentActivity.getString(R.string.upload_unknown_error);
486502
break;
487503
}
488504

@@ -656,14 +672,12 @@ public int compare(OCUpload upload1, OCUpload upload2) {
656672
}
657673
}
658674

659-
@SuppressFBWarnings("Bx")
660675
private int compareUploadId(OCUpload upload1, OCUpload upload2) {
661-
return Long.valueOf(upload1.getFixedUploadId()).compareTo(upload2.getFixedUploadId());
676+
return Long.compare(upload1.getFixedUploadId(), upload2.getFixedUploadId());
662677
}
663678

664-
@SuppressFBWarnings("Bx")
665679
private int compareUpdateTime(OCUpload upload1, OCUpload upload2) {
666-
return Long.valueOf(upload2.getFixedUploadEndTimeStamp()).compareTo(upload1.getFixedUploadEndTimeStamp());
680+
return Long.compare(upload2.getFixedUploadEndTimeStamp(), upload1.getFixedUploadEndTimeStamp());
667681
}
668682
};
669683
}

src/main/res/values/strings.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,4 +850,11 @@
850850
<string name="uploader_upload_files_behaviour_not_writable">source folder is read-only; file will only be uploaded</string>
851851
<string name="auto_upload_file_behaviour_kept_in_folder">kept in original folder, as it is readonly</string>
852852
<string name="scanQR_description">Login via QR code</string>
853+
<string name="upload_unknown_error">Unknown error</string>
854+
<string name="upload_lock_failed">Locking folder failed</string>
855+
<string name="upload_local_storage_full">Local storage full</string>
856+
<string name="upload_old_android"><![CDATA[Encryption is only possible with >= Android 5.0]]></string>
857+
<string name="upload_sync_conflict">Sync conflict, please resolve manually</string>
858+
<string name="upload_cannot_create_file">Cannot create local file</string>
859+
<string name="upload_local_storage_not_copied">File could not be copied to local storage</string>
853860
</resources>

0 commit comments

Comments
 (0)