aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPo Lu2023-08-08 16:17:10 +0800
committerPo Lu2023-08-08 16:17:10 +0800
commit440f017658aabe90668c9f6afbd38c1d892c1f6d (patch)
tree751f4e601a18a6141d69b7bf547f4813440919eb /src
parent27113c22f77b7a409c33b956a1a8d8be2d5bc673 (diff)
downloademacs-440f017658aabe90668c9f6afbd38c1d892c1f6d.tar.gz
emacs-440f017658aabe90668c9f6afbd38c1d892c1f6d.zip
Avoid caching file status when they are about to change
* java/org/gnu/emacs/EmacsSafThread.java (EmacsSafThread) (cacheFileStatus): New argument NO_CACHE. (cacheDirectoryFromCursor, statDocument1): * java/org/gnu/emacs/EmacsService.java (EmacsService) (statDocument): Plumb that argument through each of these wrapper functions. * src/android.c (android_init_emacs_service): Adjust JNI function signatures to agree with statDocument1. * src/androidvfs.c (android_saf_stat): Plumb that argument through here. (android_saf_tree_stat, android_saf_file_open): And don't cache file status if a write is imminent.
Diffstat (limited to 'src')
-rw-r--r--src/android.c2
-rw-r--r--src/androidvfs.c26
2 files changed, 19 insertions, 9 deletions
diff --git a/src/android.c b/src/android.c
index 7f263bc83d1..705ef227df3 100644
--- a/src/android.c
+++ b/src/android.c
@@ -1564,7 +1564,7 @@ android_init_emacs_service (void)
1564 "(Ljava/lang/String;Ljava/lang/String;)" 1564 "(Ljava/lang/String;Ljava/lang/String;)"
1565 "Ljava/lang/String;"); 1565 "Ljava/lang/String;");
1566 FIND_METHOD (stat_document, "statDocument", 1566 FIND_METHOD (stat_document, "statDocument",
1567 "(Ljava/lang/String;Ljava/lang/String;)[J"); 1567 "(Ljava/lang/String;Ljava/lang/String;Z)[J");
1568 FIND_METHOD (access_document, "accessDocument", 1568 FIND_METHOD (access_document, "accessDocument",
1569 "(Ljava/lang/String;Ljava/lang/String;Z)I"); 1569 "(Ljava/lang/String;Ljava/lang/String;Z)I");
1570 FIND_METHOD (open_document_directory, "openDocumentDirectory", 1570 FIND_METHOD (open_document_directory, "openDocumentDirectory",
diff --git a/src/androidvfs.c b/src/androidvfs.c
index 8e742f8b26f..0385e7348c6 100644
--- a/src/androidvfs.c
+++ b/src/androidvfs.c
@@ -3932,12 +3932,15 @@ android_saf_exception_check (int n, ...)
3932/* Return file status for the document designated by ID_NAME within 3932/* Return file status for the document designated by ID_NAME within
3933 the document tree identified by URI_NAME. 3933 the document tree identified by URI_NAME.
3934 3934
3935 If NO_CACHE, don't cache the resulting file status. Enable this
3936 option if the file status is subject to imminent change.
3937
3935 If the file status is available, place it within *STATB and return 3938 If the file status is available, place it within *STATB and return
3936 0. If not, return -1 and set errno to EPERM. */ 3939 0. If not, return -1 and set errno to EPERM. */
3937 3940
3938static int 3941static int
3939android_saf_stat (const char *uri_name, const char *id_name, 3942android_saf_stat (const char *uri_name, const char *id_name,
3940 struct stat *statb) 3943 struct stat *statb, bool no_cache)
3941{ 3944{
3942 jmethodID method; 3945 jmethodID method;
3943 jstring uri, id; 3946 jstring uri, id;
@@ -3969,10 +3972,12 @@ android_saf_stat (const char *uri_name, const char *id_name,
3969 /* Try to retrieve the file status. */ 3972 /* Try to retrieve the file status. */
3970 method = service_class.stat_document; 3973 method = service_class.stat_document;
3971 inside_saf_critical_section = true; 3974 inside_saf_critical_section = true;
3972 status = (*android_java_env)->CallNonvirtualObjectMethod (android_java_env, 3975 status
3973 emacs_service, 3976 = (*android_java_env)->CallNonvirtualObjectMethod (android_java_env,
3974 service_class.class, 3977 emacs_service,
3975 method, uri, id); 3978 service_class.class,
3979 method, uri, id,
3980 (jboolean) no_cache);
3976 inside_saf_critical_section = false; 3981 inside_saf_critical_section = false;
3977 3982
3978 /* Check for exceptions and release unneeded local references. */ 3983 /* Check for exceptions and release unneeded local references. */
@@ -5076,7 +5081,7 @@ android_saf_tree_stat (struct android_vnode *vnode,
5076 vp = (struct android_saf_tree_vnode *) vnode; 5081 vp = (struct android_saf_tree_vnode *) vnode;
5077 5082
5078 return android_saf_stat (vp->tree_uri, vp->document_id, 5083 return android_saf_stat (vp->tree_uri, vp->document_id,
5079 statb); 5084 statb, false);
5080} 5085}
5081 5086
5082static int 5087static int
@@ -5716,10 +5721,15 @@ android_saf_file_open (struct android_vnode *vnode, int flags,
5716 ANDROID_DELETE_LOCAL_REF (descriptor); 5721 ANDROID_DELETE_LOCAL_REF (descriptor);
5717 5722
5718 /* Try to retrieve the modification time of this file from the 5723 /* Try to retrieve the modification time of this file from the
5719 content provider. */ 5724 content provider.
5725
5726 Refrain from introducing the file status into the file status
5727 cache if FLAGS & O_RDWR or FLAGS & O_WRONLY: the cached file
5728 status will contain a size and modification time inconsistent
5729 with the result of any modifications that later transpire. */
5720 5730
5721 if (!android_saf_stat (vp->tree_uri, vp->document_id, 5731 if (!android_saf_stat (vp->tree_uri, vp->document_id,
5722 &statb)) 5732 &statb, write))
5723 info->mtime = get_stat_mtime (&statb); 5733 info->mtime = get_stat_mtime (&statb);
5724 else 5734 else
5725 info->mtime = invalid_timespec (); 5735 info->mtime = invalid_timespec ();