Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Less reask for file changes #722

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

vivienrobert-wefox
Copy link
Contributor

No description provided.

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())?;
Copy link
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)

src/lib.rs Outdated
@@ -186,14 +190,40 @@ fn plan(ctx: &Ctx, source_files: Vec<SourceFile>, variables: &Variables) -> Resu
Ok(actions)
}

fn decide_update_mode(
Copy link
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.

src/lib.rs Outdated
ctx: &Ctx,
actions: &[Action],
variables: &Variables,
) -> Result<Vec<(FileMeta, FileMeta)>> {
Copy link
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)

//TODO accumulate Result (and error)
fn execute(ctx: &Ctx, actions: &[Action], variables: &Variables) -> Result<()> {
fn execute(
Copy link
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)

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
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())

src/lib.rs Outdated
@@ -365,6 +415,10 @@ where
let src = src.as_ref();
loop {
match mode {
UpdateMode::Auto => {
// should not enter here
Copy link
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)

let tracked = load_tracked(target_folder)?;
let infos = tracked
.files
.get(&source)
Copy link
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

}

fn save_tracked(tracked: &TrackedFiles, target_folder: &Path) -> Result<()> {
serde_json::to_writer(
Copy link
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

}

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
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?

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
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?

fn from(variables: Variables) -> Self {
variables
.tree()
.iter()
Copy link
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 ?

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.

None yet

2 participants