-
Notifications
You must be signed in to change notification settings - Fork 4
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
Handle libzypp lock #6
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small improvements
@@ -111,6 +113,21 @@ def run_cmd(*args) | |||
rescue Cheetah::ExecutionFailed | |||
false | |||
end | |||
|
|||
# zypp lock file | |||
ZYPP_PID = Pathname("/mnt/var/run/zypp.pid") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather use Installation.destdir
instead of the hard-coded /mnt
.
# zypp lock backup file | ||
ZYPP_PID_BACKUP = ZYPP_PID.sub_ext(".save") | ||
|
||
# Run a block without the zypp lock |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment that this is really a nasty hack and should be used carefully, only in very specific cases.
# @param [Proc] Block to run | ||
def without_zypp_lock(&block) | ||
::FileUtils.mv(ZYPP_PID, ZYPP_PID_BACKUP) if ZYPP_PID.exist? | ||
block.call |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please log some warning message, removing the lock is potentially dangerous operation so it should be logged for easier debugging.
::FileUtils.mv(ZYPP_PID, ZYPP_PID_BACKUP) if ZYPP_PID.exist? | ||
block.call | ||
ensure | ||
::FileUtils.mv(ZYPP_PID_BACKUP, ZYPP_PID) if ZYPP_PID_BACKUP.exist? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, log also the lock restoration.
# | ||
# @param [Proc] Block to run | ||
def without_zypp_lock(&block) | ||
::FileUtils.mv(ZYPP_PID, ZYPP_PID_BACKUP) if ZYPP_PID.exist? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Um, what if the backup already exists? Either use a unique temporary file name or raise an exception here.
It is very unlikely that the method will be called recursively, but it's better to be on the safe side...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually a temporary file does not help, raising an exception is the only way. Otherwise the lock might be restored too early:
def foo
without_zypp_lock do
bar
end
end
def baz
without_zypp_lock do
foo
do_something # here the lock is restored!!
end
end
5b46c22
to
95154fa
Compare
Thanks for your comments! I've updated the PR. |
LGTM. Is it still WIP? If not then update the version and add the changes. |
During installation, we have two libzypp lockfiles: one in
/var/run/zypp.pid
and another on in/mnt/var/run/zypp.pid
. So when the provisioner runs (Salt or Puppet), zypper is locked and you won't be able to install any package.This code will be executed as part of the inst_finish client as the last save settings step, so I would assume that is safe to backup and restore the libzypp lock.