diff options
author | Richard Purdie <rpurdie@rpsys.net> | 2008-02-19 11:59:30 +0000 |
---|---|---|
committer | Richard Purdie <rpurdie@rpsys.net> | 2008-02-19 11:59:30 +0000 |
commit | d56c0688ea805c88d94afad341cf074060b61c16 (patch) | |
tree | febf5dd363c8008843d8d0a0382b156e43903363 /classes | |
parent | 23db6097b2e40cae71bb936c9165f403dc43be2a (diff) |
package_ipk.bbclass/package_deb.bbclass: Use bitbake locking functions
Diffstat (limited to 'classes')
-rw-r--r-- | classes/package_deb.bbclass | 22 | ||||
-rw-r--r-- | classes/package_ipk.bbclass | 28 |
2 files changed, 18 insertions, 32 deletions
diff --git a/classes/package_deb.bbclass b/classes/package_deb.bbclass index b85ffe254f..c550c2fbff 100644 --- a/classes/package_deb.bbclass +++ b/classes/package_deb.bbclass @@ -69,7 +69,7 @@ python do_package_deb_install () { } python do_package_deb () { - import sys, re, fcntl, copy + import sys, re, copy workdir = bb.data.getVar('WORKDIR', d, 1) if not workdir: @@ -102,20 +102,11 @@ python do_package_deb () { bb.debug(1, "No packages; nothing to do") return - def lockfile(name): - lf = open(name, "a+") - fcntl.flock(lf.fileno(), fcntl.LOCK_EX) - return lf - - def unlockfile(lf): - fcntl.flock(lf.fileno(), fcntl.LOCK_UN) - lf.close - for pkg in packages.split(): localdata = bb.data.createCopy(d) root = "%s/install/%s" % (workdir, pkg) - lf = lockfile(root + ".lock") + lf = bb.utils.lockfile(root + ".lock") bb.data.setVar('ROOT', '', localdata) bb.data.setVar('ROOT_%s' % pkg, root, localdata) @@ -147,7 +138,7 @@ python do_package_deb () { if not g and bb.data.getVar('ALLOW_EMPTY', localdata) != "1": from bb import note note("Not creating empty archive for %s-%s-%s" % (pkg, bb.data.getVar('PV', localdata, 1), bb.data.getVar('PR', localdata, 1))) - unlockfile(lf) + bb.utils.unlockfile(lf) continue controldir = os.path.join(root, 'DEBIAN') @@ -158,6 +149,7 @@ python do_package_deb () { # import codecs # ctrlfile = codecs.open("someFile", "w", "utf-8") except OSError: + bb.utils.unlockfile(lf) raise bb.build.FuncFailed("unable to open control file for writing.") fields = [] @@ -196,6 +188,7 @@ python do_package_deb () { ctrlfile.write(unicode(c % tuple(pullData(fs, localdata)))) except KeyError: (type, value, traceback) = sys.exc_info() + bb.utils.unlockfile(lf) ctrlfile.close() raise bb.build.FuncFailed("Missing field for deb generation: %s" % value) # more fields @@ -231,6 +224,7 @@ python do_package_deb () { try: scriptfile = file(os.path.join(controldir, script), 'w') except OSError: + bb.utils.unlockfile(lf) raise bb.build.FuncFailed("unable to open %s script file for writing." % script) scriptfile.write("#!/bin/sh\n") scriptfile.write(scriptvar) @@ -242,6 +236,7 @@ python do_package_deb () { try: conffiles = file(os.path.join(controldir, 'conffiles'), 'w') except OSError: + bb.utils.unlockfile(lf) raise bb.build.FuncFailed("unable to open conffiles for writing.") for f in conffiles_str.split(): conffiles.write('%s\n' % f) @@ -250,6 +245,7 @@ python do_package_deb () { os.chdir(basedir) ret = os.system("PATH=\"%s\" fakeroot dpkg-deb -b %s %s" % (bb.data.getVar("PATH", localdata, 1), root, pkgoutdir)) if ret != 0: + bb.utils.unlockfile(lf) raise bb.build.FuncFailed("dpkg-deb execution failed") for script in ["preinst", "postinst", "prerm", "postrm", "control" ]: @@ -263,7 +259,7 @@ python do_package_deb () { except OSError: pass - unlockfile(lf) + bb.utils.unlockfile(lf) } python () { diff --git a/classes/package_ipk.bbclass b/classes/package_ipk.bbclass index 087bbcbfb4..57fcaa763f 100644 --- a/classes/package_ipk.bbclass +++ b/classes/package_ipk.bbclass @@ -114,7 +114,7 @@ package_generate_ipkg_conf () { } python do_package_ipk () { - import sys, re, copy, fcntl + import sys, re, copy workdir = bb.data.getVar('WORKDIR', d, 1) if not workdir: @@ -147,22 +147,12 @@ python do_package_ipk () { bb.debug(1, "No packages; nothing to do") return - def lockfile(name): - lf = open(name, "a+") - fcntl.flock(lf.fileno(), fcntl.LOCK_EX) - return lf - - def unlockfile(lf): - fcntl.flock(lf.fileno(), fcntl.LOCK_UN) - lf.close - - for pkg in packages.split(): localdata = bb.data.createCopy(d) pkgdest = bb.data.getVar('PKGDEST', d, 1) root = "%s/%s" % (pkgdest, pkg) - lf = lockfile(root + ".lock") + lf = bb.utils.lockfile(root + ".lock") bb.data.setVar('ROOT', '', localdata) bb.data.setVar('ROOT_%s' % pkg, root, localdata) @@ -193,7 +183,7 @@ python do_package_ipk () { if not g and bb.data.getVar('ALLOW_EMPTY', localdata) != "1": from bb import note note("Not creating empty archive for %s-%s-%s" % (pkg, bb.data.getVar('PV', localdata, 1), bb.data.getVar('PR', localdata, 1))) - unlockfile(lf) + bb.utils.unlockfile(lf) continue controldir = os.path.join(root, 'CONTROL') @@ -201,7 +191,7 @@ python do_package_ipk () { try: ctrlfile = file(os.path.join(controldir, 'control'), 'w') except OSError: - unlockfile(lf) + bb.utils.unlockfile(lf) raise bb.build.FuncFailed("unable to open control file for writing.") fields = [] @@ -235,7 +225,7 @@ python do_package_ipk () { except KeyError: (type, value, traceback) = sys.exc_info() ctrlfile.close() - unlockfile(lf) + bb.utils.unlockfile(lf) raise bb.build.FuncFailed("Missing field for ipk generation: %s" % value) # more fields @@ -272,7 +262,7 @@ python do_package_ipk () { try: scriptfile = file(os.path.join(controldir, script), 'w') except OSError: - unlockfile(lf) + bb.utils.unlockfile(lf) raise bb.build.FuncFailed("unable to open %s script file for writing." % script) scriptfile.write(scriptvar) scriptfile.close() @@ -283,7 +273,7 @@ python do_package_ipk () { try: conffiles = file(os.path.join(controldir, 'conffiles'), 'w') except OSError: - unlockfile(lf) + bb.utils.unlockfile(lf) raise bb.build.FuncFailed("unable to open conffiles for writing.") for f in conffiles_str.split(): conffiles.write('%s\n' % f) @@ -293,7 +283,7 @@ python do_package_ipk () { ret = os.system("PATH=\"%s\" %s %s %s" % (bb.data.getVar("PATH", localdata, 1), bb.data.getVar("IPKGBUILDCMD",d,1), pkg, pkgoutdir)) if ret != 0: - unlockfile(lf) + bb.utils.unlockfile(lf) raise bb.build.FuncFailed("ipkg-build execution failed") for script in ["preinst", "postinst", "prerm", "postrm", "control" ]: @@ -306,7 +296,7 @@ python do_package_ipk () { os.rmdir(controldir) except OSError: pass - unlockfile(lf) + bb.utils.unlockfile(lf) } python () { |