mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-02-22 02:16:42 +00:00
ADD_FILE Eliot action
This commit is contained in:
parent
a37085ebcc
commit
bcfd2e8ea0
@ -25,6 +25,39 @@ from allmydata.uri import wrap_dirnode_cap
|
|||||||
from pycryptopp.cipher.aes import AES
|
from pycryptopp.cipher.aes import AES
|
||||||
from allmydata.util.dictutil import AuxValueDict
|
from allmydata.util.dictutil import AuxValueDict
|
||||||
|
|
||||||
|
from eliot import (
|
||||||
|
ActionType,
|
||||||
|
Field,
|
||||||
|
)
|
||||||
|
from eliot.twisted import (
|
||||||
|
DeferredContext,
|
||||||
|
)
|
||||||
|
|
||||||
|
NAME = Field.for_types(
|
||||||
|
u"name",
|
||||||
|
[unicode],
|
||||||
|
u"The name linking the parent to this node.",
|
||||||
|
)
|
||||||
|
|
||||||
|
METADATA = Field.for_types(
|
||||||
|
u"metadata",
|
||||||
|
[dict],
|
||||||
|
u"Data about a node.",
|
||||||
|
)
|
||||||
|
|
||||||
|
OVERWRITE = Field.for_types(
|
||||||
|
u"overwrite",
|
||||||
|
[bool],
|
||||||
|
u"True to replace an existing file of the same name, "
|
||||||
|
u"false to fail with a collision error.",
|
||||||
|
)
|
||||||
|
|
||||||
|
ADD_FILE = ActionType(
|
||||||
|
u"dirnode:add-file",
|
||||||
|
[NAME, METADATA, OVERWRITE],
|
||||||
|
[],
|
||||||
|
u"Add a new file as a child of a directory.",
|
||||||
|
)
|
||||||
|
|
||||||
def update_metadata(metadata, new_metadata, now):
|
def update_metadata(metadata, new_metadata, now):
|
||||||
"""Updates 'metadata' in-place with the information in 'new_metadata'.
|
"""Updates 'metadata' in-place with the information in 'new_metadata'.
|
||||||
@ -596,17 +629,20 @@ class DirectoryNode(object):
|
|||||||
resulting FileNode to the directory at the given name. I return a
|
resulting FileNode to the directory at the given name. I return a
|
||||||
Deferred that fires (with the IFileNode of the uploaded file) when
|
Deferred that fires (with the IFileNode of the uploaded file) when
|
||||||
the operation completes."""
|
the operation completes."""
|
||||||
name = normalize(namex)
|
with ADD_FILE(name=namex, metadata=metadata, overwrite=overwrite).context():
|
||||||
if self.is_readonly():
|
name = normalize(namex)
|
||||||
return defer.fail(NotWriteableError())
|
if self.is_readonly():
|
||||||
# XXX should pass reactor arg
|
d = DeferredContext(defer.fail(NotWriteableError()))
|
||||||
d = self._uploader.upload(uploadable, progress=progress)
|
else:
|
||||||
d.addCallback(lambda results:
|
# XXX should pass reactor arg
|
||||||
self._create_and_validate_node(results.get_uri(), None,
|
d = DeferredContext(self._uploader.upload(uploadable, progress=progress))
|
||||||
name))
|
d.addCallback(lambda results:
|
||||||
d.addCallback(lambda node:
|
self._create_and_validate_node(results.get_uri(), None,
|
||||||
self.set_node(name, node, metadata, overwrite))
|
name))
|
||||||
return d
|
d.addCallback(lambda node:
|
||||||
|
self.set_node(name, node, metadata, overwrite))
|
||||||
|
|
||||||
|
return d.addActionFinish()
|
||||||
|
|
||||||
def delete(self, namex, must_exist=True, must_be_directory=False, must_be_file=False):
|
def delete(self, namex, must_exist=True, must_be_directory=False, must_be_file=False):
|
||||||
"""I remove the child at the specific name. I return a Deferred that
|
"""I remove the child at the specific name. I return a Deferred that
|
||||||
|
Loading…
x
Reference in New Issue
Block a user