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

RegKey::encode doesn't work with existing transaction #54

Closed
dnlmlr opened this issue Jun 26, 2023 · 2 comments
Closed

RegKey::encode doesn't work with existing transaction #54

dnlmlr opened this issue Jun 26, 2023 · 2 comments

Comments

@dnlmlr
Copy link
Contributor

dnlmlr commented Jun 26, 2023

Problem Description

The encode function fails when the subkey was created using a transaction.
Example (self implements Serialize):

let t = Transaction::new().unwrap();
let key = RegKey::predef(HKEY_LOCAL_MACHINE)
    .open_subkey_transacted(Self::REGKEY_BASE, &t)
    .unwrap();
let (entry, _disp) = key
    .create_subkey_transacted(Self::REGKEY, &t)
    .unwrap();
entry.encode(self).unwrap();
t.commit().unwrap();

Error on the entry.encode line:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: IoError(Os { code: 6700, kind: Uncategorized, message: "[(translated) The transaction handle associated with this action is invalid.]" })'

Possible Solution

When looking at the code, it seems like the encode function simply creates a new Encoder using the Encoder::from_key function and commits the transaction at the end.
A possible solution (as far as I can tell) might be to simply add a RegKey::encode_transacted(value: &T, t: &Transaction) function that uses Encoder::new and doesn't call commit at the end.

If I'm not missing anything and you think this is a sensible solution, let me know and I can implement it and create a PR

Edit: I just saw that the Encoder::new function is private. This solution would therefore require either creating a new Encoder::from_key_transacted function or setting Encoder::new to pub(crate)

@dnlmlr
Copy link
Contributor Author

dnlmlr commented Jun 26, 2023

I just created a PR that shows an implementation of this issue #55 . That was pretty much faster than describing what I would implement without actually doing it. Let me know what you think about it.

@gentoo90
Copy link
Owner

Fixed in 42aa6f5

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

No branches or pull requests

2 participants