aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorPo Lu2023-07-29 15:57:44 +0800
committerPo Lu2023-07-29 15:57:44 +0800
commit4bf8b0a2e9db842283e9e3849e8d23573ba3b181 (patch)
tree57265728723b457267126270254844b90be911e0 /java
parent431fdda2ebbb6e93ea4eb705ec16a44b49c30c8d (diff)
downloademacs-4bf8b0a2e9db842283e9e3849e8d23573ba3b181.tar.gz
emacs-4bf8b0a2e9db842283e9e3849e8d23573ba3b181.zip
Update Android port
* java/org/gnu/emacs/EmacsSafThread.java (postInvalidateCache): New argument cacheName. Remove that file from the cache. (accessDocument1): Consult the storage cache as well. * java/org/gnu/emacs/EmacsService.java (deleteDocument): New argument NAME. * src/android.c (android_init_emacs_service): Add new argument. * src/androidvfs.c (android_saf_delete_document) (android_saf_tree_rmdir, android_saf_file_unlink): Pass name of file being deleted to `deleteDocument'.
Diffstat (limited to 'java')
-rw-r--r--java/org/gnu/emacs/EmacsSafThread.java71
-rw-r--r--java/org/gnu/emacs/EmacsService.java9
2 files changed, 71 insertions, 9 deletions
diff --git a/java/org/gnu/emacs/EmacsSafThread.java b/java/org/gnu/emacs/EmacsSafThread.java
index cf067adc87b..cb69df01bfb 100644
--- a/java/org/gnu/emacs/EmacsSafThread.java
+++ b/java/org/gnu/emacs/EmacsSafThread.java
@@ -478,14 +478,12 @@ public final class EmacsSafThread extends HandlerThread
478 document tree URI. 478 document tree URI.
479 Call this after deleting a document or directory. 479 Call this after deleting a document or directory.
480 480
481 Caveat emptor: this does not remove the component name cache 481 At the same time, remove the final component within the file name
482 entries linked to the name(s) of the directory being removed, the 482 CACHENAME from the cache if it exists. */
483 assumption being that the next time `documentIdFromName1' is
484 called, it will notice that the document is missing and remove
485 the outdated cache entry. */
486 483
487 public void 484 public void
488 postInvalidateCache (final Uri uri, final String documentId) 485 postInvalidateCache (final Uri uri, final String documentId,
486 final String cacheName)
489 { 487 {
490 handler.post (new Runnable () { 488 handler.post (new Runnable () {
491 @Override 489 @Override
@@ -493,9 +491,55 @@ public final class EmacsSafThread extends HandlerThread
493 run () 491 run ()
494 { 492 {
495 CacheToplevel toplevel; 493 CacheToplevel toplevel;
494 HashMap<String, DocIdEntry> children;
495 String[] components;
496 CacheEntry entry;
497 DocIdEntry idEntry;
496 498
497 toplevel = getCache (uri); 499 toplevel = getCache (uri);
498 toplevel.idCache.remove (documentId); 500 toplevel.idCache.remove (documentId);
501
502 /* If the parent of CACHENAME is cached, remove it. */
503
504 children = toplevel.children;
505 components = cacheName.split ("/");
506
507 for (String component : components)
508 {
509 /* Java `split' removes trailing empty matches but not
510 leading or intermediary ones. */
511 if (component.isEmpty ())
512 continue;
513
514 if (component == components[components.length - 1])
515 {
516 /* This is the last component, so remove it from
517 children. */
518 children.remove (component);
519 return;
520 }
521 else
522 {
523 /* Search for this component within the last level
524 of the cache. */
525
526 idEntry = children.get (component);
527
528 if (idEntry == null)
529 /* Not cached, so return. */
530 return;
531
532 entry = toplevel.idCache.get (idEntry.documentId);
533
534 if (entry == null)
535 /* Not cached, so return. */
536 return;
537
538 /* Locate the next component within this
539 directory. */
540 children = entry.children;
541 }
542 }
499 } 543 }
500 }); 544 });
501 } 545 }
@@ -1109,12 +1153,27 @@ public final class EmacsSafThread extends HandlerThread
1109 int tem, index; 1153 int tem, index;
1110 String tem1; 1154 String tem1;
1111 Cursor cursor; 1155 Cursor cursor;
1156 CacheToplevel toplevel;
1157 CacheEntry entry;
1112 1158
1113 uriObject = Uri.parse (uri); 1159 uriObject = Uri.parse (uri);
1114 1160
1115 if (documentId == null) 1161 if (documentId == null)
1116 documentId = DocumentsContract.getTreeDocumentId (uriObject); 1162 documentId = DocumentsContract.getTreeDocumentId (uriObject);
1117 1163
1164 /* If WRITABLE is false and the document ID is cached, use its
1165 cached value instead. This speeds up
1166 `directory-files-with-attributes' a little. */
1167
1168 if (!writable)
1169 {
1170 toplevel = getCache (uriObject);
1171 entry = toplevel.idCache.get (documentId);
1172
1173 if (entry != null)
1174 return 0;
1175 }
1176
1118 /* Create a document URI representing DOCUMENTID within URI's 1177 /* Create a document URI representing DOCUMENTID within URI's
1119 authority. */ 1178 authority. */
1120 1179
diff --git a/java/org/gnu/emacs/EmacsService.java b/java/org/gnu/emacs/EmacsService.java
index e2abd6c96ef..5186dec974a 100644
--- a/java/org/gnu/emacs/EmacsService.java
+++ b/java/org/gnu/emacs/EmacsService.java
@@ -1674,10 +1674,13 @@ public final class EmacsService extends Service
1674 1674
1675 /* Delete the document identified by ID from the document tree 1675 /* Delete the document identified by ID from the document tree
1676 identified by URI. Return 0 upon success and -1 upon 1676 identified by URI. Return 0 upon success and -1 upon
1677 failure. */ 1677 failure.
1678
1679 NAME should be the name of the document being deleted, and is
1680 used to invalidate the cache. */
1678 1681
1679 public int 1682 public int
1680 deleteDocument (String uri, String id) 1683 deleteDocument (String uri, String id, String name)
1681 throws FileNotFoundException 1684 throws FileNotFoundException
1682 { 1685 {
1683 Uri uriObject, tree; 1686 Uri uriObject, tree;
@@ -1688,7 +1691,7 @@ public final class EmacsService extends Service
1688 if (DocumentsContract.deleteDocument (resolver, uriObject)) 1691 if (DocumentsContract.deleteDocument (resolver, uriObject))
1689 { 1692 {
1690 if (storageThread != null) 1693 if (storageThread != null)
1691 storageThread.postInvalidateCache (tree, id); 1694 storageThread.postInvalidateCache (tree, id, name);
1692 1695
1693 return 0; 1696 return 0;
1694 } 1697 }