aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorPo Lu2023-08-08 16:17:10 +0800
committerPo Lu2023-08-08 16:17:10 +0800
commit440f017658aabe90668c9f6afbd38c1d892c1f6d (patch)
tree751f4e601a18a6141d69b7bf547f4813440919eb /java
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 'java')
-rw-r--r--java/org/gnu/emacs/EmacsSafThread.java25
-rw-r--r--java/org/gnu/emacs/EmacsService.java7
2 files changed, 22 insertions, 10 deletions
diff --git a/java/org/gnu/emacs/EmacsSafThread.java b/java/org/gnu/emacs/EmacsSafThread.java
index 421e82c5759..1b62662b4fc 100644
--- a/java/org/gnu/emacs/EmacsSafThread.java
+++ b/java/org/gnu/emacs/EmacsSafThread.java
@@ -437,11 +437,14 @@ public final class EmacsSafThread extends HandlerThread
437 /* Cache file status for DOCUMENTID within TOPLEVEL. Value is the 437 /* Cache file status for DOCUMENTID within TOPLEVEL. Value is the
438 new cache entry. CURSOR is the cursor from where to retrieve the 438 new cache entry. CURSOR is the cursor from where to retrieve the
439 file status, in the form of the columns COLUMN_FLAGS, 439 file status, in the form of the columns COLUMN_FLAGS,
440 COLUMN_SIZE, COLUMN_MIME_TYPE and COLUMN_LAST_MODIFIED. */ 440 COLUMN_SIZE, COLUMN_MIME_TYPE and COLUMN_LAST_MODIFIED.
441
442 If NO_CACHE, don't cache the file status; just return the
443 entry. */
441 444
442 private StatCacheEntry 445 private StatCacheEntry
443 cacheFileStatus (String documentId, CacheToplevel toplevel, 446 cacheFileStatus (String documentId, CacheToplevel toplevel,
444 Cursor cursor) 447 Cursor cursor, boolean no_cache)
445 { 448 {
446 StatCacheEntry entry; 449 StatCacheEntry entry;
447 int flagsIndex, columnIndex, typeIndex; 450 int flagsIndex, columnIndex, typeIndex;
@@ -482,7 +485,8 @@ public final class EmacsSafThread extends HandlerThread
482 entry.mtime = cursor.getLong (mtimeIndex); 485 entry.mtime = cursor.getLong (mtimeIndex);
483 486
484 /* Finally, add this entry to the cache and return. */ 487 /* Finally, add this entry to the cache and return. */
485 toplevel.statCache.put (documentId, entry); 488 if (!no_cache)
489 toplevel.statCache.put (documentId, entry);
486 return entry; 490 return entry;
487 } 491 }
488 492
@@ -546,7 +550,7 @@ public final class EmacsSafThread extends HandlerThread
546 directory listing is being requested, it's very likely 550 directory listing is being requested, it's very likely
547 that a series of calls for file status will follow. */ 551 that a series of calls for file status will follow. */
548 552
549 cacheFileStatus (id, toplevel, cursor); 553 cacheFileStatus (id, toplevel, cursor, false);
550 554
551 /* If this constituent is a directory, don't cache any 555 /* If this constituent is a directory, don't cache any
552 information about it. It cannot be cached without 556 information about it. It cannot be cached without
@@ -1217,7 +1221,7 @@ public final class EmacsSafThread extends HandlerThread
1217 1221
1218 private long[] 1222 private long[]
1219 statDocument1 (String uri, String documentId, 1223 statDocument1 (String uri, String documentId,
1220 CancellationSignal signal) 1224 CancellationSignal signal, boolean noCache)
1221 { 1225 {
1222 Uri uriObject, tree; 1226 Uri uriObject, tree;
1223 String[] projection; 1227 String[] projection;
@@ -1266,7 +1270,8 @@ public final class EmacsSafThread extends HandlerThread
1266 if (!cursor.moveToFirst ()) 1270 if (!cursor.moveToFirst ())
1267 return null; 1271 return null;
1268 1272
1269 cache = cacheFileStatus (documentId, toplevel, cursor); 1273 cache = cacheFileStatus (documentId, toplevel, cursor,
1274 noCache);
1270 } 1275 }
1271 finally 1276 finally
1272 { 1277 {
@@ -1332,18 +1337,22 @@ public final class EmacsSafThread extends HandlerThread
1332 last modification to this file in milliseconds since 00:00, 1337 last modification to this file in milliseconds since 00:00,
1333 January 1st, 1970. 1338 January 1st, 1970.
1334 1339
1340 If NOCACHE, refrain from placing the file status within the
1341 status cache.
1342
1335 OperationCanceledException and other typical exceptions may be 1343 OperationCanceledException and other typical exceptions may be
1336 signaled upon receiving async input or other errors. */ 1344 signaled upon receiving async input or other errors. */
1337 1345
1338 public long[] 1346 public long[]
1339 statDocument (final String uri, final String documentId) 1347 statDocument (final String uri, final String documentId,
1348 final boolean noCache)
1340 { 1349 {
1341 return (long[]) runObjectFunction (new SafObjectFunction () { 1350 return (long[]) runObjectFunction (new SafObjectFunction () {
1342 @Override 1351 @Override
1343 public Object 1352 public Object
1344 runObject (CancellationSignal signal) 1353 runObject (CancellationSignal signal)
1345 { 1354 {
1346 return statDocument1 (uri, documentId, signal); 1355 return statDocument1 (uri, documentId, signal, noCache);
1347 } 1356 }
1348 }); 1357 });
1349 } 1358 }
diff --git a/java/org/gnu/emacs/EmacsService.java b/java/org/gnu/emacs/EmacsService.java
index 14ff2cce98f..379b1d30eda 100644
--- a/java/org/gnu/emacs/EmacsService.java
+++ b/java/org/gnu/emacs/EmacsService.java
@@ -1389,11 +1389,14 @@ public final class EmacsService extends Service
1389 last modification to this file in milliseconds since 00:00, 1389 last modification to this file in milliseconds since 00:00,
1390 January 1st, 1970. 1390 January 1st, 1970.
1391 1391
1392 If NOCACHE, refrain from placing the file status within the
1393 status cache.
1394
1392 OperationCanceledException and other typical exceptions may be 1395 OperationCanceledException and other typical exceptions may be
1393 signaled upon receiving async input or other errors. */ 1396 signaled upon receiving async input or other errors. */
1394 1397
1395 public long[] 1398 public long[]
1396 statDocument (String uri, String documentId) 1399 statDocument (String uri, String documentId, boolean noCache)
1397 { 1400 {
1398 /* Start the thread used to run SAF requests if it isn't already 1401 /* Start the thread used to run SAF requests if it isn't already
1399 running. */ 1402 running. */
@@ -1404,7 +1407,7 @@ public final class EmacsService extends Service
1404 storageThread.start (); 1407 storageThread.start ();
1405 } 1408 }
1406 1409
1407 return storageThread.statDocument (uri, documentId); 1410 return storageThread.statDocument (uri, documentId, noCache);
1408 } 1411 }
1409 1412
1410 /* Find out whether Emacs has access to the document designated by 1413 /* Find out whether Emacs has access to the document designated by