Skip to content

Commit

Permalink
Merge pull request #5442 from nextcloud/ezaquarii/fix-crash-on-text-f…
Browse files Browse the repository at this point in the history
…ile-creation

Fix crash during text file creation
  • Loading branch information
tobiasKaminsky authored Feb 17, 2020
2 parents 5c74f2b + 0977c37 commit 20b910a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
2 changes: 1 addition & 1 deletion scripts/analysis/findbugs-results.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
386
385
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.PorterDuff;
Expand Down Expand Up @@ -241,35 +242,36 @@ protected String doInBackground(Void... voids) {
new DirectEditingCreateFileRemoteOperation(path,
creator.getEditor(),
creator.getId(),
template.getTitle())
.execute(client);

if (result.isSuccess()) {
// get file
RemoteOperationResult newFileResult = new ReadFileRemoteOperation(path)
.execute(client);

if (newFileResult.isSuccess()) {
OCFile temp = FileStorageUtils.fillOCFile((RemoteFile) newFileResult.getData().get(0));

if (chooseTemplateDialogFragmentWeakReference.get() != null) {
FileDataStorageManager storageManager = new FileDataStorageManager(
user.toPlatformAccount(),
chooseTemplateDialogFragmentWeakReference.get().requireContext().getContentResolver());
storageManager.saveFile(temp);
file = storageManager.getFileByPath(path);

return result.getData().get(0).toString();
}
else {
return "";
}
} else {
return "";
}
} else {
template.getTitle()).execute(client);
if (!result.isSuccess()) {
return "";
}

RemoteOperationResult newFileResult = new ReadFileRemoteOperation(path).execute(client);
if (!newFileResult.isSuccess()) {
return "";
}

OCFile temp = FileStorageUtils.fillOCFile((RemoteFile) newFileResult.getData().get(0));

final ChooseTemplateDialogFragment fragment = chooseTemplateDialogFragmentWeakReference.get();
if (fragment == null) {
return "";
}

final Context context = fragment.getContext();
if (context == null) {
// fragment has been detached
return "";
}

FileDataStorageManager storageManager = new FileDataStorageManager(user.toPlatformAccount(),
context.getContentResolver());
storageManager.saveFile(temp);
file = storageManager.getFileByPath(path);

return result.getData().get(0).toString();

} catch (ClientFactory.CreationException e) {
Log_OC.e(TAG, "Error creating file from template!", e);
return "";
Expand Down

0 comments on commit 20b910a

Please sign in to comment.