Can't externally acquire lock on /var/lib/apt/lists/lock
Hi all, newbie here.
What I'm trying to accomplish is offline updating packages lists in
/var/lib/apt/lists. As far as I know, there's no supported way of
doing this with apt tools, so I'm trying to do so with a bash script.
Assuming that no synaptic, aptitude, apt-get, etc. process is running,
doing the following will just works (assuming you have saved
/var/lib/apt/lists folder in lists.tar.bz2):
rm -r /var/lib/apt/lists
tar xvjpf lists.tar.bz2 -C /var/lib/apt
I realize this is ugly and unsafe, so I'd like to write the same in a
cleaner way, taking the lock on /var/lib/apt/lists/lock first,
similarly to what apt-get update and other tools do. Surprisingly, it
wasn't so easy as I tough, and the following bash script doesn't work
as I expected:
--------------------------------------
#!/bin/bash
set -e
(
flock --exclusive --nonblock 200
# do something inside /var/lib/apt/lists
sleep 50 # Taking some time to test if the lock works
) 200>/var/lib/apt/lists/lock
--------------------------------------
It doesn't work in the sense that trying to launch apt-get update
during the sleep time will simply works, like no lock was set. What am
I doing wrong?
I hope apt-get is not actually checking which process is taking the
lock and failing just if the lock was taken by apt-get: I think it
would not be a good design and would mean that my task, offline
updating apt packages lists with a provided archive, can't be safely
implemented.
Any idea, workaround? Thanks a lot.
Greetings,
Francesco
Reply to: