Skip to content

Commit b77fa2f

Browse files
committed
handle question variant conflicts
1 parent 3e2da66 commit b77fa2f

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

src/utils.rs

+18-19
Original file line numberDiff line numberDiff line change
@@ -104,31 +104,30 @@ pub(crate) fn pack(lc: &LeetCode<Authorized>, file: Option<std::path::PathBuf>)
104104
.read(true)
105105
.write(true)
106106
.open(GIT_README)?;
107+
let mut write_to_root = true;
107108
if root_readme_file.metadata()?.len() == 0 {
108109
std::io::Write::write_all(&mut root_readme_file, "# LeetCode Solutions\n\n".as_bytes())?;
109-
std::io::Write::write_all(
110-
&mut root_readme_file,
111-
format!(
112-
"- [{title}]({title}/main.{ex})\n",
113-
ex = code_file.language.extension(),
114-
title = code_file.question_title,
115-
)
116-
.as_bytes(),
117-
)?;
118110
} else {
119111
let mut contents = String::new();
120112
std::io::Read::read_to_string(&mut root_readme_file, &mut contents)?;
121-
if !contents.contains(&code_file.question_title) {
122-
std::io::Write::write_all(
123-
&mut root_readme_file,
124-
format!(
125-
"- [{title}]({title}/main.{ex})\n",
126-
ex = code_file.language.extension(),
127-
title = code_file.question_title,
128-
)
129-
.as_bytes(),
130-
)?;
113+
if let Some(i) = contents.find(&code_file.question_title) {
114+
if *contents
115+
.as_bytes()
116+
.get(i + code_file.question_title.len())
117+
.unwrap_or(&b'-')
118+
== b']'
119+
{
120+
// this is important as questions have variation
121+
// like "frog-jump", "frog-jump-ii"
122+
write_to_root = false
123+
}
131124
}
132125
}
126+
if write_to_root {
127+
std::io::Write::write_all(
128+
&mut root_readme_file,
129+
format!("- [{title}]({title}/)\n", title = code_file.question_title,).as_bytes(),
130+
)?;
131+
}
133132
Ok(())
134133
}

0 commit comments

Comments
 (0)