Skip to content

Less reask for file changes - #722

Draft
vivienrobert-wefox wants to merge 12 commits into
ffizer:masterfrom
vivienrobert-wefox:feature/less_reask_for_file_changes
Draft

Less reask for file changes#722
vivienrobert-wefox wants to merge 12 commits into
ffizer:masterfrom
vivienrobert-wefox:feature/less_reask_for_file_changes

Conversation

@vivienrobert-wefox

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread src/lib.rs Outdated
debug!("Saving metadata");
timeline::save_options(&used_variables, &ctx.cmd_opt.src, &ctx.cmd_opt.dst_folder)?;

timeline::save_metas_for_source(new_metas, &ctx.cmd_opt.dst_folder, "global".into())?;

@IgorLaborieWefox IgorLaborieWefox Jan 8, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤌 nitpick: If you transform a &str to a String, You can use String::from("global") or "global".to_string() to be more explicit for the reader (and the compiler)

Comment thread src/lib.rs Outdated
Ok(actions)
}

fn decide_update_mode(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 thought: I do not like this method, every argument has the same type, so it's prone to error (caller can easily swap 2 args.)
Because this function is private, that's not a big deal.

Comment thread src/lib.rs Outdated
ctx: &Ctx,
actions: &[Action],
variables: &Variables,
) -> Result<Vec<(FileMeta, FileMeta)>> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤌 nitpick: maybe return a struct instead of the tuple to add meaningful name (see previous comment)

Comment thread src/lib.rs

//TODO accumulate Result (and error)
fn execute(ctx: &Ctx, actions: &[Action], variables: &Variables) -> Result<()> {
fn execute(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤌 nitpick: my damaged-by-Java mind prefers to see a method on Ctx instead of that function.

Just for your information, you can have multiple impl blocs in Rust, even in different modules. (but the type should be define in the crate)

Comment thread src/lib.rs Outdated
// let source = &ctx.cmd_opt.src;
let target_folder = &ctx.cmd_opt.dst_folder;
let past_metas = timeline::get_stored_metas_for_source(target_folder, "global".into())?;
let mut new_metas = Vec::new();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤌 nitpick: here I prefer vec![] or a Vec::with_capacity(actions.len())

Comment thread src/lib.rs Outdated
loop {
match mode {
UpdateMode::Auto => {
// should not enter here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤌 nitpick: if you are sure of that, use the unreachable!() macro (it's panicking)

Comment thread src/timeline/files.rs Outdated
let tracked = load_tracked(target_folder)?;
let infos = tracked
.files
.get(&source)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 suggestion: you can avoid the cloned if you remove instead of the get

Comment thread src/timeline/files.rs Outdated
}

fn save_tracked(tracked: &TrackedFiles, target_folder: &Path) -> Result<()> {
serde_json::to_writer(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 suggestion: introduce local variables to avoid this nesting

Comment thread src/timeline/files.rs Outdated
}

pub(crate) fn get_meta(base_folder: &Path, relative_path: &Path) -> Result<FileMeta> {
let h = Code::Sha2_256.digest(&fs::read(base_folder.join(relative_path))?);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 thought: need to fully read the file to compute the hash.
Maybe there is a way to use a buffered reader?

Comment thread src/timeline/files.rs Outdated
pub(crate) fn get_meta(base_folder: &Path, relative_path: &Path) -> Result<FileMeta> {
let h = Code::Sha2_256.digest(&fs::read(base_folder.join(relative_path))?);
let info = FileMeta {
key: relative_path.to_string_lossy().to_string(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 thought: Why not use a PathBuf in the `FileMeta?

Comment thread src/timeline/options.rs
fn from(variables: Variables) -> Self {
variables
.tree()
.iter()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 thought: maybe there is an into_iter() to avoid clone ?

@davidB
davidB force-pushed the master branch 2 times, most recently from f1196a8 to 0face17 Compare September 17, 2025 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants