Commit f167804a authored by Xavier Thompson's avatar Xavier Thompson

Switch to json

parent f9c8da8c
......@@ -20,38 +20,45 @@ cdef Str sep = Str("/")
cdef char * file_fmt = """\
[{}]
type = file
sha256 = {}
sha512 = {}
{}
"{}": {{
"type": "file",
"sha256": "{}",
"sha512": "{}",
"stat": {}
}},
"""
cdef char * dir_fmt = """\
[{}]
type = dir
{}
"{}": {{
"type": "dir",
"entries": ["{}"],
"stat": {}
}},
"""
cdef char * symlink_fmt = """\
[{}]
type = symlink
target = {}
{}
"{}": {{
"type": "symlink",
"target": "{}",
"stat": {}
}},
"""
cdef char * stat_fmt = """\
dev = {}
ino = {}
mode = {}
nlink = {}
owner = {{ uid = {}, gid = {} }}
rdev = {}
sizes = {{ size = {}, blksize = {}, blocks = {} }}
times = {{ atim = [{}, {}], mtim = [{}, {}], ctim = [{}, {}] }}"""
cdef char * stat_fmt = """{{
"dev": {},
"ino": {},
"mode": {},
"nlink": {},
"uid": {},
"gid": {},
"rdev": {},
"size": {},
"blksize": {},
"blocks": {},
"atim": [{}, {}],
"mtim": [{}, {}],
"ctim": [{}, {}]
}}"""
cdef lock Scheduler scheduler = Scheduler()
......@@ -71,7 +78,7 @@ cdef cypclass Node activable:
void write_node(self, FILE * stream): pass
Str to_toml(self):
Str to_json(self):
return format(stat_fmt,
self.stat.st_dev,
self.stat.st_ino,
......@@ -134,12 +141,12 @@ cdef cypclass DirNode(Node):
self.text = format(dir_fmt,
self.path,
self.to_toml(),
Str('", "').join(entries) if entries is not NULL else Str(""),
self.to_json(),
)
for active_child in self.children:
active_child.build_node(NULL)
pass
void write_node(self, FILE * stream):
os.write(self.text, stream)
......@@ -194,9 +201,12 @@ cdef cypclass FileNode(Node):
self.path,
self.sha256 if self.sha256 else Str("<error>"),
self.sha512 if self.sha512 else Str("<error>"),
self.to_toml(),
self.to_json(),
)
void write_node(self, FILE * stream):
os.write(self.text, stream)
cdef cypclass SymlinkNode(Node):
Str target
......@@ -210,9 +220,12 @@ cdef cypclass SymlinkNode(Node):
self.text = format(symlink_fmt,
self.path,
target,
self.to_toml(),
self.to_json(),
)
void write_node(self, FILE * stream):
os.write(self.text, stream)
cdef int scan(iso Str path) nogil:
root = Node.node(consume path)
......@@ -223,7 +236,9 @@ cdef int scan(iso Str path) nogil:
scheduler.join()
os.write(Str("{"), os.stdout)
root.write_node(os.stdout)
os.write(Str(' "": \n}'), os.stdout)
return 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment