aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPo Lu2023-08-06 21:45:29 +0800
committerPo Lu2023-08-06 21:45:29 +0800
commit7873369338ee0159ca285153fd4592cbcff65d7a (patch)
treebd4fb3b1c8b19836d8d78b3ff4173470cfefd687
parent669a4b96c374801faa137f43b4497b2ed6511104 (diff)
downloademacs-7873369338ee0159ca285153fd4592cbcff65d7a.tar.gz
emacs-7873369338ee0159ca285153fd4592cbcff65d7a.zip
Update Android port
* java/org/gnu/emacs/EmacsNative.java: Declare ftruncate. * java/org/gnu/emacs/EmacsSafThread.java (openDocument1): If initially opening with rwt, verify the file descriptor is really writable; if not, resort to rw and truncating the file descriptor by hand instead. * src/androidvfs.c (NATIVE_NAME (ftruncate)): New function. Truncate file descriptor and return whether that was successful.
-rw-r--r--ChangeLog.android9
-rw-r--r--java/org/gnu/emacs/EmacsNative.java4
-rw-r--r--java/org/gnu/emacs/EmacsSafThread.java37
-rw-r--r--src/androidvfs.c8
4 files changed, 57 insertions, 1 deletions
diff --git a/ChangeLog.android b/ChangeLog.android
index 689482d2f1a..82ab75b40c1 100644
--- a/ChangeLog.android
+++ b/ChangeLog.android
@@ -1,11 +1,20 @@
12023-08-06 Po Lu <luangruo@yahoo.com> 12023-08-06 Po Lu <luangruo@yahoo.com>
2 2
3 * java/org/gnu/emacs/EmacsSafThread.java (openDocument1): If
4 initially opening with rwt, verify the file descriptor is really
5 writable; if not, resort to rw and truncating the file descriptor
6 by hand instead.
7
8 * src/androidvfs.c (NATIVE_NAME (ftruncate)): New function.
9 Truncate file descriptor and return whether that was successful.
10
3 * src/androidvfs.c (android_saf_tree_chmod): Repair file access 11 * src/androidvfs.c (android_saf_tree_chmod): Repair file access
4 permissions allowed within FLAGS. 12 permissions allowed within FLAGS.
5 13
62023-08-05 Po Lu <luangruo@yahoo.com> 142023-08-05 Po Lu <luangruo@yahoo.com>
7 15
8 * doc/lispref/commands.texi (Touchscreen Events): Fix typo. 16 * doc/lispref/commands.texi (Touchscreen Events): Fix typo.
17
9 * lisp/subr.el (y-or-n-p): Don't call set-text-conversion-style 18 * lisp/subr.el (y-or-n-p): Don't call set-text-conversion-style
10 when not present. 19 when not present.
11 20
diff --git a/java/org/gnu/emacs/EmacsNative.java b/java/org/gnu/emacs/EmacsNative.java
index 7d72a9f192e..fae0ba98f86 100644
--- a/java/org/gnu/emacs/EmacsNative.java
+++ b/java/org/gnu/emacs/EmacsNative.java
@@ -274,6 +274,10 @@ public final class EmacsNative
274 operations. */ 274 operations. */
275 public static native void safPostRequest (); 275 public static native void safPostRequest ();
276 276
277 /* Detect and return FD is writable. FD may be truncated to 0 bytes
278 in the process. */
279 public static native boolean ftruncate (int fd);
280
277 static 281 static
278 { 282 {
279 /* Older versions of Android cannot link correctly with shared 283 /* Older versions of Android cannot link correctly with shared
diff --git a/java/org/gnu/emacs/EmacsSafThread.java b/java/org/gnu/emacs/EmacsSafThread.java
index 29cd3fa6bc7..3ae3c0839ce 100644
--- a/java/org/gnu/emacs/EmacsSafThread.java
+++ b/java/org/gnu/emacs/EmacsSafThread.java
@@ -24,6 +24,7 @@ import java.util.HashMap;
24import java.util.Iterator; 24import java.util.Iterator;
25 25
26import java.io.FileNotFoundException; 26import java.io.FileNotFoundException;
27import java.io.IOException;
27 28
28import android.content.ContentResolver; 29import android.content.ContentResolver;
29import android.database.Cursor; 30import android.database.Cursor;
@@ -1597,6 +1598,42 @@ public final class EmacsSafThread extends HandlerThread
1597 = resolver.openFileDescriptor (documentUri, mode, 1598 = resolver.openFileDescriptor (documentUri, mode,
1598 signal); 1599 signal);
1599 1600
1601 /* If a writable file descriptor is requested and TRUNCATE is set,
1602 then probe the file descriptor to detect if it is actually
1603 readable. If not, close this file descriptor and reopen it
1604 with MODE set to rw; some document providers granting access to
1605 Samba shares don't implement rwt, but these document providers
1606 invariably truncate the file opened even when the mode is
1607 merely rw.
1608
1609 This may be ascribed to a mix-up in Android's documentation
1610 regardin DocumentsProvider: the `openDocument' function is only
1611 documented to accept r or rw, whereas the default
1612 implementation of the `openFile' function (which documents rwt)
1613 delegates to `openDocument'. */
1614
1615 if (write && truncate && fileDescriptor != null
1616 && !EmacsNative.ftruncate (fileDescriptor.getFd ()))
1617 {
1618 try
1619 {
1620 fileDescriptor.closeWithError ("File descriptor requested"
1621 + " is not writable");
1622 }
1623 catch (IOException e)
1624 {
1625 Log.w (TAG, "Leaking unclosed file descriptor " + e);
1626 }
1627
1628 fileDescriptor
1629 = resolver.openFileDescriptor (documentUri, "rw", signal);
1630
1631 /* Try to truncate fileDescriptor just to stay on the safe
1632 side. */
1633 if (fileDescriptor != null)
1634 EmacsNative.ftruncate (fileDescriptor.getFd ());
1635 }
1636
1600 /* Every time a document is opened, remove it from the file status 1637 /* Every time a document is opened, remove it from the file status
1601 cache. */ 1638 cache. */
1602 toplevel = getCache (treeUri); 1639 toplevel = getCache (treeUri);
diff --git a/src/androidvfs.c b/src/androidvfs.c
index dc5097f463e..d6daff481b0 100644
--- a/src/androidvfs.c
+++ b/src/androidvfs.c
@@ -5605,7 +5605,7 @@ android_saf_file_open (struct android_vnode *vnode, int flags,
5605 /* Open a parcel file descriptor according to flags. */ 5605 /* Open a parcel file descriptor according to flags. */
5606 5606
5607 method = service_class.open_document; 5607 method = service_class.open_document;
5608 trunc = flags & O_TRUNC; 5608 trunc = (flags & O_TRUNC);
5609 write = ((flags & O_RDWR) == O_RDWR || (flags & O_WRONLY)); 5609 write = ((flags & O_RDWR) == O_RDWR || (flags & O_WRONLY));
5610 inside_saf_critical_section = true; 5610 inside_saf_critical_section = true;
5611 descriptor 5611 descriptor
@@ -6121,6 +6121,12 @@ NATIVE_NAME (safPostRequest) (JNIEnv *env, jobject object)
6121 sem_post (&saf_completion_sem); 6121 sem_post (&saf_completion_sem);
6122} 6122}
6123 6123
6124JNIEXPORT jboolean JNICALL
6125NATIVE_NAME (ftruncate) (JNIEnv *env, jobject object, jint fd)
6126{
6127 return ftruncate (fd, 0) != -1;
6128}
6129
6124#ifdef __clang__ 6130#ifdef __clang__
6125#pragma clang diagnostic pop 6131#pragma clang diagnostic pop
6126#else /* GNUC */ 6132#else /* GNUC */