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

Make sure alpm_release is run at end of transaction. #8

Open
richard-uk1 opened this issue Apr 12, 2017 · 13 comments
Open

Make sure alpm_release is run at end of transaction. #8

richard-uk1 opened this issue Apr 12, 2017 · 13 comments

Comments

@richard-uk1
Copy link
Owner

It is needed to run alpm_release at the end of all transaction, if it succeed or not, in order to remove the db.lck lock file. This lock file is created after a success run of alpm_trans_init.

@richard-uk1
Copy link
Owner Author

@guinux alpm_release is always run when the Alpm struct is dropped, which must happen even in a panic (Drop functions are still run in a panic). Is this sufficient?

@guinux
Copy link
Contributor

guinux commented Apr 12, 2017

It is alpm_trans_release which need to be run at the end of all transaction not alpm_release.

@guinux
Copy link
Contributor

guinux commented Apr 12, 2017

Sorry for the mistake on the function names.

@richard-uk1
Copy link
Owner Author

np. I still need to understand transactions!

@guinux
Copy link
Contributor

guinux commented Apr 13, 2017

To save you some time understanding the sources, here is how a transaction works:

  • init a transaction (register transaction flags and lock databases) with alpm_trans_in it
  • add a pkg to install (a ref to pkg in syncdb, can be run multiple times) with alpm_add_pkg
  • AND/OR add a pkg to remove (a ref to a pkg in localdb, can be run multiple times) with alpm_remove_pkg
  • AND/OR find pkgs to update and add them to install with alpm_sync_sysupgrade
  • prepare the transaction (check deps and conflicts, data is a list of conflicts) with alpm_trans_prepare
  • run transaction with alpm_trans_commit
  • end transaction (unlock databases) with alpm_trans_release

@richard-uk1
Copy link
Owner Author

that's brill, thanks!

@guinux
Copy link
Contributor

guinux commented Apr 13, 2017

Between alpm_trans_prepare and alpm_trans_commit your can have access to the complete list of pkgs to install and remove (with deps and conflicts to remove) with alpm_trans_get_add and alpm_trans_get_remove

@richard-uk1
Copy link
Owner Author

I'm looking at modeling this as

enum Initialized {}
enum Prepared {}

impl Transaction<Initialized> {
   pub fn add(...) { ... }
   pub fn remove(...) { ... }
   pub fn prepare(...) -> Transaction<Prepared> { ... }
}

impl Transaction<Prepared> {
   pub fn commit(...) { ... }
}

These might not be the correct signatures, but hopefully you get the idea - the transaction is parameterised and different functionality is available depending on the state parameter. This is how http requests are handled in hyper (hyper http docs)

@guinux
Copy link
Contributor

guinux commented Apr 13, 2017

Looks good to me :)

@richard-uk1
Copy link
Owner Author

richard-uk1 commented Apr 13, 2017

I'm currently struggling with transactions. There are various times when alpm_trans_prepare does nothing but returns success (if there is nothing to do). This makes it hard for me to strongly type my transaction.

The only solution I can see is exploit the internal structure of the transaction to get the state, but this would then be vulnerable to updates (a non-breaking change could break my code). Sadly I can't see any other way to do it, but I'll think about it and see if I have any ideas.

@guinux
Copy link
Contributor

guinux commented Apr 13, 2017

What about running alpm_get_add and alpm_get_remove after running a successful alpm_trans_prepare to check if there is something to do?

@richard-uk1
Copy link
Owner Author

Ooh good idea!

@richard-uk1
Copy link
Owner Author

An implementation is now comitted. It's testable using the examples/update.rs example.

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