emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 5e7e7304c3e 1/2: Fix truncation for the Android internal storage


From: Po Lu
Subject: master 5e7e7304c3e 1/2: Fix truncation for the Android internal storage provider
Date: Tue, 8 Aug 2023 02:11:25 -0400 (EDT)

branch: master
commit 5e7e7304c3e556e66c7e4157eb2fc80422a9d1be
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    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.
---
 java/org/gnu/emacs/EmacsSafThread.java | 9 +++++++--
 1 file 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
          /* Set mode to w when WRITE && !READ, disregarding TRUNCATE.
             In contradiction with the ContentResolver documentation,
             document providers seem to truncate files whenever w is
-            specified, at least superficially.  */
+            specified, at least superficially.  (But see below.)  */
          mode = "w";
       }
     else
@@ -1607,7 +1607,6 @@ public final class EmacsSafThread extends HandlerThread
     fileDescriptor
       = resolver.openFileDescriptor (documentUri, mode,
                                     signal);
-    Log.d (TAG, "openDocument1: " + mode + " " + fileDescriptor);
 
     /* If a writable on-disk file descriptor is requested and TRUNCATE
        is set, then probe the file descriptor to detect if it is
@@ -1644,6 +1643,12 @@ public final class EmacsSafThread extends HandlerThread
        if (fileDescriptor != null)
          EmacsNative.ftruncate (fileDescriptor.getFd ());
       }
+    else if (!read && write && truncate && fileDescriptor != null)
+      /* Moreover, document providers that return actual seekable
+        files characteristically neglect to truncate the file
+        returned when the access mode is merely w, so attempt to
+        truncate it by hand.  */
+      EmacsNative.ftruncate (fileDescriptor.getFd ());
 
     /* Every time a document is opened, remove it from the file status
        cache.  */



reply via email to

[Prev in Thread] Current Thread [Next in Thread]