summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Purdie <richard@openedhand.com>2007-11-24 14:55:57 +0000
committerRichard Purdie <richard@openedhand.com>2007-11-24 14:55:57 +0000
commitc0659779483182aff39d8e8a6821a40d1489dc0f (patch)
tree80c62fdc5c28c4d1820b209374706af7b38bc4b2
parent701aa74aeb2e06368a927b4b61dd02160066101a (diff)
downloadopenembedded-core-c0659779483182aff39d8e8a6821a40d1489dc0f.tar.gz
openembedded-core-c0659779483182aff39d8e8a6821a40d1489dc0f.tar.bz2
openembedded-core-c0659779483182aff39d8e8a6821a40d1489dc0f.tar.xz
openembedded-core-c0659779483182aff39d8e8a6821a40d1489dc0f.zip
classes: Use internal bitbake functions and fix packaging unlocking on error paths
git-svn-id: https://svn.o-hand.com/repos/poky/trunk@3222 311d38ba-8fff-0310-9ca6-ca027cbcb966
-rw-r--r--meta/classes/package.bbclass72
-rw-r--r--meta/classes/package_deb.bbclass20
-rw-r--r--meta/classes/package_ipk.bbclass22
3 files changed, 18 insertions, 96 deletions
diff --git a/meta/classes/package.bbclass b/meta/classes/package.bbclass
index e17627eaa..c2741d022 100644
--- a/meta/classes/package.bbclass
+++ b/meta/classes/package.bbclass
@@ -318,76 +318,6 @@ python package_do_split_locales() {
#bb.data.setVar('RDEPENDS_%s' % mainpkg, ' '.join(rdep), d)
}
-def copyfile(src,dest,newmtime=None,sstat=None):
- """
- Copies a file from src to dest, preserving all permissions and
- attributes; mtime will be preserved even when moving across
- filesystems. Returns true on success and false on failure.
- """
- import os, stat, shutil, commands
-
- #print "copyfile("+src+","+dest+","+str(newmtime)+","+str(sstat)+")"
- try:
- if not sstat:
- sstat=os.lstat(src)
- except Exception, e:
- print "copyfile: Stating source file failed...", e
- return False
-
- destexists=1
- try:
- dstat=os.lstat(dest)
- except:
- dstat=os.lstat(os.path.dirname(dest))
- destexists=0
-
- if destexists:
- if stat.S_ISLNK(dstat[stat.ST_MODE]):
- try:
- os.unlink(dest)
- destexists=0
- except Exception, e:
- pass
-
- if stat.S_ISLNK(sstat[stat.ST_MODE]):
- try:
- target=os.readlink(src)
- if destexists and not stat.S_ISDIR(dstat[stat.ST_MODE]):
- os.unlink(dest)
- os.symlink(target,dest)
- #os.lchown(dest,sstat[stat.ST_UID],sstat[stat.ST_GID])
- return os.lstat(dest)
- except Exception, e:
- print "copyfile: failed to properly create symlink:", dest, "->", target, e
- return False
-
- if stat.S_ISREG(sstat[stat.ST_MODE]):
- try: # For safety copy then move it over.
- shutil.copyfile(src,dest+"#new")
- os.rename(dest+"#new",dest)
- except Exception, e:
- print 'copyfile: copy', src, '->', dest, 'failed.', e
- return False
- else:
- #we don't yet handle special, so we need to fall back to /bin/mv
- a=commands.getstatusoutput("/bin/cp -f "+"'"+src+"' '"+dest+"'")
- if a[0]!=0:
- print "copyfile: Failed to copy special file:" + src + "' to '" + dest + "'", a
- return False # failure
- try:
- os.lchown(dest,sstat[stat.ST_UID],sstat[stat.ST_GID])
- os.chmod(dest, stat.S_IMODE(sstat[stat.ST_MODE])) # Sticky is reset on chown
- except Exception, e:
- print "copyfile: Failed to chown/chmod/unlink", dest, e
- return False
-
- if newmtime:
- os.utime(dest,(newmtime,newmtime))
- else:
- os.utime(dest, (sstat[stat.ST_ATIME], sstat[stat.ST_MTIME]))
- newmtime=sstat[stat.ST_MTIME]
- return newmtime
-
python populate_packages () {
import glob, stat, errno, re
@@ -491,7 +421,7 @@ python populate_packages () {
fpath = os.path.join(root,file)
dpath = os.path.dirname(fpath)
bb.mkdirhier(dpath)
- ret = copyfile(file, fpath)
+ ret = bb.copyfile(file, fpath)
if ret is False or ret == 0:
raise bb.build.FuncFailed("File population failed")
del localdata
diff --git a/meta/classes/package_deb.bbclass b/meta/classes/package_deb.bbclass
index ce4d5c914..a5b850d8a 100644
--- a/meta/classes/package_deb.bbclass
+++ b/meta/classes/package_deb.bbclass
@@ -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/meta/classes/package_ipk.bbclass b/meta/classes/package_ipk.bbclass
index be300e04b..e69745665 100644
--- a/meta/classes/package_ipk.bbclass
+++ b/meta/classes/package_ipk.bbclass
@@ -33,7 +33,7 @@ python package_ipk_install () {
# Generate ipk.conf if it or the stamp doesnt exist
conffile = os.path.join(stagingdir,"ipkg.conf")
- if not os.access(conffile, os.R_OK):
+ if not os.access(conffile, os.R_OK):
ipkg_archs = bb.data.getVar('PACKAGE_ARCHS',d)
if ipkg_archs is None:
bb.error("PACKAGE_ARCHS missing")
@@ -152,20 +152,11 @@ 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)
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)
@@ -195,7 +186,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')
@@ -203,6 +194,7 @@ python do_package_ipk () {
try:
ctrlfile = file(os.path.join(controldir, 'control'), 'w')
except OSError:
+ bb.utils.unlockfile(lf)
raise bb.build.FuncFailed("unable to open control file for writing.")
fields = []
@@ -236,6 +228,7 @@ python do_package_ipk () {
except KeyError:
(type, value, traceback) = sys.exc_info()
ctrlfile.close()
+ bb.utils.unlockfile(lf)
raise bb.build.FuncFailed("Missing field for ipk generation: %s" % value)
# more fields
@@ -272,6 +265,7 @@ python do_package_ipk () {
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(scriptvar)
scriptfile.close()
@@ -282,6 +276,7 @@ python do_package_ipk () {
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)
@@ -291,6 +286,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:
+ bb.utils.unlockfile(lf)
raise bb.build.FuncFailed("ipkg-build execution failed")
for script in ["preinst", "postinst", "prerm", "postrm", "control" ]:
@@ -303,7 +299,7 @@ python do_package_ipk () {
os.rmdir(controldir)
except OSError:
pass
- unlockfile(lf)
+ bb.utils.unlockfile(lf)
}
python () {