Commit f1e7f6f8 authored by Ophélie Gagnard's avatar Ophélie Gagnard

src/main.{pyx,cpp}:

- Switch to SHA256 (instead of MD5).
- Add back the files stats.
parent 0b8d1321
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -12,7 +12,7 @@ from runtime.unistd cimport pid_t, execlp, fork, sleep
from runtime.wait cimport wait, waitpid
from stdlib.stat cimport Stat, dev_t
from stdlib.digest cimport MessageDigest, md5sum, sha1sum, sha256sum, sha512sum
from stdlib.digest cimport MessageDigest, sha256sum, sha512sum
from stdlib.fmt cimport sprintf
from stdlib.string cimport string
from stdlib.dirent cimport DIR, struct_dirent, opendir, readdir, closedir
......@@ -43,12 +43,12 @@ cdef cypclass Node activable:
pass
void format_node(self):
#''' light data version
''' light data version
self.formatted = sprintf("""{"path": "%s"}\n""",
self.path,
)
#'''
''' full data version
#''' full data version
self.formatted = sprintf("""{"path": "%s", "stat": %s}\n""",
self.path,
self.st.to_json(),
......@@ -124,12 +124,12 @@ cdef cypclass DirNode(Node):
active_child.build_node(NULL, dev_whitelist, ignore_paths)
void format_node(self):
#''' light data version
''' light data version
self.formatted = sprintf("""{"path": "%s/"}\n""",
self.path,
)
#'''
''' full data version
#''' full data version
self.formatted = sprintf("""{"path": "%s/", "stat": %s}\n""",
self.path,
self.st.to_json(),
......@@ -149,8 +149,6 @@ cdef enum:
BUFSIZE = 64 * 1024
cdef cypclass FileNode(Node):
string md5_data
string sha1_data
string sha256_data
string sha512_data
bint error
......@@ -162,8 +160,6 @@ cdef cypclass FileNode(Node):
void build_node(self, lock cyplist[dev_t] dev_whitelist, lock cyplist[string] ignore_paths):
cdef unsigned char buffer[BUFSIZE]
cdef bint eof = False
cdef bint md5_ok
cdef bint sha1_ok
cdef bint sha256_ok
cdef bint sha512_ok
......@@ -174,17 +170,13 @@ cdef cypclass FileNode(Node):
self.format_node()
return
md5 = MessageDigest(md5sum())
sha1 = MessageDigest(sha1sum())
sha256 = MessageDigest(sha256sum())
sha512 = MessageDigest(sha512sum())
md5_ok = md5 is not NULL
sha1_ok = sha1 is not NULL
sha256_ok = sha256 is not NULL
sha512_ok = sha512 is not NULL
while not eof and (md5_ok or sha1_ok or sha256_ok or sha512_ok):
while not eof and (sha256_ok or sha512_ok):
size = fread(buffer, 1, BUFSIZE, file)
if size != BUFSIZE:
self.error = ferror(file)
......@@ -192,16 +184,12 @@ cdef cypclass FileNode(Node):
break
eof = True
if md5_ok: md5_ok = md5.update(buffer, size) == 0
if sha1_ok: sha1_ok = sha1.update(buffer, size) == 0
if sha256_ok: sha256_ok = sha256.update(buffer, size) == 0
if sha512_ok: sha512_ok = sha512.update(buffer, size) == 0
fclose(file)
if not self.error:
if md5_ok: self.md5_data = md5.hexdigest()
if sha1_ok: self.sha1_data = sha1.hexdigest()
if sha256_ok: self.sha256_data = sha256.hexdigest()
if sha512_ok: self.sha512_data = sha512.hexdigest()
......@@ -211,18 +199,16 @@ cdef cypclass FileNode(Node):
if self.error:
Node.format_node(self)
else:
#''' light data version
self.formatted = sprintf("""{"path": "%s", "hash": {"md5": "%s"}}\n""",
''' light data version
self.formatted = sprintf("""{"path": "%s", "hash": {"sha256": "%s"}}\n""",
self.path,
self.md5_data,
self.sha256_data,
)
#'''
''' full data version
self.formatted = sprintf("""{"path": "%s", "stat": %s, "hash": {"md5": "%s", "sha1": "%s", "sha256": "%s", "sha512": "%s"}}\n""",
#''' full data version
self.formatted = sprintf("""{"path": "%s", "stat": %s, "hash": {"sha256": "%s", "sha512": "%s"}}\n""",
self.path,
self.st.to_json(),
self.md5_data,
self.sha1_data,
self.sha256_data,
self.sha512_data,
)
......@@ -248,13 +234,13 @@ cdef cypclass SymlinkNode(Node):
if self.error:
Node.format_node(self)
else:
#''' light data version
''' light data version
self.formatted = sprintf("""{"path": "%s", "target": "%s"}\n""",
self.path,
self.target,
)
#'''
''' full data version
#''' full data version
self.formatted = sprintf("""{"path": "%s", "stat": %s, "target": "%s"}\n""",
self.path,
self.st.to_json(),
......
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