implement removeExportDirectory

Not yet called by Command.Export.

WebDAV needs this to clean up empty collections. Also, example.sh turned
out to not be cleaning up directories when removing content
from them, so it made sense for it to use this.

Remote.Directory did not need it, and since its cleanup method for empty
directories is more efficient than what Command.Export will need to do
to find empty directories, it uses Nothing so that extra work can be
avoided.

This commit was sponsored by Thom May on Patreon.
This commit is contained in:
Joey Hess 2017-09-15 13:15:47 -04:00
parent 78a67f29f8
commit 9f4ffe65e9
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
9 changed files with 156 additions and 87 deletions

View file

@ -176,6 +176,17 @@ replying with `UNSUPPORTED-REQUEST` is acceptable.
`REMOVE-FAILURE`.
If the content was already not present in the remote, it should
respond with `REMOVE-SUCCESS`.
* `REMOVEEXPORTDIRECTORY Directory`
Requests the remote remove an exported directory.
If the remote does not use directories, or automatically cleans up
empty directories, this does not need to be implemented.
The directory will be in the form of a relative path, and may contain path
separators, whitespace, and other special characters.
Typically the directory will be empty, but it could possbly contain
files or other directories, and it's ok to remove those.
The remote responds with either `REMOVEEXPORTDIRECTORY-SUCCESS`
or `REMOVEEXPORTDIRECTORY-FAILURE`.
Should not fail if the directory was already removed.
* `RENAMEEXPORT Key NewName`
Requests the remote rename a file stored on it from the previously
provided Name to the NewName.
@ -261,6 +272,10 @@ while it's handling a request.
Indicates that a `RENAMEEXPORT` was done successfully.
* `RENAMEEXPORT-FAILURE Key`
Indicates that a `RENAMEEXPORT` failed for whatever reason.
* `REMOVEEXPORTDIRECTORY-SUCCESS`
Indicates that a `REMOVEEXPORTDIRECTORY` was done successfully.
* `REMOVEEXPORTDIRECTORY-FAILURE`
Indicates that a `REMOVEEXPORTDIRECTORY` failed for whatever reason.
* `UNSUPPORTED-REQUEST`
Indicates that the special remote does not know how to handle a request.

View file

@ -264,6 +264,15 @@ while read line; do
key="$2"
doremove "$key" "$exportlocation"
;;
REMOVEEXPORTDIRECTORY)
shift 1
dir="$@"
if [ ! -d "$dir" ] || rm -rf "$mydirectory/$dir"; then
echo REMOVEEXPORTDIRECTORY-SUCCESS
else
echo REMOVEEXPORTDIRECTORY-FAILURE
fi
;;
RENAMEEXPORT)
key="$2"
shift 2