Skip to content

Commit fa8fbe2

Browse files
committed
wip
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent 764f1ec commit fa8fbe2

1 file changed

Lines changed: 46 additions & 32 deletions

File tree

app/src/main/java/com/owncloud/android/providers/DocumentsStorageProvider.java

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -678,45 +678,59 @@ private String createFile(Document targetFolder, String displayName, String mime
678678

679679
// FIXME we need to update the mimeType somewhere else as well
680680

681-
// perform the upload, no need for chunked operation as we have a empty file
682-
OwnCloudClient client = targetFolder.getClient();
683-
final var result = new UploadFileRemoteOperation(emptyFile.getAbsolutePath(),
684-
newFilePath,
685-
mimeType,
686-
"",
687-
System.currentTimeMillis() / 1000,
688-
FileUtil.getCreationTimestamp(emptyFile),
689-
false)
690-
.execute(client);
681+
try {
682+
// perform the upload, no need for chunked operation as we have a empty file
683+
OwnCloudClient client = targetFolder.getClient();
684+
final var result = new UploadFileRemoteOperation(emptyFile.getAbsolutePath(),
685+
newFilePath,
686+
mimeType,
687+
"",
688+
System.currentTimeMillis() / 1000,
689+
FileUtil.getCreationTimestamp(emptyFile),
690+
false)
691+
.execute(client);
691692

692-
if (!result.isSuccess()) {
693-
Log_OC.e(TAG, result.toString());
694-
throw new FileNotFoundException("Failed to upload document with path " + newFilePath);
695-
}
693+
if (!result.isSuccess()) {
694+
Log_OC.e(TAG, result.toString());
695+
notifyRemoteOperationError(result);
696+
throw new FileNotFoundException("Failed to upload document with path " + newFilePath);
697+
}
696698

697-
Context context = getNonNullContext();
699+
Context context = getNonNullContext();
698700

699-
final var updateParent = new RefreshFolderOperation(targetFolder.getFile(),
700-
System.currentTimeMillis(),
701-
false,
702-
false,
703-
true,
704-
targetFolder.getStorageManager(),
705-
user,
706-
context)
707-
.execute(client);
701+
final var updateParent = new RefreshFolderOperation(targetFolder.getFile(),
702+
System.currentTimeMillis(),
703+
false,
704+
false,
705+
true,
706+
targetFolder.getStorageManager(),
707+
user,
708+
context)
709+
.execute(client);
708710

709-
if (!updateParent.isSuccess()) {
710-
Log_OC.e(TAG, updateParent.toString());
711-
throw new FileNotFoundException("Failed to create document with documentId "
712-
+ targetFolder.getDocumentId());
713-
}
711+
if (!updateParent.isSuccess()) {
712+
Log_OC.e(TAG, updateParent.toString());
713+
notifyRemoteOperationError(updateParent);
714+
throw new FileNotFoundException("Failed to create document with documentId "
715+
+ targetFolder.getDocumentId());
716+
}
714717

715-
Document newFile = new Document(targetFolder.getStorageManager(), newFilePath);
718+
Document newFile = new Document(targetFolder.getStorageManager(), newFilePath);
716719

717-
context.getContentResolver().notifyChange(toNotifyUri(targetFolder), null, false);
720+
context.getContentResolver().notifyChange(toNotifyUri(targetFolder), null, false);
721+
722+
return newFile.getDocumentId();
723+
} finally {
724+
if (emptyFile.exists() && !emptyFile.delete()) {
725+
Log_OC.w(TAG, "Temp file could not be deleted: " + emptyFile.getAbsolutePath());
726+
}
727+
}
728+
}
718729

719-
return newFile.getDocumentId();
730+
private void notifyRemoteOperationError(RemoteOperationResult result) {
731+
if (result.getCode() == RemoteOperationResult.ResultCode.MAINTENANCE_MODE) {
732+
showToast(R.string.maintenance_mode);
733+
}
720734
}
721735

722736
@Override

0 commit comments

Comments
 (0)