diff --git a/src/plugins/terminal/src/android/AlpineDocumentProvider.java b/src/plugins/terminal/src/android/AlpineDocumentProvider.java index 38fdc6712..f69e58315 100644 --- a/src/plugins/terminal/src/android/AlpineDocumentProvider.java +++ b/src/plugins/terminal/src/android/AlpineDocumentProvider.java @@ -172,6 +172,33 @@ public void deleteDocument(String documentId) throws FileNotFoundException { } } + @Override + public String renameDocument(String documentId, String displayName) throws FileNotFoundException { + File file = getFileForDocId(documentId); + File parent = file.getParentFile(); + if (parent == null) { + throw new FileNotFoundException("Failed to rename root document with id " + documentId); + } + if (displayName == null || displayName.trim().isEmpty()) { + throw new FileNotFoundException("Failed to rename document with id " + documentId); + } + if (displayName.equals(file.getName())) { + return documentId; + } + if (displayName.contains(File.separator)) { + throw new FileNotFoundException("Invalid display name for rename: " + displayName); + } + + File target = new File(parent, displayName); + if (target.exists()) { + throw new FileNotFoundException("Target already exists: " + target.getAbsolutePath()); + } + if (!file.renameTo(target)) { + throw new FileNotFoundException("Failed to rename document with id " + documentId); + } + return getDocIdForFile(target); + } + @Override public String getDocumentType(String documentId) throws FileNotFoundException { File file = getFileForDocId(documentId); @@ -258,6 +285,7 @@ private void includeFile(MatrixCursor result, String docId, File file) throws Fi File parentFile = file.getParentFile(); if (parentFile != null && parentFile.canWrite()) { flags = flags | DocumentsContract.Document.FLAG_SUPPORTS_DELETE; + flags = flags | DocumentsContract.Document.FLAG_SUPPORTS_RENAME; } String displayName = file.getName(); @@ -336,4 +364,4 @@ private static String getMimeType(File file) { return "application/octet-stream"; } } -} \ No newline at end of file +}