Subject: rmdir inside a union-mounted dir
To: None <netbsd-users@netbsd.org>
From: Martijn van Buul <martijnb@atlas.ipv6.stack.nl>
List: netbsd-users
Date: 03/27/2005 18:15:07
Hello.
I'm trying to write a shellscript that'll make package rebuilding less
painful, and I stumbled across a problem that I don't really grok.
Basicly, my idea was as follows:
1) Figure out what packages need updating (using lintpkgsrc)
2) Setup a sandbox, using null-mounted directories, except for /etc, /var and
/usr/pkg, which get a union mount
3) Delete the packages (using pkgdepgraph -D) inside the sandbox
4) Rebuild (pkgdepgraph -R) the packages inside the sandbox, leaving binary
packages in /usr/pkg/packages
5) Delete the packages on the real system (again, pkgdepgraph -D)
6) Reinstall, using the binary packages made in #4.
all in a single shell script.
This way, I wouldn't end up with a partly unusuable system for 2 days, just
because a core library got updated. Furthermore, if the rebuild couldn't
be completed, I'd still have a working system.
I wrote a script (It's a bit long to include, so see
http://www.stack.nl/~martijnb/pkgupdate, comments are welcome), and I'm having
problems with #3. my sandboxed /usr/pkg gets trashed, because *apperently* an
rmdir of a non-empty directory in a union-mounted fs *succeeds*, turning a
harmless "rmdir /usr/pkg/bin" into the equivalent of a "rm -rf /usr/pkg/bin".
And, since pkg_delete tries to clean up after itself, my mirrored /usr/pkg gets
destroyed after the first package gets deleted.
I don't really understand this behaviour of the unionfs. I'm not sure if it's
a bug in unionfs, or a bug in my understanding of it all. (For the record,
I'm using NetBSD-3.99.1, March 23 sources). If it *is* desired behaviour
of unionfs, is there something else I could do to prevent pkg_delete from
wreaking havoc? I could use pkg_delete -O, but that doesn't sound like
a very wise thing to do, and I'd like to avoid having to make an integral
*copy* of the various directories - that's why I used a unionfs to begin
with.
Kind regards,
Martijn