Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
scan-filesystem
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Xavier Thompson
scan-filesystem
Commits
f9c8da8c
Commit
f9c8da8c
authored
Oct 12, 2022
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve scan.pyx
parent
6f79ca87
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
70 deletions
+49
-70
scan.pyx
scan.pyx
+49
-70
No files found.
scan.pyx
View file @
f9c8da8c
...
...
@@ -21,6 +21,7 @@ cdef Str sep = Str("/")
cdef
char
*
file_fmt
=
"""
\
[{}]
type = file
sha256 = {}
sha512 = {}
{}
...
...
@@ -29,12 +30,14 @@ sha512 = {}
cdef
char
*
dir_fmt
=
"""
\
[{}]
type = dir
{}
"""
cdef
char
*
symlink_fmt
=
"""
\
[{}]
type = symlink
target = {}
{}
...
...
@@ -66,9 +69,9 @@ cdef cypclass Node activable:
void
build_node
(
self
):
pass
void
format_node
(
self
):
pass
void
write_node
(
self
,
FILE
*
stream
):
pass
Str
format_stat
(
self
):
Str
to_toml
(
self
):
return
format
(
stat_fmt
,
self
.
stat
.
st_dev
,
self
.
stat
.
st_ino
,
...
...
@@ -88,15 +91,13 @@ cdef cypclass Node activable:
self
.
stat
.
st_ctim
.
tv_nsec
,
)
void
write_node
(
self
,
FILE
*
stream
):
pass
@
staticmethod
iso
Node
creat
e
(
iso
Str
path
):
iso
Node
nod
e
(
iso
Str
path
):
cdef
Node
node
p
=
<
Str
>
consume
path
s
=
os
.
stat
(
p
)
if
s
is
NULL
:
node
=
NULL
return
NULL
elif
s
.
is_symlink
():
node
=
SymlinkNode
(
p
,
s
)
elif
s
.
is_dir
():
...
...
@@ -104,7 +105,7 @@ cdef cypclass Node activable:
elif
s
.
is_regular
():
node
=
FileNode
(
p
,
s
)
else
:
node
=
NULL
return
NULL
del
p
,
s
return
consume
node
...
...
@@ -125,23 +126,21 @@ cdef cypclass DirNode(Node):
continue
path
=
self
.
path
if
Str
(
path
[
-
1
])
!=
sep
:
path
=
path
+
sep
path
=
path
+
sep
path
=
path
+
name
child
=
Node
.
creat
e
(
consume
path
)
child
=
Node
.
nod
e
(
consume
path
)
if
child
is
not
NULL
:
self
.
children
.
append
(
activate
(
consume
child
))
self
.
format_node
()
for
active_child
in
self
.
children
:
active_child
.
build_node
(
NULL
)
void
format_node
(
self
):
self
.
text
=
format
(
dir_fmt
,
self
.
path
,
self
.
format_stat
(),
self
.
to_toml
(),
)
for
active_child
in
self
.
children
:
active_child
.
build_node
(
NULL
)
pass
void
write_node
(
self
,
FILE
*
stream
):
os
.
write
(
self
.
text
,
stream
)
while
self
.
children
.
__len__
()
>
0
:
...
...
@@ -150,9 +149,7 @@ cdef cypclass DirNode(Node):
child
.
write_node
(
stream
)
cdef
enum
:
CHUNK
=
64
*
1024
cdef
enum
:
CHUNK
=
64
*
1024
cdef
cypclass
FileNode
(
Node
):
Str
sha256
...
...
@@ -162,89 +159,71 @@ cdef cypclass FileNode(Node):
Node
.
__init__
(
self
,
path
,
stat
)
void
build_node
(
self
):
cdef
bint
sha256_ok
cdef
bint
sha512_ok
cdef
bint
error
=
False
cdef
bint
sha256_ok
=
False
cdef
bint
sha512_ok
=
False
cdef
FILE
*
file
=
os
.
open
(
self
.
path
,
'rb'
)
if
file
is
NULL
:
self
.
format_node
()
return
file
=
os
.
open
(
self
.
path
,
'rb'
)
if
file
is
not
NULL
:
sha256
=
hashlib
.
Hash
(
hashlib
.
sha256
())
sha512
=
hashlib
.
Hash
(
hashlib
.
sha512
())
sha256
=
hashlib
.
Hash
(
hashlib
.
sha256
())
sha512
=
hashlib
.
Hash
(
hashlib
.
sha512
())
sha256_ok
=
sha256
is
not
NULL
sha512_ok
=
sha512
is
not
NULL
sha256_ok
=
sha256
is
not
NULL
sha512_ok
=
sha512
is
not
NULL
while
(
sha256_ok
or
sha512_ok
):
s
=
os
.
read
(
file
,
CHUNK
)
if
s
is
NULL
:
error
=
Tru
e
break
while
(
sha256_ok
or
sha512_ok
):
s
=
os
.
read
(
file
,
CHUNK
)
if
s
is
NULL
:
sha256_ok
=
sha512_ok
=
Fals
e
break
if
sha256_ok
:
sha256_ok
=
sha256
.
update
(
s
)
==
0
if
sha512_ok
:
sha512_ok
=
sha512
.
update
(
s
)
==
0
if
sha256_ok
:
sha256_ok
=
sha256
.
update
(
s
)
==
0
if
sha512_ok
:
sha512_ok
=
sha512
.
update
(
s
)
==
0
if
s
.
__len__
()
!=
CHUNK
:
break
if
s
.
__len__
()
!=
CHUNK
:
break
os
.
close
(
file
)
os
.
close
(
file
)
if
not
error
:
self
.
sha256
=
sha256
.
hexdigest
()
if
sha256_ok
else
NULL
self
.
sha512
=
sha512
.
hexdigest
()
if
sha512_ok
else
NULL
self
.
format_node
()
void
format_node
(
self
):
sha256
=
self
.
sha256
if
self
.
sha256
else
Str
(
"<error>"
)
sha512
=
self
.
sha512
if
self
.
sha512
else
Str
(
"<error>"
)
self
.
text
=
format
(
file_fmt
,
self
.
path
,
s
ha256
,
s
ha512
,
self
.
format_stat
(),
s
elf
.
sha256
if
self
.
sha256
else
Str
(
"<error>"
)
,
s
elf
.
sha512
if
self
.
sha512
else
Str
(
"<error>"
)
,
self
.
to_toml
(),
)
void
write_node
(
self
,
FILE
*
stream
):
os
.
write
(
self
.
text
,
stream
)
cdef
cypclass
SymlinkNode
(
Node
):
Str
target
void
build_node
(
self
):
self
.
target
=
os
.
readlink
(
self
.
path
,
self
.
stat
.
st_size
)
self
.
format_node
()
target
=
os
.
readlink
(
self
.
path
,
self
.
stat
.
st_size
)
if
target
is
NULL
:
target
=
Str
(
"<error>"
)
void
format_node
(
self
):
target
=
self
.
target
if
self
.
target
is
not
NULL
else
Str
(
"<error>"
)
self
.
target
=
target
self
.
text
=
format
(
symlink_fmt
,
self
.
path
,
target
,
self
.
format_stat
(),
self
.
to_toml
(),
)
void
write_node
(
self
,
FILE
*
stream
):
os
.
write
(
self
.
text
,
stream
)
cdef
int
scan
(
iso
Str
root
)
nogil
:
node
=
Node
.
create
(
consume
root
)
if
node
is
NULL
:
cdef
int
scan
(
iso
Str
path
)
nogil
:
root
=
Node
.
node
(
consume
path
)
if
root
is
NULL
:
return
-
1
active_node
=
activate
(
consume
node
)
active_node
.
build_node
(
NULL
)
root
.
build_node
()
scheduler
.
join
()
node
=
consume
active_node
node
.
write_node
(
os
.
stdout
)
root
.
write_node
(
os
.
stdout
)
return
0
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment