From 4e132c3aa5ee9505e0683a0c3fb5bb7d8f77a799 Mon Sep 17 00:00:00 2001 From: Pinghao Wu Date: Fri, 1 Nov 2024 20:31:35 +0800 Subject: [PATCH] CephFSDocumentsProvider: support simple delete TODO reduce stat call, notify list changes --- .../safcephfs/CephFSDocumentsProvider.java | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/safcephfs/CephFSDocumentsProvider.java b/src/main/java/org/safcephfs/CephFSDocumentsProvider.java index 307453c..523e798 100644 --- a/src/main/java/org/safcephfs/CephFSDocumentsProvider.java +++ b/src/main/java/org/safcephfs/CephFSDocumentsProvider.java @@ -193,6 +193,15 @@ public class CephFSDocumentsProvider extends DocumentsProvider { return documentIdFromPath(path); } + public void deleteDocument(String documentId) throws FileNotFoundException { + Log.v(APP_NAME, "deleteDocument " + documentId); + var path = pathFromDocumentId(documentId); + executor.executeWithUnchecked(cm -> { + cm.unlink(path); + return null; + }); + } + public boolean isChildDocument(String parentDocumentId, String documentId) { return documentId.startsWith(parentDocumentId) && documentId.charAt(parentDocumentId.length()) == '/'; @@ -279,7 +288,7 @@ public class CephFSDocumentsProvider extends DocumentsProvider { } private void buildDocumentRow(String dir, String displayName, - String[] thumbnails, MatrixCursor result) + MatrixCursor result, String[] thumbnails, CephStat parentStat) throws FileNotFoundException { // TODO consider EXTRA_ERROR? var path = dir + displayName; @@ -372,6 +381,18 @@ public class CephFSDocumentsProvider extends DocumentsProvider { } break; } + + if (parentStat == null) { + parentStat = executor.executeWithUnchecked(cm -> { + var st = new CephStat(); + cm.stat(dir, st); + return st; + }); + } + // TODO support recur + if (mayWrite(parentStat) && !lcs.isDir()) { + flags |= Document.FLAG_SUPPORTS_DELETE; + } yield flags; } case Document.COLUMN_ICON -> { @@ -426,7 +447,7 @@ public class CephFSDocumentsProvider extends DocumentsProvider { } for (String entry : res) { - buildDocumentRow(path + "/", entry, thumbnails, result); + buildDocumentRow(path + "/", entry, result, thumbnails, null); } return result; } @@ -439,7 +460,7 @@ public class CephFSDocumentsProvider extends DocumentsProvider { int dirIndex = path.lastIndexOf("/"); String filename = path.substring(dirIndex + 1); String dir = path.substring(0, dirIndex + 1); - buildDocumentRow(dir, filename, null, result); + buildDocumentRow(dir, filename, result, null, null); return result; } -- 2.45.2