aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rw-r--r--java/org/gnu/emacs/EmacsNative.java4
-rw-r--r--java/org/gnu/emacs/EmacsSafThread.java37
2 files changed, 41 insertions, 0 deletions
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);