Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File preallocation does not work after its priority is changed from "do not download" #7732

Closed
HanabishiRecca opened this issue Sep 7, 2024 · 6 comments

Comments

@HanabishiRecca
Copy link
Contributor

libtorrent version (or branch): 2.0.10
platform/architecture: Linux

File preallocation does not work after its priority is changed from "do not download".
It is reproducible if you try to download additional files on a partial torrent.

I see that open_file_impl intentionally checks for dont_download priority.

// files with priority 0 should always be sparse
if (m_file_priority.end_index() > file && m_file_priority[file] == dont_download)
mode |= aux::open_mode::sparse;

But the problem is, set_file_priority opens the file before updating the priority.

if (old_prio == dont_download && new_prio != dont_download)
{
// move stuff out of the part file
std::shared_ptr<aux::file_mapping> f = open_file(sett, i, aux::open_mode::write, ec);
if (ec)
{
prio = m_file_priority;
return;
}


This patch fixes the issue:

--- a/src/mmap_storage.cpp
+++ b/src/mmap_storage.cpp
@@ -164,6 +164,7 @@ error_code translate_error(std::error_code const& err, bool const write)
 			if (old_prio == dont_download && new_prio != dont_download)
 			{
 				// move stuff out of the part file
+				m_file_priority[i] = new_prio;
 				std::shared_ptr<aux::file_mapping> f = open_file(sett, i, aux::open_mode::write, ec);
 				if (ec)
 				{

But I'm not sure how appropriate it is. What do you think, @arvidn?

@ValeZAA
Copy link

ValeZAA commented Sep 14, 2024

I had a torrent 100%, then switched off file, then deleted file, then enabled file. It allocates 0 byte file on the disk with sparse metadata of correct size of that file. There is no bug...

Qbittorrent 5.0.0beta1 still has those issues: no rehashing of specific folders or files without full rehashing, Tixati has it; issues with restarting torrents if you delete specific files without first disabling them...

@HanabishiRecca
Copy link
Contributor Author

HanabishiRecca commented Sep 14, 2024

It allocates 0 byte file on the disk with sparse metadata of correct size of that file. There is no bug...

I don't really get what you are trying to say. Preallocation is supposed to create a file with its full size. Like fallocate -l SIZE file.
There is a bug and my patch fixes it.

@ValeZAA
Copy link

ValeZAA commented Sep 14, 2024

Preallocation is supposed to create a file with its full size.

I am not sure such a mode makes any sense, but sure, if there is undefined behaviour where you first open file and then change open properties... Can you submit a patch? Fork this repo, click edit in the file in your repo, click pull request on this repo, submit changes.

@HanabishiRecca
Copy link
Contributor Author

I am not sure such a mode makes any sense

That's how it works right now. Add a new torrent (without checking or unchecking the files), start it, and you'll see that full-sized files are created on first access.

Can you submit a patch?

Yes. I just waited for @arvidn's response on it. But I guess it could be reviewed as a PR.

@HanabishiRecca
Copy link
Contributor Author

@HanabishiRecca
Copy link
Contributor Author

Fixed in #7738.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants