From a70fba4ef163ed7a73619ce1600f0803f46add33 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Mon, 11 Feb 2008 19:14:10 -0700 Subject: [PATCH] webish: add edge metadata to t=json output, including timestamps --- docs/webapi.txt | 59 +++++++++++++++++++++++----------- src/allmydata/test/test_web.py | 11 +++++++ src/allmydata/webish.py | 2 ++ 3 files changed, 53 insertions(+), 19 deletions(-) diff --git a/docs/webapi.txt b/docs/webapi.txt index 7604ce42..5e77a740 100644 --- a/docs/webapi.txt +++ b/docs/webapi.txt @@ -94,7 +94,7 @@ d. examining files or directories GET $URL?t=json - out: json metadata + out: json description of $URL This returns machine-parseable information about the indicated file or directory in the HTTP response body. The JSON always contains a list, and @@ -104,28 +104,49 @@ d. examining files or directories If it is a file, then the information includes file size and URI, like this: - [ 'filenode', { 'ro_uri': file_uri, - 'size': bytes } ] + GET $FILEURL?t=json : + + [ 'filenode', { 'ro_uri': file_uri, + 'size': bytes, + 'metadata': {'ctime': 1202777696.7564139, + 'mtime': 1202777696.7564139, + }, + } ] If it is a directory, then it includes information about the children of - this directory, as a mapping from child name to a set of metadata about the + this directory, as a mapping from child name to a set of data about the child (the same data that would appear in a corresponding GET?t=json of the - child itself). Like this: - - [ 'dirnode', { 'rw_uri': read_write_uri, - 'ro_uri': read_only_uri, - 'children': children } ] - - In the above example, 'children' is a dictionary in which the keys are - child names and the values depend upon whether the child is a file or a - directory: - - 'foo.txt': [ 'filenode', { 'ro_uri': uri, 'size': bytes } ] - 'subdir': [ 'dirnode', { 'rw_uri': rwuri, 'ro_uri': rouri } ] + child itself). The child entries also include metadata about each child, + including creation- and modification- timestamps. The output looks like + this: - note that the value is the same as the JSON representation of the child - object (except that directories do not recurse -- the "children" entry of - the child is omitted). + GET $DIRURL?t=json : + + [ 'dirnode', { 'rw_uri': read_write_uri, + 'ro_uri': read_only_uri, + 'children': [ + 'foo.txt': [ 'filenode', { 'ro_uri': uri, + 'size': bytes, + 'metadata': { + 'ctime': 1202777696.7564139, + 'mtime': 1202777696.7564139, + }, + } ], + 'subdir': [ 'dirnode', { 'rw_uri': rwuri, + 'ro_uri': rouri, + 'metadata': { + 'ctime': 1202778102.7589991, + 'mtime': 1202778111.2160511, + }, + } ], + ] } ] + + In the above example, note how 'children' is a dictionary in which the keys + are child names and the values depend upon whether the child is a file or a + directory. The value is mostly the same as the JSON representation of the + child object (except that directories do not recurse -- the "children" + entry of the child is omitted, and the directory view includes the metadata + that is stored on the directory edge). Then the rw_uri field will be present in the information about a directory if and only if you have read-write access to that directory, diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index eb7fb809..97c92ff1 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -96,6 +96,7 @@ class WebMixin(object): self.BAR_CONTENTS, n, self._bar_txt_uri = self.makefile(0) foo.set_uri("bar.txt", self._bar_txt_uri) + foo.set_uri("empty", res[3][1].get_uri()) sub_uri = res[4][1].get_uri() foo.set_uri("sub", sub_uri) @@ -125,7 +126,12 @@ class WebMixin(object): # public/reedownlee/ # public/reedownlee/nor self.NEWFILE_CONTENTS = "newfile contents\n" + + return foo.get_metadata_for("bar.txt") d.addCallback(_then) + def _got_metadata(metadata): + self._bar_txt_metadata = metadata + d.addCallback(_got_metadata) return d def makefile(self, number): @@ -162,9 +168,14 @@ class WebMixin(object): ["bar.txt", "blockingfile", "empty", "sub"]) kids = data[1]["children"] self.failUnlessEqual(kids["sub"][0], "dirnode") + self.failUnless("metadata" in kids["sub"][1]) + self.failUnless("ctime" in kids["sub"][1]["metadata"]) + self.failUnless("mtime" in kids["sub"][1]["metadata"]) self.failUnlessEqual(kids["bar.txt"][0], "filenode") self.failUnlessEqual(kids["bar.txt"][1]["size"], len(self.BAR_CONTENTS)) self.failUnlessEqual(kids["bar.txt"][1]["ro_uri"], self._bar_txt_uri) + self.failUnlessEqual(kids["bar.txt"][1]["metadata"]["ctime"], + self._bar_txt_metadata["ctime"]) def GET(self, urlpath, followRedirect=False): url = self.webish_url + urlpath diff --git a/src/allmydata/webish.py b/src/allmydata/webish.py index 7341a3f6..4c2c5abe 100644 --- a/src/allmydata/webish.py +++ b/src/allmydata/webish.py @@ -656,11 +656,13 @@ class DirectoryJSONMetadata(rend.Page): kiddata = ("filenode", {'ro_uri': kiduri, 'size': childnode.get_size(), + 'metadata': metadata, }) else: assert IDirectoryNode.providedBy(childnode), (childnode, children,) kiddata = ("dirnode", {'ro_uri': childnode.get_readonly_uri(), + 'metadata': metadata, }) if not childnode.is_readonly(): kiddata[1]['rw_uri'] = childnode.get_uri() -- 2.45.2