Skip to content

Commit c7a4ed3

Browse files
committed
docs: Add documentation
Signed-off-by: Dheshan Mohandass <dheshan@mohandass.com>
1 parent 4e77d05 commit c7a4ed3

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

src/bin/diskusage/main.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ struct Arguments {
1919
debug: bool,
2020
}
2121

22+
/// Ensure that the user exists in the database.
23+
/// If the user does not exist, insert the user into the database.
24+
/// Users are stored in a cache to prevent querying the database for the same user multiple times.
25+
///
26+
/// Arguments
27+
/// * `owner` - The user id to check.
28+
/// * `pool` - The database connection pool.
29+
/// * `cache` - The cache to store user ids.
30+
///
31+
/// Returns
32+
/// * Ok(()) if the user exists or is inserted successfully.
33+
/// * Err(sqlx::Error) if an error occurs while inserting the user.
2234
async fn ensure_user_exists(
2335
owner: Option<i32>,
2436
pool: std::sync::Arc<sqlx::Pool<sqlx::Postgres>>,
@@ -47,6 +59,17 @@ async fn ensure_user_exists(
4759
Ok(())
4860
}
4961

62+
/// Process a directory entry.
63+
/// Insert the directory into the database. If the directory already exists, update the directory.
64+
///
65+
/// Arguments
66+
/// * `entry` - The directory entry to process.
67+
/// * `pool` - The database connection pool.
68+
/// * `handle` - The tokio runtime handle.
69+
/// * `cache` - The cache to store user ids.
70+
///
71+
/// Returns
72+
/// * None
5073
fn process_directory(
5174
entry: walkdir::DirEntry,
5275
pool: std::sync::Arc<sqlx::Pool<sqlx::Postgres>>,
@@ -74,6 +97,19 @@ fn process_directory(
7497
});
7598
}
7699

100+
/// Process a file entry.
101+
/// Insert the file into the database. If the file already exists, update the file.
102+
/// If the file is not inserted, retry the insert. Assume the file is not inserted due to
103+
/// its parent directory not being inserted.
104+
///
105+
/// Arguments
106+
/// * `entry` - The file entry to process.
107+
/// * `pool` - The database connection pool.
108+
/// * `handle` - The tokio runtime handle.
109+
/// * `cache` - The cache to store user ids.
110+
///
111+
/// Returns
112+
/// * None
77113
fn process_file(
78114
entry: walkdir::DirEntry,
79115
pool: std::sync::Arc<sqlx::Pool<sqlx::Postgres>>,

src/bin/estimate/main.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ struct Arguments {
1111
/// The path to the directory to estimate.
1212
#[clap(short, long)]
1313
path: String,
14+
/// The number of large files to display.
1415
#[clap(short, long, default_value = "5")]
1516
large_files_count: usize,
17+
/// The offset to start displaying large files.
1618
#[clap(short, long, default_value = "0")]
1719
offset: usize,
1820
}
@@ -82,7 +84,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
8284
let size_gb: BigDecimal = size_mb.clone() / 1024;
8385
let size_tb: BigDecimal = size_gb.clone() / 1024;
8486

85-
log::info!("Estimated size: {:.2} TB = {:.2} GB = {:.2} MB = {:.2} KB = {:.2} bytes", size_tb, size_gb, size_mb, size_kb, total_size);
87+
log::info!(
88+
"Estimated size: {:.2} TB = {:.2} GB = {:.2} MB = {:.2} KB = {:.2} bytes",
89+
size_tb,
90+
size_gb,
91+
size_mb,
92+
size_kb,
93+
total_size
94+
);
8695

8796
let largest_files_query = format!(
8897
r#"
@@ -131,7 +140,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
131140
for i in 0..df_row_count {
132141
let mut row: Vec<String> = vec![];
133142
for series in df.get_columns() {
134-
let value: Result<polars::prelude::AnyValue, polars::prelude::PolarsError> = series.get(i);
143+
let value: Result<polars::prelude::AnyValue, polars::prelude::PolarsError> =
144+
series.get(i);
135145
let value_str = match value {
136146
Ok(value) => value.to_string(),
137147
Err(_) => "".to_string(),
@@ -143,7 +153,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
143153

144154
println!("Largest files in directory:");
145155
println!("{table}")
146-
}).await?;
156+
})
157+
.await?;
147158

148159
Ok(())
149160
}

0 commit comments

Comments
 (0)