do not create padding files
This commit is contained in:
parent
af7a0ddb4f
commit
8bb029bbc0
2 changed files with 22 additions and 10 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue