2007-08-17 20:23:16 +00:00
|
|
|
|
2007-10-12 05:29:23 +00:00
|
|
|
import urllib
|
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)
|
|
|
|
except UnknownAliasError, 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:
|
|
|
|
print >>stderr, """
|
2011-08-01 22:01:08 +00:00
|
|
|
'tahoe %s' can only unlink directory entries, so a path must be given.""" % (command,)
|
2011-01-22 07:42:12 +00:00
|
|
|
return 1
|
|
|
|
|
2008-05-20 02:28:50 +00:00
|
|
|
url = nodeurl + "uri/%s" % urllib.quote(rootcap)
|
|
|
|
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,):
|
2010-06-07 01:02:15 +00:00
|
|
|
print >>stdout, format_http_success(resp)
|
2007-10-12 05:29:23 +00:00
|
|
|
return 0
|
2007-08-17 20:23:16 +00:00
|
|
|
|
2010-06-07 01:02:15 +00:00
|
|
|
print >>stderr, format_http_error("ERROR", resp)
|
2007-08-17 20:23:16 +00:00
|
|
|
return 1
|