|
@@ -150,10 +150,10 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
|
|
final long docId = Long.parseLong(documentId);
|
|
|
updateCurrentStorageManagerIfNeeded(docId);
|
|
|
|
|
|
- OCFile file = currentStorageManager.getFileById(docId);
|
|
|
+ OCFile ocFile = currentStorageManager.getFileById(docId);
|
|
|
|
|
|
- if (file == null) {
|
|
|
- throw new FileNotFoundException("File with id " + documentId + " not found!");
|
|
|
+ if (ocFile == null) {
|
|
|
+ throw new FileNotFoundException("File not found: " + documentId);
|
|
|
}
|
|
|
|
|
|
Account account = currentStorageManager.getAccount();
|
|
@@ -163,11 +163,10 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
|
|
throw new FileNotFoundException("Context may not be null!");
|
|
|
}
|
|
|
|
|
|
- if (!file.isDown()) {
|
|
|
-
|
|
|
+ if (!ocFile.isDown()) {
|
|
|
Intent i = new Intent(getContext(), FileDownloader.class);
|
|
|
i.putExtra(FileDownloader.EXTRA_ACCOUNT, account);
|
|
|
- i.putExtra(FileDownloader.EXTRA_FILE, file);
|
|
|
+ i.putExtra(FileDownloader.EXTRA_FILE, ocFile);
|
|
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
|
|
context.startForegroundService(i);
|
|
|
} else {
|
|
@@ -178,14 +177,14 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
|
|
if (!waitOrGetCancelled(cancellationSignal)) {
|
|
|
throw new FileNotFoundException("File with id " + documentId + " not found!");
|
|
|
}
|
|
|
- file = currentStorageManager.getFileById(docId);
|
|
|
+ ocFile = currentStorageManager.getFileById(docId);
|
|
|
|
|
|
- if (file == null) {
|
|
|
+ if (ocFile == null) {
|
|
|
throw new FileNotFoundException("File with id " + documentId + " not found!");
|
|
|
}
|
|
|
- } while (!file.isDown());
|
|
|
+ } while (!ocFile.isDown());
|
|
|
} else {
|
|
|
- OCFile finalFile = file;
|
|
|
+ OCFile finalFile = ocFile;
|
|
|
Thread syncThread = new Thread(() -> {
|
|
|
try {
|
|
|
FileDataStorageManager storageManager =
|
|
@@ -220,7 +219,33 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return ParcelFileDescriptor.open(new File(file.getStoragePath()), ParcelFileDescriptor.parseMode(mode));
|
|
|
+ File file = new File(ocFile.getStoragePath());
|
|
|
+ int accessMode = ParcelFileDescriptor.parseMode(mode);
|
|
|
+ boolean isWrite = (mode.indexOf('w') != -1);
|
|
|
+
|
|
|
+ final OCFile oldFile = ocFile;
|
|
|
+ final OCFile newFile = ocFile;
|
|
|
+
|
|
|
+ if (isWrite) {
|
|
|
+ try {
|
|
|
+ Handler handler = new Handler(context.getMainLooper());
|
|
|
+ return ParcelFileDescriptor.open(file, accessMode, handler, l -> {
|
|
|
+ RemoteOperationResult result = new SynchronizeFileOperation(newFile, oldFile, account, true,
|
|
|
+ context)
|
|
|
+ .execute(client, currentStorageManager);
|
|
|
+
|
|
|
+ boolean success = result.isSuccess();
|
|
|
+
|
|
|
+ if (!success) {
|
|
|
+ Log_OC.e(TAG, "Failed to update document with id " + documentId);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new FileNotFoundException("Failed to open/edit document with id " + documentId);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return ParcelFileDescriptor.open(file, accessMode);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void showToast() {
|