2021-06-03 13:39:13 +00:00
|
|
|
"""
|
|
|
|
Ported to Python 3.
|
|
|
|
"""
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
from __future__ import absolute_import
|
|
|
|
from __future__ import division
|
2019-03-24 13:09:10 +00:00
|
|
|
from __future__ import print_function
|
2007-08-17 20:23:16 +00:00
|
|
|
|
2021-06-03 13:39:13 +00:00
|
|
|
from future.utils import PY2
|
|
|
|
if PY2:
|
|
|
|
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
|
|
|
|
|
2021-05-04 15:22:12 +00:00
|
|
|
from urllib.parse import quote as url_quote
|
2010-06-07 01:02:15 +00:00
|
|
|
from allmydata.scripts.common_http import do_http, format_http_success, format_http_error
|
2010-02-11 02:43:18 +00:00
|
|
|
from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path, \
|
|
|
|
UnknownAliasError
|
2007-08-17 20:23:16 +00:00
|
|
|
|
2011-08-01 22:01:08 +00:00
|
|
|
def unlink(options, command="unlink"):
|
2007-08-17 20:23:16 +00:00
|
|
|
"""
|
|
|
|
@return: a Deferred which eventually fires with the exit code
|
|
|
|
"""
|
2008-08-01 18:46:24 +00:00
|
|
|
nodeurl = options['node-url']
|
|
|
|
aliases = options.aliases
|
|
|
|
where = options.where
|
|
|
|
stdout = options.stdout
|
|
|
|
stderr = options.stderr
|
|
|
|
|
2007-10-12 05:29:23 +00:00
|
|
|
if nodeurl[-1] != "/":
|
|
|
|
nodeurl += "/"
|
2010-02-11 02:43:18 +00:00
|
|
|
try:
|
|
|
|
rootcap, path = get_alias(aliases, where, DEFAULT_ALIAS)
|
2019-03-28 11:45:28 +00:00
|
|
|
except UnknownAliasError as e:
|
2010-06-07 01:02:15 +00:00
|
|
|
e.display(stderr)
|
2010-02-11 02:43:18 +00:00
|
|
|
return 1
|
2011-01-22 07:42:12 +00:00
|
|
|
if not path:
|
2019-03-24 13:09:10 +00:00
|
|
|
print("""
|
|
|
|
'tahoe %s' can only unlink directory entries, so a path must be given.""" % (command,), file=stderr)
|
2011-01-22 07:42:12 +00:00
|
|
|
return 1
|
|
|
|
|
2021-05-04 15:22:12 +00:00
|
|
|
url = nodeurl + "uri/%s" % url_quote(rootcap)
|
2008-05-20 02:28:50 +00:00
|
|
|
url += "/" + escape_path(path)
|
2007-08-17 20:23:16 +00:00
|
|
|
|
2007-10-12 05:29:23 +00:00
|
|
|
resp = do_http("DELETE", url)
|
2007-08-17 20:23:16 +00:00
|
|
|
|
2007-10-12 05:29:23 +00:00
|
|
|
if resp.status in (200,):
|
2019-03-24 13:09:10 +00:00
|
|
|
print(format_http_success(resp), file=stdout)
|
2007-10-12 05:29:23 +00:00
|
|
|
return 0
|
2007-08-17 20:23:16 +00:00
|
|
|
|
2019-03-24 13:09:10 +00:00
|
|
|
print(format_http_error("ERROR", resp), file=stderr)
|
2007-08-17 20:23:16 +00:00
|
|
|
return 1
|