From 925ac3643217eca9ce93e7c92b473c7fc370410d Mon Sep 17 00:00:00 2001 From: Pinghao Wu Date: Fri, 1 Nov 2024 22:11:12 +0800 Subject: [PATCH] CephFSDocumentsProvider: support rename --- .../org/safcephfs/CephFSDocumentsProvider.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/org/safcephfs/CephFSDocumentsProvider.java b/src/main/java/org/safcephfs/CephFSDocumentsProvider.java index c90c4cb..6c1bb9f 100644 --- a/src/main/java/org/safcephfs/CephFSDocumentsProvider.java +++ b/src/main/java/org/safcephfs/CephFSDocumentsProvider.java @@ -219,6 +219,20 @@ public class CephFSDocumentsProvider extends DocumentsProvider { AUTHORITY, toParentDocumentId(documentId)), null, 0); } + public String renameDocument(String documentId, String displayName) + throws FileNotFoundException { + var fromPath = pathFromDocumentId(documentId); + var parentDocumentId = toParentDocumentId(documentId); + var toPath = pathFromDocumentId(parentDocumentId) + "/" + displayName; + executor.executeWithUnchecked(cm -> { + cm.rename(fromPath, toPath); + return null; + }); + cr.notifyChange(DocumentsContract.buildChildDocumentsUri( + AUTHORITY, parentDocumentId), null, 0); + return documentIdFromPath(toPath); + } + public boolean isChildDocument(String parentDocumentId, String documentId) { return documentId.startsWith(parentDocumentId) && documentId.charAt(parentDocumentId.length()) == '/'; @@ -410,6 +424,9 @@ public class CephFSDocumentsProvider extends DocumentsProvider { if (mayWrite(parentStat) && !lcs.isDir()) { flags |= Document.FLAG_SUPPORTS_DELETE; } + if (mayWrite(parentStat)) { + flags |= Document.FLAG_SUPPORTS_RENAME; + } yield flags; } case Document.COLUMN_ICON -> { -- 2.45.2