Skip to content

Commit 9c8a895

Browse files
author
meow
committed
cargo fmt
1 parent 9b2712c commit 9c8a895

4 files changed

Lines changed: 41 additions & 19 deletions

File tree

implants/lib/eldritch/stdlib/eldritch-libfile/src/fake.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,11 @@ impl FileLibrary for FileLibraryFake {
172172
}
173173
}
174174

175-
fn list(&self, path: Option<String>, dir_self: Option<bool>) -> Result<Vec<BTreeMap<String, Value>>, String> {
175+
fn list(
176+
&self,
177+
path: Option<String>,
178+
dir_self: Option<bool>,
179+
) -> Result<Vec<BTreeMap<String, Value>>, String> {
176180
let path = path.unwrap_or_else(|| "/".to_string());
177181
let mut root = self.root.lock();
178182
let parts = Self::normalize_path(&path);

implants/lib/eldritch/stdlib/eldritch-libfile/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,11 @@ pub trait FileLibrary {
158158
///
159159
/// **Errors**
160160
/// - Returns an error string if listing fails.
161-
fn list(&self, path: Option<String>, dir_self: Option<bool>) -> Result<Vec<BTreeMap<String, Value>>, String>;
161+
fn list(
162+
&self,
163+
path: Option<String>,
164+
dir_self: Option<bool>,
165+
) -> Result<Vec<BTreeMap<String, Value>>, String>;
162166

163167
#[eldritch_method]
164168
/// Lists all named pipes on the system.

implants/lib/eldritch/stdlib/eldritch-libfile/src/std/list_impl.rs

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,21 @@ use eldritch_core::Value;
1313
#[cfg(unix)]
1414
use nix::unistd::{Gid, Group, Uid, User};
1515
#[cfg(feature = "stdlib")]
16+
use spin::RwLock;
17+
#[cfg(feature = "stdlib")]
1618
use std::fs;
1719
#[cfg(feature = "stdlib")]
1820
use std::path::Path;
1921
#[cfg(feature = "stdlib")]
2022
use std::sync::Arc;
21-
#[cfg(feature="stdlib")]
22-
use spin::RwLock;
2323
#[cfg(feature = "stdlib")]
2424
use std::time::UNIX_EPOCH;
2525

2626
#[cfg(feature = "stdlib")]
27-
pub fn list(path: Option<String>, dir_self: Option<bool>) -> Result<Vec<BTreeMap<String, Value>>, String> {
27+
pub fn list(
28+
path: Option<String>,
29+
dir_self: Option<bool>,
30+
) -> Result<Vec<BTreeMap<String, Value>>, String> {
2831
let path = path.unwrap_or_else(|| {
2932
::std::env::current_dir()
3033
.map(|p| p.to_string_lossy().to_string())
@@ -42,7 +45,7 @@ pub fn list(path: Option<String>, dir_self: Option<bool>) -> Result<Vec<BTreeMap
4245
#[cfg(not(feature = "stdlib"))]
4346
pub fn list(
4447
_path: Option<alloc::string::String>,
45-
dir_self: Option<bool>
48+
dir_self: Option<bool>,
4649
) -> Result<
4750
alloc::vec::Vec<alloc::collections::BTreeMap<alloc::string::String, eldritch_core::Value>>,
4851
alloc::string::String,
@@ -66,7 +69,7 @@ fn list_impl(path: String, dir_self: bool) -> AnyhowResult<Vec<BTreeMap<String,
6669
if !path_buf.is_dir() || dir_self {
6770
final_res.push(create_dict_from_file(&path_buf)?);
6871
}
69-
72+
7073
// for dir, show subcontents
7174
if path_buf.is_dir() {
7275
for entry in fs::read_dir(&path_buf)? {
@@ -86,35 +89,42 @@ fn list_impl(path: String, dir_self: bool) -> AnyhowResult<Vec<BTreeMap<String,
8689

8790
// get the timestamps of a metadata object and return it as a dictionary
8891
#[cfg(feature = "stdlib")]
89-
fn get_times_dict(metadata: std::fs::Metadata, mtime: std::io::Result<std::time::SystemTime>) -> Value {
92+
fn get_times_dict(
93+
metadata: std::fs::Metadata,
94+
mtime: std::io::Result<std::time::SystemTime>,
95+
) -> Value {
9096
// create dictionary for times data
9197
let mut times: BTreeMap<Value, Value> = BTreeMap::new();
9298

9399
// add changed time (it's already in epoch format) if we're in unix
94-
#[cfg(unix)] {
100+
#[cfg(unix)]
101+
{
95102
use std::os::unix::fs::MetadataExt;
96-
times.insert(Value::String("changed".to_string()), Value::Int(metadata.ctime()));
103+
times.insert(
104+
Value::String("changed".to_string()),
105+
Value::Int(metadata.ctime()),
106+
);
97107
}
98108

99109
// add time information
100110
let timestamps = [
101111
("modified", mtime),
102112
("created", metadata.created()),
103-
("accessed", metadata.accessed())
113+
("accessed", metadata.accessed()),
104114
];
105115
for timestamp_req in timestamps {
106116
// if getting the timestamp was successful, add it
107117
if let Ok(timestamp) = timestamp_req.1 {
108118
// convert timestamp to epoch
109119
let secs = match timestamp.duration_since(UNIX_EPOCH) {
110120
Ok(duration) => duration.as_secs() as i64,
111-
Err(err) => -(err.duration().as_secs() as i64)
121+
Err(err) => -(err.duration().as_secs() as i64),
112122
};
113123

114124
// add timestamp to dict
115125
times.insert(Value::String(timestamp_req.0.to_string()), Value::Int(secs));
116126
}
117-
};
127+
}
118128

119129
// insert times section to the dictionary
120130
return Value::Dictionary(Arc::new(RwLock::new(times)));
@@ -233,14 +243,14 @@ mod tests {
233243
assert!(f.contains_key("absolute_path"));
234244
assert!(f.contains_key("times"));
235245
// check times sub-dict
236-
if let Value::Dictionary(d) = &f["times"] {
237-
let inner = d.read();
246+
if let Value::Dictionary(d) = &f["times"] {
247+
let inner = d.read();
238248
assert!(inner.contains_key(&Value::String("modified".into())));
239249
assert!(inner.contains_key(&Value::String("accessed".into())));
240250
assert!(inner.contains_key(&Value::String("created".into())));
241-
#[cfg(unix)]
242-
assert!(inner.contains_key(&Value::String("changed".into())));
243-
}
251+
#[cfg(unix)]
252+
assert!(inner.contains_key(&Value::String("changed".into())));
253+
}
244254

245255
// check modified string
246256
assert!(f.contains_key("modified"));

implants/lib/eldritch/stdlib/eldritch-libfile/src/std/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ impl FileLibrary for StdFileLibrary {
7878
is_file_impl::is_file(path)
7979
}
8080

81-
fn list(&self, path: Option<String>, dir_self: Option<bool>) -> Result<Vec<BTreeMap<String, Value>>, String> {
81+
fn list(
82+
&self,
83+
path: Option<String>,
84+
dir_self: Option<bool>,
85+
) -> Result<Vec<BTreeMap<String, Value>>, String> {
8286
list_impl::list(path, dir_self)
8387
}
8488

0 commit comments

Comments
 (0)