2021-06-03 09:39:13 -04:00
|
|
|
"""
|
|
|
|
Ported to Python 3.
|
|
|
|
"""
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
from __future__ import absolute_import
|
|
|
|
from __future__ import division
|
2019-03-24 14:09:10 +01:00
|
|
|
from __future__ import print_function
|
2007-08-17 13:23:16 -07:00
|
|
|
|
2021-06-03 09:39:13 -04: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 11:22:12 -04:00
|
|
|
from urllib.parse import quote as url_quote
|
2010-06-06 18:02:15 -07:00
|
|
|
from allmydata.scripts.common_http import do_http, format_http_success, format_http_error
|
2010-02-10 18:43:18 -08:00
|
|
|
from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path, \
|
|
|
|
UnknownAliasError
|
2007-08-17 13:23:16 -07:00
|
|
|
|
2011-08-01 15:01:08 -07:00
|
|
|
def unlink(options, command="unlink"):
|
2007-08-17 13:23:16 -07:00
|
|
|
"""
|
|
|
|
@return: a Deferred which eventually fires with the exit code
|
|
|
|
"""
|
2008-08-01 11:46:24 -07:00
|
|
|
nodeurl = options['node-url']
|
|
|
|
aliases = options.aliases
|
|
|
|
where = options.where
|
|
|
|
stdout = options.stdout
|
|
|
|
stderr = options.stderr
|
|
|
|
|
2007-10-11 22:29:23 -07:00
|
|
|
if nodeurl[-1] != "/":
|
|
|
|
nodeurl += "/"
|
2010-02-10 18:43:18 -08:00
|
|
|
try:
|
|
|
|
rootcap, path = get_alias(aliases, where, DEFAULT_ALIAS)
|
2019-03-28 12:45:28 +01:00
|
|
|
except UnknownAliasError as e:
|
2010-06-06 18:02:15 -07:00
|
|
|
e.display(stderr)
|
2010-02-10 18:43:18 -08:00
|
|
|
return 1
|
2011-01-22 00:42:12 -07:00
|
|
|
if not path:
|
2019-03-24 14:09:10 +01:00
|
|
|
print("""
|
|
|
|
'tahoe %s' can only unlink directory entries, so a path must be given.""" % (command,), file=stderr)
|
2011-01-22 00:42:12 -07:00
|
|
|
return 1
|
|
|
|
|
2021-05-04 11:22:12 -04:00
|
|
|
url = nodeurl + "uri/%s" % url_quote(rootcap)
|
2008-05-19 19:28:50 -07:00
|
|
|
url += "/" + escape_path(path)
|
2007-08-17 13:23:16 -07:00
|
|
|
|
2007-10-11 22:29:23 -07:00
|
|
|
resp = do_http("DELETE", url)
|
2007-08-17 13:23:16 -07:00
|
|
|
|
2007-10-11 22:29:23 -07:00
|
|
|
if resp.status in (200,):
|
2019-03-24 14:09:10 +01:00
|
|
|
print(format_http_success(resp), file=stdout)
|
2007-10-11 22:29:23 -07:00
|
|
|
return 0
|
2007-08-17 13:23:16 -07:00
|
|
|
|
2019-03-24 14:09:10 +01:00
|
|
|
print(format_http_error("ERROR", resp), file=stderr)
|
2007-08-17 13:23:16 -07:00
|
|
|
return 1
|