Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Read-write ROSAF - to replace SAF #376

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
51 changes: 24 additions & 27 deletions primitiveFTPd/src/org/primftpd/filesystem/RoSafFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,13 @@ public boolean isFile() {
}

public boolean isWritable() {
// TODO writing with SAF cursor/uri api
//boolean result = writable;
boolean result = false;
boolean result = writable;
logger.trace("[{}] isWritable() -> {}", name, result);
return result;
}

public boolean isRemovable() {
// TODO writing with SAF cursor/uri api
//boolean result = deletable;
boolean result = false;
boolean result = deletable;
logger.trace("[{}] isRemovable() -> {}", name, result);
return result;
}
Expand Down Expand Up @@ -231,32 +227,33 @@ public boolean mkdir() {

public boolean delete() {
logger.trace("[{}] delete()", name);
// TODO writing with SAF cursor/uri api
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// Uri docUri = DocumentsContract.buildDocumentUriUsingTree(startUrl, documentId);
// logger.trace("delete(): docUri: '{}'", docUri);
// try {
// return DocumentsContract.deleteDocument(contentResolver, docUri);
// } catch (FileNotFoundException e) {
// logger.error("could not delete " + name, e);
// }
// }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Uri docUri = DocumentsContract.buildDocumentUriUsingTree(startUrl, documentId);
logger.trace("delete(): docUri: '{}'", docUri);
try {
return DocumentsContract.deleteDocument(contentResolver, docUri);
} catch (FileNotFoundException e) {
logger.error("could not delete " + name, e);
}
}
return false;
}

public boolean move(RoSafFile<T> destination) {
logger.trace("[{}] move({})", name, destination.getAbsolutePath());
// TODO writing with SAF cursor/uri api
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// Uri docUri = DocumentsContract.buildDocumentUriUsingTree(startUrl, documentId);
// logger.trace("move(): docUri: '{}'", docUri);
// try {
// Uri newNameUri = DocumentsContract.renameDocument(contentResolver, docUri, destination.getName());
// return newNameUri != null;
// } catch (FileNotFoundException e) {
// logger.error("could not rename " + name, e);
// }
// }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Uri docUri = DocumentsContract.buildDocumentUriUsingTree(startUrl, documentId);
logger.trace("move(): docUri: '{}'", docUri);
try {
Uri newNameUri = DocumentsContract.renameDocument(contentResolver, docUri, destination.getName());
if (newNameUri != null && !docUri.equals(newNameUri)) {
documentId = DocumentsContract.getDocumentId(newNameUri);
}
return newNameUri != null;
} catch (FileNotFoundException e) {
logger.error("could not rename " + name, e);
}
}
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ public T getFile(String file) {
if (childCursor.isAfterLast()) {
// not found
if (i == parts.size() - 1) {
// TODO we are read only -> there is no upload anyway
// probably upload -> create object just with name
logger.trace(" calling createFile() for not found doc: {}", currentPart);
return createFileNonExistent(contentResolver, startUrl, currentPart, Utils.toPath(parts), pftpdService);
Expand Down