~xdavidwu/saf-cephfs

4e132c3aa5ee9505e0683a0c3fb5bb7d8f77a799 — Pinghao Wu a month ago 944b4b1
CephFSDocumentsProvider: support simple delete

TODO reduce stat call, notify list changes
1 files changed, 24 insertions(+), 3 deletions(-)

M src/main/java/org/safcephfs/CephFSDocumentsProvider.java
M src/main/java/org/safcephfs/CephFSDocumentsProvider.java => src/main/java/org/safcephfs/CephFSDocumentsProvider.java +24 -3
@@ 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;
	}