do not create padding files

This commit is contained in:
Igor Katson 2024-10-14 15:53:50 +01:00
parent af7a0ddb4f
commit 8bb029bbc0
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
2 changed files with 22 additions and 10 deletions

View file

@ -157,14 +157,20 @@ impl TorrentStorage for FilesystemStorage {
full_path.push(relative_path);
std::fs::create_dir_all(full_path.parent().context("bug: no parent")?)?;
let file = 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"))?
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")
})?,
)
} else {
// create_new does not seem to work with read(true), so calling this twice.
OpenOptions::new()
@ -177,9 +183,9 @@ impl TorrentStorage for FilesystemStorage {
&full_path
)
})?;
OpenOptions::new().read(true).write(true).open(&full_path)?
OpenedFile::new(OpenOptions::new().read(true).write(true).open(&full_path)?)
};
files.push(OpenedFile::new(file));
files.push(file);
}
self.opened_files = files;

View file

@ -14,6 +14,12 @@ impl OpenedFile {
}
}
pub fn new_dummy() -> Self {
Self {
file: RwLock::new(None),
}
}
pub fn take(&self) -> anyhow::Result<Option<File>> {
let mut f = self.file.write();
Ok(f.take())