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
a563af18
Commit
a563af18
authored
Oct 11, 2022
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify rust version
parent
05d5030a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
42 deletions
+3
-42
rust/src/main.rs
rust/src/main.rs
+3
-42
No files found.
rust/src/main.rs
View file @
a563af18
...
...
@@ -4,10 +4,8 @@ use serde::Serialize;
use
std
::
collections
::
HashMap
;
use
std
::{
fs
::
DirEntry
,
fs
::
File
,
io
::{
Read
,
Write
},
path
::
PathBuf
,
path
::
Path
,
io
::{
Read
,
Write
,
stdout
}
,
sync
::{
Arc
,
Mutex
},
};
...
...
@@ -70,10 +68,8 @@ struct Tree {
fn
construct_fs_tree
(
cur_tree
:
Option
<
Tree
>
,
path
:
&
PathBuf
,
dev_whitelist
:
&
Vec
<
u64
>
,
ignored_dirs
:
&
Vec
<
PathBuf
>
,
)
->
Result
<
Tree
>
{
let
mut
cur_tree
=
match
cur_tree
{
let
cur_tree
=
match
cur_tree
{
Some
(
cur_tree
)
=>
cur_tree
,
None
=>
Tree
{
stat
:
Some
(
nix
::
sys
::
stat
::
lstat
(
path
)
?
.into
()),
...
...
@@ -81,18 +77,6 @@ fn construct_fs_tree(
},
};
if
!
dev_whitelist
.iter
()
.any
(|
x
|
match
&
cur_tree
.stat
{
Some
(
stat
)
if
stat
.st_dev
==
*
x
=>
true
,
_
=>
false
,
})
{
return
Ok
(
cur_tree
);
}
if
ignored_dirs
.iter
()
.any
(|
x
|
path
.starts_with
(
x
))
{
cur_tree
.ignored
=
true
;
return
Ok
(
cur_tree
);
}
let
entries
:
Vec
<
Result
<
DirEntry
,
_
>>
=
match
std
::
fs
::
read_dir
(
&
path
)
{
Ok
(
x
)
=>
x
,
_
=>
return
Ok
(
cur_tree
),
...
...
@@ -117,8 +101,6 @@ fn construct_fs_tree(
tree
=
construct_fs_tree
(
Some
(
tree
),
&
entry
.path
(),
dev_whitelist
,
ignored_dirs
,
)
.unwrap
();
}
...
...
@@ -189,35 +171,14 @@ fn construct_fs_tree(
}
fn
main
()
->
Result
<
()
>
{
let
ignored_dirs
=
[
"/opt/slapgrid"
,
"/srv/slapgrid"
]
.iter
()
.map
(
PathBuf
::
from
)
.collect
();
let
disk_partitions
=
[
"."
,
"/"
,
"/boot"
];
let
dev_whitelist
=
disk_partitions
.iter
()
.filter_map
(|
p
|
match
nix
::
sys
::
stat
::
lstat
(
&
PathBuf
::
from
(
p
))
{
Ok
(
stat
)
=>
Some
(
stat
.st_dev
),
Err
(
_
)
=>
None
,
})
.collect
();
let
tree
=
construct_fs_tree
(
None
,
&
PathBuf
::
from
(
"."
),
&
dev_whitelist
,
&
ignored_dirs
,
)
?
;
let
result
=
serde_json
::
to_string_pretty
(
&
tree
)
?
;
let
path
=
Path
::
new
(
"result.json"
);
let
mut
file
=
File
::
create
(
&
path
)
.unwrap
();
file
.write_all
(
result
.as_bytes
())
.unwrap
();
stdout
()
.write_all
(
result
.as_bytes
())
.unwrap
();
Ok
(())
}
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