Skip to content

Commit c578646

Browse files
Copilotploiu
andcommitted
Improve documentation and clarity of generate_database_from_files function
Co-authored-by: ploiu <43047560+ploiu@users.noreply.github.com>
1 parent 517da32 commit c578646

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/repository/mod.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,12 @@ pub fn initialize_db() -> Result<()> {
7272
/// Generates database entries from the existing files directory structure.
7373
/// This walks the directory tree depth-first, creating folders before files at each level.
7474
///
75+
/// This function is designed to be called with `parent_folder = None` to start the
76+
/// generation from the root files directory. The `parent_folder` parameter exists
77+
/// to satisfy the API contract but the actual recursive traversal is handled internally.
78+
///
7579
/// # Arguments
76-
/// * `parent_folder` - The parent folder id in the database, or None for root level
80+
/// * `parent_folder` - Should be None to start from root. Any other value is a no-op.
7781
/// * `con` - Database connection
7882
///
7983
/// # Returns
@@ -82,14 +86,12 @@ pub fn generate_database_from_files(
8286
parent_folder: Option<u32>,
8387
con: &Connection,
8488
) -> Result<()> {
85-
let base_path = if parent_folder.is_none() {
86-
file_dir()
87-
} else {
88-
// For recursive calls, we need to build the path from the parent folder
89-
// This is handled by passing the path directly via internal helper
89+
// This function only processes the root level; recursion is handled internally
90+
if parent_folder.is_some() {
9091
return Ok(());
91-
};
92+
}
9293

94+
let base_path = file_dir();
9395
let path = Path::new(&base_path);
9496
if !path.exists() || !path.is_dir() {
9597
return Ok(());
@@ -105,7 +107,7 @@ pub fn generate_database_from_files(
105107
return Ok(());
106108
}
107109

108-
generate_database_from_files_internal(&base_path, parent_folder, con)
110+
generate_database_from_files_internal(&base_path, None, con)
109111
}
110112

111113
/// Internal helper that walks the directory tree and creates database entries.

0 commit comments

Comments
 (0)