writecap, readcap, metadata = e
precondition(isinstance(writecap, (str,type(None))), writecap)
precondition(isinstance(readcap, (str,type(None))), readcap)
-
+
# We now allow packing unknown nodes, provided they are valid
# for this type of directory.
child_node = self._create_and_validate_node(writecap, readcap, namex)
abandoned = self.abandoned
parent = self.parent
childname = self.childname
-
+
# has_changed is set when writeChunk is called, not when the write occurs, so
# it is correct to optimize out the commit if it is False at the close call.
has_changed = self.has_changed
def _abandon_any_heisenfiles(self, userpath, direntry):
request = "._abandon_any_heisenfiles(%r, %r)" % (userpath, direntry)
self.log(request, level=OPERATIONAL)
-
+
assert isinstance(userpath, str), userpath
# First we synchronously mark all heisenfiles matching the userpath or direntry
return self.copy_file(source, target)
if isinstance(target, (LocalDirectoryTarget, TahoeDirectoryTarget)):
- # We're copying to an existing directory -- make sure that we
+ # We're copying to an existing directory -- make sure that we
# have target names for everything
for (name, source) in sources:
if name is None and isinstance(source, TahoeFileSource):
piece += "s"
fmt_pieces.append(piece)
fmt = " ".join(fmt_pieces)
-
+
rc = 0
for (encoding_error, row) in rows:
if encoding_error:
u"tiny_litdir": (nm.create_from_cap(tiny_litdir_uri), {}),
}
d = c.create_dirnode(kids)
-
+
def _created(dn):
self.failUnless(isinstance(dn, dirnode.DirectoryNode))
self.failUnless(dn.is_mutable())
self.failUnless("RW-MUT" in rep)
return dn.list()
d.addCallback(_created)
-
+
def _check_kids(children):
self.failUnlessReallyEqual(set(children.keys()),
set([one_nfc, u"two", u"mut", u"fut", u"fro",
frona_node, frona_metadata = children[u"fro-unic"]
emptylit_node, emptylit_metadata = children[u"empty_litdir"]
tinylit_node, tinylit_metadata = children[u"tiny_litdir"]
-
+
self.failUnlessReallyEqual(one_node.get_size(), 3)
self.failUnlessReallyEqual(one_node.get_uri(), one_uri)
self.failUnlessReallyEqual(one_node.get_readonly_uri(), one_uri)
self.failUnless(isinstance(one_metadata, dict), one_metadata)
-
+
self.failUnlessReallyEqual(two_node.get_size(), 14861)
self.failUnlessReallyEqual(two_node.get_uri(), setup_py_uri)
self.failUnlessReallyEqual(two_node.get_readonly_uri(), setup_py_uri)
self.failUnlessEqual(two_metadata["metakey"], "metavalue")
-
+
self.failUnlessReallyEqual(mut_node.get_uri(), mut_write_uri)
self.failUnlessReallyEqual(mut_node.get_readonly_uri(), mut_read_uri)
self.failUnless(isinstance(mut_metadata, dict), mut_metadata)
-
+
self.failUnless(fut_node.is_unknown())
self.failUnlessReallyEqual(fut_node.get_uri(), future_write_uri)
self.failUnlessReallyEqual(fut_node.get_readonly_uri(), "ro." + future_read_uri)
u"tiny_litdir": (nm.create_from_cap(tiny_litdir_uri), {}),
}
d = c.create_immutable_dirnode(kids)
-
+
def _created(dn):
self.failUnless(isinstance(dn, dirnode.DirectoryNode))
self.failIf(dn.is_mutable())
self.cap = cap
return dn.list()
d.addCallback(_created)
-
+
def _check_kids(children):
self.failUnlessReallyEqual(set(children.keys()),
set([one_nfc, u"two", u"fut", u"futna", u"empty_litdir", u"tiny_litdir"]))
return d2
d.addCallback(_check_kids)
-
+
d.addCallback(lambda ign: nm.create_from_cap(self.cap.to_string()))
d.addCallback(lambda dn: dn.list())
d.addCallback(_check_kids)
previously_disappeared = self._get_count('drop_upload.files_disappeared')
d = defer.Deferred()
-
+
# Note: this relies on the fact that we only get one IN_CLOSE_WRITE notification per file
# (otherwise we would get a defer.AlreadyCalledError). Should we be relying on that?
self.uploader.set_uploaded_callback(d.callback)
try:
tmpdir = tempfile.mkdtemp()
for fname in TEST_FILENAMES:
- open(os.path.join(tmpdir, fname), 'w').close()
+ open(os.path.join(tmpdir, fname), 'w').close()
# Use Unicode API under Windows or MacOS X
if sys.platform in ('win32', 'darwin'):
self.failUnlessRaises(FilenameEncodingError,
listdir_unicode,
u'/dummy')
-
+
# We're trying to list a directory whose name cannot be represented in
# the filesystem encoding. This should fail.
mock_getfilesystemencoding.return_value = 'ascii'
_reload()
self.failUnlessReallyEqual(unicode_platform(), matrix[self.platform])
-
+
@patch('sys.getfilesystemencoding')
@patch('os.listdir')
def test_listdir_unicode(self, mock_listdir, mock_getfilesystemencoding):
def test_convert_error(self):
self.failUnlessReallyEqual(sftpd._convert_error(None, "request"), None)
-
+
d = defer.succeed(None)
d.addCallback(lambda ign:
self.shouldFailWithSFTPError(sftp.FX_FAILURE, "_convert_error SFTPError",
d.addCallback(lambda ign:
self.shouldFailWithSFTPError(sftp.FX_NO_SUCH_FILE, "removefile ''",
self.handler.removeFile, ""))
-
+
# removing a directory should fail
d.addCallback(lambda ign:
self.shouldFailWithSFTPError(sftp.FX_PERMISSION_DENIED, "removeFile tiny_lit_dir",
self.failUnless(CSS_STYLE.search(res), res)
d.addCallback(_check)
return d
-
+
def test_GET_FILEURL_uri_missing(self):
d = self.GET(self.public_url + "/foo/missing?t=uri")
d.addBoth(self.should404, "test_GET_FILEURL_uri_missing")
self.failUnless(re.search(get_sub, res), res)
d.addCallback(_check)
- # look at a readonly directory
+ # look at a readonly directory
d.addCallback(lambda res:
self.GET(self.public_url + "/reedownlee", followRedirect=True))
def _check2(res):
d = self.POST(self.public_url +
"/foo/?t=start-manifest&ophandle=%d" % ophandle,
followRedirect=True)
- # By following the initial redirect, we collect the ophandle
+ # By following the initial redirect, we collect the ophandle
# we've just created.
return d
- # Create a collected ophandle, then collect it after 23 hours
+ # Create a collected ophandle, then collect it after 23 hours
# and 59 seconds to make sure that it is still there.
d = _make_collected_ophandle(133)
d.addCallback(lambda ign:
d.addCallback(lambda ign: self.GET("%s%s?t=json" % (self.rourl, str(name))))
d.addCallback(_check_json, expect_rw_uri=False)
-
+
# TODO: check that getting t=info from the Info link in the ro directory
# works, and does not include the writecap URI.
return d
lonely_uri = "URI:LIT:n5xgk" # LIT for "one"
mut_write_uri = "URI:SSK:vfvcbdfbszyrsaxchgevhmmlii:euw4iw7bbnkrrwpzuburbhppuxhc3gwxv26f6imekhz7zyw2ojnq"
mut_read_uri = "URI:SSK-RO:e3mdrzfwhoq42hy5ubcz6rp3o4:ybyibhnp3vvwuq2vaw2ckjmesgkklfs6ghxleztqidihjyofgw7q"
-
+
# This method tests mainly dirnode, but we'd have to duplicate code in order to
# test the dirnode and web layers separately.
-
+
# 'lonely' is a valid LIT child, 'ro' is a mutant child with an SSK-RO readcap,
- # and 'write-in-ro' is a mutant child with an SSK writecap in the ro_uri field.
+ # and 'write-in-ro' is a mutant child with an SSK writecap in the ro_uri field.
# When the directory is read, the mutants should be silently disposed of, leaving
# their lonely sibling.
# We don't test the case of a retrieving a cap from the encrypted rw_uri field,
u"write-in-ro": (mutant_write_in_ro_child, {}),
}
d = c.create_immutable_dirnode(kids)
-
+
def _created(dn):
self.failUnless(isinstance(dn, dirnode.DirectoryNode))
self.failIf(dn.is_mutable())
self.failUnlessReallyEqual(numkids, 3)
return self.rootnode.list()
d.addCallback(_check_data)
-
+
# Now when we use the real directory listing code, the mutants should be absent.
def _check_kids(children):
self.failUnlessReallyEqual(sorted(children.keys()), [u"lonely"])
error = MustBeDeepImmutableError(kind + " used in an immutable context", name)
else:
error = MustBeReadonlyError(kind + " used in a read-only context", name)
-
+
except BadURIError, e:
error = e
charset = get_arg(req, "_charset", "utf-8")
name = name.decode(charset)
replace = boolean_of_arg(get_arg(req, "replace", "true"))
-
+
# We mustn't pass childcap for the readcap argument because we don't
# know whether it is a read cap. Passing a read cap as the writecap
# argument will work (it ends up calling NodeMaker.create_from_cap,