Skip to content

Commit

Permalink
Do not create empty folders for padding files
Browse files Browse the repository at this point in the history
  • Loading branch information
ikatson committed Nov 7, 2024
1 parent cc002a4 commit ecc094a
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions crates/librqbit/src/storage/filesystem/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,19 @@ impl TorrentStorage for FilesystemStorage {
let relative_path = &file_details.relative_filename;
full_path.push(relative_path);

if file_details.attrs.padding {
files.push(OpenedFile::new_dummy());
continue;
};
std::fs::create_dir_all(full_path.parent().context("bug: no parent")?)?;
let file = if file_details.attrs.padding {
OpenedFile::new_dummy()
} else if meta.options.allow_overwrite {
OpenedFile::new(
OpenOptions::new()
.create(true)
.truncate(false)
.read(true)
.write(true)
.open(&full_path)
.with_context(|| {
format!("error opening {full_path:?} in read/write mode")
})?,
)
let f = if meta.options.allow_overwrite {
OpenOptions::new()
.create(true)
.truncate(false)
.read(true)
.write(true)
.open(&full_path)
.with_context(|| format!("error opening {full_path:?} in read/write mode"))?
} else {
// create_new does not seem to work with read(true), so calling this twice.
OpenOptions::new()
Expand All @@ -183,9 +181,9 @@ impl TorrentStorage for FilesystemStorage {
&full_path
)
})?;
OpenedFile::new(OpenOptions::new().read(true).write(true).open(&full_path)?)
OpenOptions::new().read(true).write(true).open(&full_path)?
};
files.push(file);
files.push(OpenedFile::new(f));
}

self.opened_files = files;
Expand Down

0 comments on commit ecc094a

Please sign in to comment.