Do not create empty folders for padding files

This commit is contained in:
Igor Katson 2024-11-07 15:58:03 +00:00
parent cc002a4ed3
commit ecc094a444
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5

View file

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