diff options
| author | Po Lu | 2023-08-08 14:04:36 +0800 |
|---|---|---|
| committer | Po Lu | 2023-08-08 14:04:36 +0800 |
| commit | 5e7e7304c3e556e66c7e4157eb2fc80422a9d1be (patch) | |
| tree | 1fef96dba758bbe672ce0da16ee7cfe48ff455d6 /java | |
| parent | 8cd1681c32dad9f0b674d2e6f55d61e1e025a7b1 (diff) | |
| download | emacs-5e7e7304c3e556e66c7e4157eb2fc80422a9d1be.tar.gz emacs-5e7e7304c3e556e66c7e4157eb2fc80422a9d1be.zip | |
Fix truncation for the Android internal storage provider
* java/org/gnu/emacs/EmacsSafThread.java (openDocument1): If
truncate is specified while resorting to `w', try truncating the
file by hand.
Diffstat (limited to 'java')
| -rw-r--r-- | java/org/gnu/emacs/EmacsSafThread.java | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/java/org/gnu/emacs/EmacsSafThread.java b/java/org/gnu/emacs/EmacsSafThread.java index 9f5d7f3d0cf..421e82c5759 100644 --- a/java/org/gnu/emacs/EmacsSafThread.java +++ b/java/org/gnu/emacs/EmacsSafThread.java | |||
| @@ -1598,7 +1598,7 @@ public final class EmacsSafThread extends HandlerThread | |||
| 1598 | /* Set mode to w when WRITE && !READ, disregarding TRUNCATE. | 1598 | /* Set mode to w when WRITE && !READ, disregarding TRUNCATE. |
| 1599 | In contradiction with the ContentResolver documentation, | 1599 | In contradiction with the ContentResolver documentation, |
| 1600 | document providers seem to truncate files whenever w is | 1600 | document providers seem to truncate files whenever w is |
| 1601 | specified, at least superficially. */ | 1601 | specified, at least superficially. (But see below.) */ |
| 1602 | mode = "w"; | 1602 | mode = "w"; |
| 1603 | } | 1603 | } |
| 1604 | else | 1604 | else |
| @@ -1607,7 +1607,6 @@ public final class EmacsSafThread extends HandlerThread | |||
| 1607 | fileDescriptor | 1607 | fileDescriptor |
| 1608 | = resolver.openFileDescriptor (documentUri, mode, | 1608 | = resolver.openFileDescriptor (documentUri, mode, |
| 1609 | signal); | 1609 | signal); |
| 1610 | Log.d (TAG, "openDocument1: " + mode + " " + fileDescriptor); | ||
| 1611 | 1610 | ||
| 1612 | /* If a writable on-disk file descriptor is requested and TRUNCATE | 1611 | /* If a writable on-disk file descriptor is requested and TRUNCATE |
| 1613 | is set, then probe the file descriptor to detect if it is | 1612 | is set, then probe the file descriptor to detect if it is |
| @@ -1644,6 +1643,12 @@ public final class EmacsSafThread extends HandlerThread | |||
| 1644 | if (fileDescriptor != null) | 1643 | if (fileDescriptor != null) |
| 1645 | EmacsNative.ftruncate (fileDescriptor.getFd ()); | 1644 | EmacsNative.ftruncate (fileDescriptor.getFd ()); |
| 1646 | } | 1645 | } |
| 1646 | else if (!read && write && truncate && fileDescriptor != null) | ||
| 1647 | /* Moreover, document providers that return actual seekable | ||
| 1648 | files characteristically neglect to truncate the file | ||
| 1649 | returned when the access mode is merely w, so attempt to | ||
| 1650 | truncate it by hand. */ | ||
| 1651 | EmacsNative.ftruncate (fileDescriptor.getFd ()); | ||
| 1647 | 1652 | ||
| 1648 | /* Every time a document is opened, remove it from the file status | 1653 | /* Every time a document is opened, remove it from the file status |
| 1649 | cache. */ | 1654 | cache. */ |