Skip to content

Commit cc679ca

Browse files
committed
Construct book build path outside process_book
1 parent fc2bcf3 commit cc679ca

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/cmd/shelf.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::env::current_dir;
21
use std::fs::File;
32
use std::io::Read;
43
use std::io::Write;
@@ -69,18 +68,16 @@ fn update_index(
6968
Ok(())
7069
}
7170

72-
fn process_book(path: &str, shelf_url: &PathBuf) -> Result<BookContext> {
71+
fn process_book(path: &str, books_dir: &PathBuf, shelf_url: &PathBuf) -> Result<BookContext> {
7372
let book_dir = path.try_resolve()?;
7473
let book_dir = std::fs::canonicalize(book_dir)?;
7574
let mut book = MDBook::load(book_dir)?;
7675

7776
// Build book
7877
let title = book.config.book.title.clone().unwrap();
79-
let mut path = current_dir()?;
80-
path.push(BOOKSHELF_DIR);
81-
path.push(BOOKS_DIR);
82-
path.push(title);
83-
book.config.build.build_dir = path;
78+
let mut build_path = books_dir.to_owned();
79+
build_path.push(title);
80+
book.config.build.build_dir = build_path;
8481
// Create back reference to bookshelf
8582
book.config.book.shelf_url = Some(shelf_url.to_owned());
8683
book.build()?;
@@ -131,6 +128,10 @@ pub fn execute(_args: &ArgMatches) -> Result<()> {
131128
writeln!(summary_file, "# Summary")?;
132129
writeln!(summary_file, "- [Index](./{INDEX_MD_FILE})")?;
133130

131+
let mut books_build_dir = std::env::current_dir()?;
132+
books_build_dir.push(BOOKSHELF_DIR);
133+
books_build_dir.push(BOOKS_DIR);
134+
134135
for sb in &shelf_config.books {
135136
let book_path = if let Some(url) = &sb.git_url {
136137
prepare_git(sb, url)
@@ -142,7 +143,7 @@ pub fn execute(_args: &ArgMatches) -> Result<()> {
142143
};
143144

144145
if let Some(path) = book_path {
145-
let update_context = process_book(&path, &shelf_url)?;
146+
let update_context = process_book(&path, &books_build_dir, &shelf_url)?;
146147
let _ = update_index(
147148
&mut index_file,
148149
&mut summary_file,

0 commit comments

Comments
 (0)