Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/plugins/terminal/src/android/AlpineDocumentProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -336,4 +364,4 @@ private static String getMimeType(File file) {
return "application/octet-stream";
}
}
}
}