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

Wait for db.lck to become available before starting a db operation #573

Merged
merged 5 commits into from
Jul 21, 2018

Conversation

Jguer
Copy link
Owner

@Jguer Jguer commented Jul 21, 2018

On split updates some funkiness can happen where an yay instance is unlocked before the other one gets to the 2nd pacman call but it should be working resulting in:

yay-1 -Syu
yay-2 -Syu
yay-1 pacman
yay-2 pacman
yay-1 pacman
yay-2 pacman

It should be stable enough for forced deployment without a flag though

exec.go Outdated
// waitLock will lock yay checking the status of db.lck until it does not exist
func waitLock() (err error) {
for {
if _, err := os.Stat("/var/lib/pacman/db.lck"); os.IsNotExist(err) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be join pacmanconf.DbPath + db.lck

case "R", "remove":
return true
case "S", "sync":
if parser.existsArg("y", "refresh") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are redundant, they'll be caught by the default return true at the end.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default is return false though, I did notice needRoot does have a lot of redundancy

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default inside of sync is true though.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. 😇

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe needRoot needs a touch up as well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, been a long time since I've even looked at it.

exec.go Outdated
if _, err := os.Stat("/var/lib/pacman/db.lck"); os.IsNotExist(err) {
return nil
}
fmt.Println(bold(yellow(smallArrow)), "db.lck is present. Waiting 3 seconds and trying again")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I'd like it to drop the 3 second message and just say Waiting.... The timer can still be on 3 seconds and then resume when it see's the lock is gone. Avoids the spam of seeing this every 3 seconds.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do an initial check, print the message and then loop

exec.go Outdated
// waitLock will lock yay checking the status of db.lck until it does not exist
func waitLock() (err error) {
for {
if _, err := os.Stat("/var/lib/pacman/db.lck"); os.IsNotExist(err) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible to get different errors. After checking os.IsNotExist(err) You should have a else if for the generic err != nil.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That else if would return nil as well and abort the lock so any error actually will return nil

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I just noticed you're not even handling errors. In that case why have a return value at all?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of habit

exec.go Outdated

for {
time.Sleep(3 * time.Second)
if _, err := os.Stat(alpmConf.DBPath + "db.lck"); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filepath.Join ;)

@Morganamilo
Copy link
Contributor

I think it's good now apart from my last comment (and that I have not actually ran the code)

@Jguer Jguer merged commit f9972da into master Jul 21, 2018
@Morganamilo
Copy link
Contributor

Testing this out I have the most nit picky ocd complaint. The cursor is put on the next line while it waits. This annoys me for some reason. Apart from that works well.

What do you think about this instead?

diff --git a/exec.go b/exec.go
index 2a97ae3..a5b95dc 100644
--- a/exec.go
+++ b/exec.go
@@ -60,11 +60,12 @@ func waitLock() {
                return
        }
 
-       fmt.Println(bold(yellow(smallArrow)), "db.lck is present. Waiting... ")
+       fmt.Print(bold(yellow(smallArrow)), " db.lck is present. Waiting...")
 
        for {
                time.Sleep(3 * time.Second)
                if _, err := os.Stat(filepath.Join(alpmConf.DBPath, "db.lck")); err != nil {
+                       fmt.Println()
                        return
                }
        }

@Jguer
Copy link
Owner Author

Jguer commented Jul 21, 2018

That is the most nit picky ocd complaint 😆 , merge it with #576

@Jguer Jguer deleted the wait-lock branch July 26, 2018 11:03
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 this pull request may close these issues.

2 participants