cap = options.cap
stdout = options.stdout
stderr = options.stderr
- aliasfile = os.path.join(nodedir, "private", "aliases")
- cap = uri.from_string_dirnode(cap).to_string()
assert ":" not in alias
assert " " not in alias
- # probably check for others..
+
+ old_aliases = get_aliases(nodedir)
+ if alias in old_aliases:
+ print >>stderr, "Alias '%s' already exists!" % alias
+ return 1
+ aliasfile = os.path.join(nodedir, "private", "aliases")
+ cap = uri.from_string_dirnode(cap).to_string()
f = open(aliasfile, "a")
f.write("%s: %s\n" % (alias, cap))
f.close()
alias = options.alias
stdout = options.stdout
stderr = options.stderr
- aliasfile = os.path.join(nodedir, "private", "aliases")
assert ":" not in alias
assert " " not in alias
+ old_aliases = get_aliases(nodedir)
+ if alias in old_aliases:
+ print >>stderr, "Alias '%s' already exists!" % alias
+ return 1
+
+ aliasfile = os.path.join(nodedir, "private", "aliases")
+
nodeurl = options['node-url']
if not nodeurl.endswith("/"):
nodeurl += "/"
self.tahoe_url = uribase + urllib.quote(aliases["tahoe"])
self.tahoe_subdir_url = self.tahoe_url + "/subdir"
self.two_url = uribase + urllib.quote(aliases["two"])
+ self.two_uri = aliases["two"]
d.addCallback(_stash_urls)
+ d.addCallback(lambda res: self.do_cli("create-alias", "two")) # dup
+ def _check_create_duplicate((rc,stdout,stderr)):
+ self.failIfEqual(rc, 0)
+ self.failUnless("Alias 'two' already exists!" in stderr)
+ aliases = get_aliases(self.getdir("client0"))
+ self.failUnlessEqual(aliases["two"], self.two_uri)
+ d.addCallback(_check_create_duplicate)
+
+ d.addCallback(lambda res: self.do_cli("add-alias", "added", self.two_uri))
+ def _check_add((rc,stdout,stderr)):
+ self.failUnlessEqual(rc, 0)
+ self.failUnless("Alias 'added' added" in stdout)
+ d.addCallback(_check_add)
+
+ # check add-alias with a duplicate
+ d.addCallback(lambda res: self.do_cli("add-alias", "two", self.two_uri))
+ def _check_add_duplicate((rc,stdout,stderr)):
+ self.failIfEqual(rc, 0)
+ self.failUnless("Alias 'two' already exists!" in stderr)
+ aliases = get_aliases(self.getdir("client0"))
+ self.failUnlessEqual(aliases["two"], self.two_uri)
+ d.addCallback(_check_add_duplicate)
+
def _test_urls(junk):
self._test_webopen([], self.tahoe_url)
self._test_webopen(["/"], self.tahoe_url)