Skip to content

Commit

Permalink
fixed LIBRARY_SPLIT = 1 creating "id ~ id" directories
Browse files Browse the repository at this point in the history
  • Loading branch information
9-FS committed Nov 27, 2024
1 parent 126b6a9 commit 4bfa586
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 27 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "MIT"
name = "nhentai_archivist"
readme = "readme.md"
repository = "https://github.com/9-FS/nhentai_archivist"
version = "3.6.1"
version = "3.6.2"

[dependencies]
chrono = { version = "^0.4.0", features = ["serde"] }
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
services:
nhentai_archivist:
container_name: "nhentai_archivist"
image: "ghcr.io/9-fs/nhentai_archivist:3.6.1"
image: "ghcr.io/9-fs/nhentai_archivist:3.6.2"
environment:
HOST_OS: "Unraid"
TZ: "UTC"
Expand Down
30 changes: 12 additions & 18 deletions src/hentai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl Hentai
{
const WORKERS: usize = 5; // number of parallel workers
let cbz_final_filepath: String; //filepath to final cbz in library
let cbz_temp_filepath: String = format!("{}{}/{}", self.library_path, self.id, self.cbz_filename); //filepath to temporary cbz, cbz is created here and when finished moved to final location, roundabout way over temporary cbz filepath in case program gets stopped while creating cbz, so no half finished cbz remains in library
let cbz_temp_filepath: String = format!("{}{}/{}.temp", self.library_path, self.id, self.cbz_filename); //filepath to temporary cbz, cbz is created here and when finished moved to final location, roundabout way over temporary cbz filepath in case program gets stopped while creating cbz, so no half finished cbz remains in library
let comicinfoxml_filepath: String = format!("{}{}/ComicInfo.xml", self.library_path, self.id); // filepath to metadata file if cleanup_temporary_files is false
let f = scaler::Formatter::new()
.set_scaling(scaler::Scaling::None)
Expand All @@ -178,21 +178,12 @@ impl Hentai
let mut zip_writer: zip::ZipWriter<std::fs::File>; // write to zip file


if self.library_split == 0 // no library split
cbz_final_filepath = match self.library_split // determine final cbz filepath
{
cbz_final_filepath = format!("{}{}", self.library_path, self.cbz_filename);
}
else // with library split
{
cbz_final_filepath = format!
(
"{}{}~{}/{}",
self.library_path.to_owned(),
self.id.div_euclid(self.library_split) * self.library_split,
(self.id.div_euclid(self.library_split) + 1) * self.library_split - 1,
self.cbz_filename,
);
}
0 => format!("{}{}", self.library_path, self.cbz_filename), // no library split
1 => format!("{}{}/{}", self.library_path, self.id, self.cbz_filename), // library split into directories with single hentai per directory
_ => format!("{}{}~{}/{}", self.library_path, self.id.div_euclid(self.library_split) * self.library_split, (self.id.div_euclid(self.library_split) + 1) * self.library_split - 1, self.cbz_filename), // library split into directories with multiple hentai per directory
};

if let Ok(o) = tokio::fs::metadata(cbz_final_filepath.as_str()).await
{
Expand Down Expand Up @@ -298,10 +289,13 @@ impl Hentai

if cleanup_temporary_files // if temporary files should be cleaned up
{
match tokio::fs::remove_dir_all(format!("{}{}", self.library_path, self.id)).await // cleanup, delete image directory
for image_filename in self.images_filename.iter() // cleanup, don't just delete directory because with library split = 1 would also delete final hentai cbz
{
Ok(_) => log::debug!("Deleted \"{}{}/\".", self.library_path, self.id),
Err(e) => log::warn!("Deleting \"{}{}/\" failed with: {e}", self.library_path, self.id),
match tokio::fs::remove_file(format!("{}{}/{}", self.library_path, self.id, image_filename)).await // delete images
{
Ok(_) => log::debug!("Deleted \"{}{}/{}\".", self.library_path, self.id, image_filename),
Err(e) => log::warn!("Deleting \"{}{}/{}\" failed with: {e}", self.library_path, self.id, image_filename),
}
}
}
else // if temporary files should not be cleaned up
Expand Down

0 comments on commit 4bfa586

Please sign in to comment.