summaryrefslogtreecommitdiffstats
path: root/meta/classes
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 /meta/classes
parent701aa74aeb2e06368a927b4b61dd02160066101a (diff)
downloadpoky-c0659779483182aff39d8e8a6821a40d1489dc0f.tar.gz
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
Diffstat (limited to 'meta/classes')
-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 e17627eaac..c2741d0222 100644
--- a/meta/classes/package.bbclass
+++ b/meta/classes/package.bbclass
@@ -318,76 +318,6 @@ python package_do_split_locales() {
318 #bb.data.setVar('RDEPENDS_%s' % mainpkg, ' '.join(rdep), d) 318 #bb.data.setVar('RDEPENDS_%s' % mainpkg, ' '.join(rdep), d)
319} 319}
320 320
321def copyfile(src,dest,newmtime=None,sstat=None):
322 """
323 Copies a file from src to dest, preserving all permissions and
324 attributes; mtime will be preserved even when moving across
325 filesystems. Returns true on success and false on failure.
326 """
327 import os, stat, shutil, commands
328
329 #print "copyfile("+src+","+dest+","+str(newmtime)+","+str(sstat)+")"
330 try:
331 if not sstat:
332 sstat=os.lstat(src)
333 except Exception, e:
334 print "copyfile: Stating source file failed...", e
335 return False
336
337 destexists=1
338 try:
339 dstat=os.lstat(dest)
340 except:
341 dstat=os.lstat(os.path.dirname(dest))
342 destexists=0
343
344 if destexists:
345 if stat.S_ISLNK(dstat[stat.ST_MODE]):
346 try:
347 os.unlink(dest)
348 destexists=0
349 except Exception, e:
350 pass
351
352 if stat.S_ISLNK(sstat[stat.ST_MODE]):
353 try:
354 target=os.readlink(src)
355 if destexists and not stat.S_ISDIR(dstat[stat.ST_MODE]):
356 os.unlink(dest)
357 os.symlink(target,dest)
358 #os.lchown(dest,sstat[stat.ST_UID],sstat[stat.ST_GID])
359 return os.lstat(dest)
360 except Exception, e:
361 print "copyfile: failed to properly create symlink:", dest, "->", target, e
362 return False
363
364 if stat.S_ISREG(sstat[stat.ST_MODE]):
365 try: # For safety copy then move it over.
366 shutil.copyfile(src,dest+"#new")
367 os.rename(dest+"#new",dest)
368 except Exception, e:
369 print 'copyfile: copy', src, '->', dest, 'failed.', e
370 return False
371 else:
372 #we don't yet handle special, so we need to fall back to /bin/mv
373 a=commands.getstatusoutput("/bin/cp -f "+"'"+src+"' '"+dest+"'")
374 if a[0]!=0:
375 print "copyfile: Failed to copy special file:" + src + "' to '" + dest + "'", a
376 return False # failure
377 try:
378 os.lchown(dest,sstat[stat.ST_UID],sstat[stat.ST_GID])
379 os.chmod(dest, stat.S_IMODE(sstat[stat.ST_MODE])) # Sticky is reset on chown
380 except Exception, e:
381 print "copyfile: Failed to chown/chmod/unlink", dest, e
382 return False
383
384 if newmtime:
385 os.utime(dest,(newmtime,newmtime))
386 else:
387 os.utime(dest, (sstat[stat.ST_ATIME], sstat[stat.ST_MTIME]))
388 newmtime=sstat[stat.ST_MTIME]
389 return newmtime
390
391python populate_packages () { 321python populate_packages () {
392 import glob, stat, errno, re 322 import glob, stat, errno, re
393 323
@@ -491,7 +421,7 @@ python populate_packages () {
491 fpath = os.path.join(root,file) 421 fpath = os.path.join(root,file)
492 dpath = os.path.dirname(fpath) 422 dpath = os.path.dirname(fpath)
493 bb.mkdirhier(dpath) 423 bb.mkdirhier(dpath)
494 ret = copyfile(file, fpath) 424 ret = bb.copyfile(file, fpath)
495 if ret is False or ret == 0: 425 if ret is False or ret == 0:
496 raise bb.build.FuncFailed("File population failed") 426 raise bb.build.FuncFailed("File population failed")
497 del localdata 427 del localdata
diff --git a/meta/classes/package_deb.bbclass b/meta/classes/package_deb.bbclass
index ce4d5c914c..a5b850d8ad 100644
--- a/meta/classes/package_deb.bbclass
+++ b/meta/classes/package_deb.bbclass
@@ -102,20 +102,11 @@ python do_package_deb () {
102 bb.debug(1, "No packages; nothing to do") 102 bb.debug(1, "No packages; nothing to do")
103 return 103 return
104 104
105 def lockfile(name):
106 lf = open(name, "a+")
107 fcntl.flock(lf.fileno(), fcntl.LOCK_EX)
108 return lf
109
110 def unlockfile(lf):
111 fcntl.flock(lf.fileno(), fcntl.LOCK_UN)
112 lf.close
113
114 for pkg in packages.split(): 105 for pkg in packages.split():
115 localdata = bb.data.createCopy(d) 106 localdata = bb.data.createCopy(d)
116 root = "%s/install/%s" % (workdir, pkg) 107 root = "%s/install/%s" % (workdir, pkg)
117 108
118 lf = lockfile(root + ".lock") 109 lf = bb.utils.lockfile(root + ".lock")
119 110
120 bb.data.setVar('ROOT', '', localdata) 111 bb.data.setVar('ROOT', '', localdata)
121 bb.data.setVar('ROOT_%s' % pkg, root, localdata) 112 bb.data.setVar('ROOT_%s' % pkg, root, localdata)
@@ -147,7 +138,7 @@ python do_package_deb () {
147 if not g and bb.data.getVar('ALLOW_EMPTY', localdata) != "1": 138 if not g and bb.data.getVar('ALLOW_EMPTY', localdata) != "1":
148 from bb import note 139 from bb import note
149 note("Not creating empty archive for %s-%s-%s" % (pkg, bb.data.getVar('PV', localdata, 1), bb.data.getVar('PR', localdata, 1))) 140 note("Not creating empty archive for %s-%s-%s" % (pkg, bb.data.getVar('PV', localdata, 1), bb.data.getVar('PR', localdata, 1)))
150 unlockfile(lf) 141 bb.utils.unlockfile(lf)
151 continue 142 continue
152 143
153 controldir = os.path.join(root, 'DEBIAN') 144 controldir = os.path.join(root, 'DEBIAN')
@@ -158,6 +149,7 @@ python do_package_deb () {
158 # import codecs 149 # import codecs
159 # ctrlfile = codecs.open("someFile", "w", "utf-8") 150 # ctrlfile = codecs.open("someFile", "w", "utf-8")
160 except OSError: 151 except OSError:
152 bb.utils.unlockfile(lf)
161 raise bb.build.FuncFailed("unable to open control file for writing.") 153 raise bb.build.FuncFailed("unable to open control file for writing.")
162 154
163 fields = [] 155 fields = []
@@ -196,6 +188,7 @@ python do_package_deb () {
196 ctrlfile.write(unicode(c % tuple(pullData(fs, localdata)))) 188 ctrlfile.write(unicode(c % tuple(pullData(fs, localdata))))
197 except KeyError: 189 except KeyError:
198 (type, value, traceback) = sys.exc_info() 190 (type, value, traceback) = sys.exc_info()
191 bb.utils.unlockfile(lf)
199 ctrlfile.close() 192 ctrlfile.close()
200 raise bb.build.FuncFailed("Missing field for deb generation: %s" % value) 193 raise bb.build.FuncFailed("Missing field for deb generation: %s" % value)
201 # more fields 194 # more fields
@@ -231,6 +224,7 @@ python do_package_deb () {
231 try: 224 try:
232 scriptfile = file(os.path.join(controldir, script), 'w') 225 scriptfile = file(os.path.join(controldir, script), 'w')
233 except OSError: 226 except OSError:
227 bb.utils.unlockfile(lf)
234 raise bb.build.FuncFailed("unable to open %s script file for writing." % script) 228 raise bb.build.FuncFailed("unable to open %s script file for writing." % script)
235 scriptfile.write("#!/bin/sh\n") 229 scriptfile.write("#!/bin/sh\n")
236 scriptfile.write(scriptvar) 230 scriptfile.write(scriptvar)
@@ -242,6 +236,7 @@ python do_package_deb () {
242 try: 236 try:
243 conffiles = file(os.path.join(controldir, 'conffiles'), 'w') 237 conffiles = file(os.path.join(controldir, 'conffiles'), 'w')
244 except OSError: 238 except OSError:
239 bb.utils.unlockfile(lf)
245 raise bb.build.FuncFailed("unable to open conffiles for writing.") 240 raise bb.build.FuncFailed("unable to open conffiles for writing.")
246 for f in conffiles_str.split(): 241 for f in conffiles_str.split():
247 conffiles.write('%s\n' % f) 242 conffiles.write('%s\n' % f)
@@ -250,6 +245,7 @@ python do_package_deb () {
250 os.chdir(basedir) 245 os.chdir(basedir)
251 ret = os.system("PATH=\"%s\" fakeroot dpkg-deb -b %s %s" % (bb.data.getVar("PATH", localdata, 1), root, pkgoutdir)) 246 ret = os.system("PATH=\"%s\" fakeroot dpkg-deb -b %s %s" % (bb.data.getVar("PATH", localdata, 1), root, pkgoutdir))
252 if ret != 0: 247 if ret != 0:
248 bb.utils.unlockfile(lf)
253 raise bb.build.FuncFailed("dpkg-deb execution failed") 249 raise bb.build.FuncFailed("dpkg-deb execution failed")
254 250
255 for script in ["preinst", "postinst", "prerm", "postrm", "control" ]: 251 for script in ["preinst", "postinst", "prerm", "postrm", "control" ]:
@@ -263,7 +259,7 @@ python do_package_deb () {
263 except OSError: 259 except OSError:
264 pass 260 pass
265 261
266 unlockfile(lf) 262 bb.utils.unlockfile(lf)
267} 263}
268 264
269python () { 265python () {
diff --git a/meta/classes/package_ipk.bbclass b/meta/classes/package_ipk.bbclass
index be300e04b1..e69745665f 100644
--- a/meta/classes/package_ipk.bbclass
+++ b/meta/classes/package_ipk.bbclass
@@ -33,7 +33,7 @@ python package_ipk_install () {
33 33
34 # Generate ipk.conf if it or the stamp doesnt exist 34 # Generate ipk.conf if it or the stamp doesnt exist
35 conffile = os.path.join(stagingdir,"ipkg.conf") 35 conffile = os.path.join(stagingdir,"ipkg.conf")
36 if not os.access(conffile, os.R_OK): 36 if not os.access(conffile, os.R_OK):
37 ipkg_archs = bb.data.getVar('PACKAGE_ARCHS',d) 37 ipkg_archs = bb.data.getVar('PACKAGE_ARCHS',d)
38 if ipkg_archs is None: 38 if ipkg_archs is None:
39 bb.error("PACKAGE_ARCHS missing") 39 bb.error("PACKAGE_ARCHS missing")
@@ -152,20 +152,11 @@ python do_package_ipk () {
152 bb.debug(1, "No packages; nothing to do") 152 bb.debug(1, "No packages; nothing to do")
153 return 153 return
154 154
155 def lockfile(name):
156 lf = open(name, "a+")
157 fcntl.flock(lf.fileno(), fcntl.LOCK_EX)
158 return lf
159
160 def unlockfile(lf):
161 fcntl.flock(lf.fileno(), fcntl.LOCK_UN)
162 lf.close
163
164 for pkg in packages.split(): 155 for pkg in packages.split():
165 localdata = bb.data.createCopy(d) 156 localdata = bb.data.createCopy(d)
166 root = "%s/install/%s" % (workdir, pkg) 157 root = "%s/install/%s" % (workdir, pkg)
167 158
168 lf = lockfile(root + ".lock") 159 lf = bb.utils.lockfile(root + ".lock")
169 160
170 bb.data.setVar('ROOT', '', localdata) 161 bb.data.setVar('ROOT', '', localdata)
171 bb.data.setVar('ROOT_%s' % pkg, root, localdata) 162 bb.data.setVar('ROOT_%s' % pkg, root, localdata)
@@ -195,7 +186,7 @@ python do_package_ipk () {
195 if not g and bb.data.getVar('ALLOW_EMPTY', localdata) != "1": 186 if not g and bb.data.getVar('ALLOW_EMPTY', localdata) != "1":
196 from bb import note 187 from bb import note
197 note("Not creating empty archive for %s-%s-%s" % (pkg, bb.data.getVar('PV', localdata, 1), bb.data.getVar('PR', localdata, 1))) 188 note("Not creating empty archive for %s-%s-%s" % (pkg, bb.data.getVar('PV', localdata, 1), bb.data.getVar('PR', localdata, 1)))
198 unlockfile(lf) 189 bb.utils.unlockfile(lf)
199 continue 190 continue
200 191
201 controldir = os.path.join(root, 'CONTROL') 192 controldir = os.path.join(root, 'CONTROL')
@@ -203,6 +194,7 @@ python do_package_ipk () {
203 try: 194 try:
204 ctrlfile = file(os.path.join(controldir, 'control'), 'w') 195 ctrlfile = file(os.path.join(controldir, 'control'), 'w')
205 except OSError: 196 except OSError:
197 bb.utils.unlockfile(lf)
206 raise bb.build.FuncFailed("unable to open control file for writing.") 198 raise bb.build.FuncFailed("unable to open control file for writing.")
207 199
208 fields = [] 200 fields = []
@@ -236,6 +228,7 @@ python do_package_ipk () {
236 except KeyError: 228 except KeyError:
237 (type, value, traceback) = sys.exc_info() 229 (type, value, traceback) = sys.exc_info()
238 ctrlfile.close() 230 ctrlfile.close()
231 bb.utils.unlockfile(lf)
239 raise bb.build.FuncFailed("Missing field for ipk generation: %s" % value) 232 raise bb.build.FuncFailed("Missing field for ipk generation: %s" % value)
240 # more fields 233 # more fields
241 234
@@ -272,6 +265,7 @@ python do_package_ipk () {
272 try: 265 try:
273 scriptfile = file(os.path.join(controldir, script), 'w') 266 scriptfile = file(os.path.join(controldir, script), 'w')
274 except OSError: 267 except OSError:
268 bb.utils.unlockfile(lf)
275 raise bb.build.FuncFailed("unable to open %s script file for writing." % script) 269 raise bb.build.FuncFailed("unable to open %s script file for writing." % script)
276 scriptfile.write(scriptvar) 270 scriptfile.write(scriptvar)
277 scriptfile.close() 271 scriptfile.close()
@@ -282,6 +276,7 @@ python do_package_ipk () {
282 try: 276 try:
283 conffiles = file(os.path.join(controldir, 'conffiles'), 'w') 277 conffiles = file(os.path.join(controldir, 'conffiles'), 'w')
284 except OSError: 278 except OSError:
279 bb.utils.unlockfile(lf)
285 raise bb.build.FuncFailed("unable to open conffiles for writing.") 280 raise bb.build.FuncFailed("unable to open conffiles for writing.")
286 for f in conffiles_str.split(): 281 for f in conffiles_str.split():
287 conffiles.write('%s\n' % f) 282 conffiles.write('%s\n' % f)
@@ -291,6 +286,7 @@ python do_package_ipk () {
291 ret = os.system("PATH=\"%s\" %s %s %s" % (bb.data.getVar("PATH", localdata, 1), 286 ret = os.system("PATH=\"%s\" %s %s %s" % (bb.data.getVar("PATH", localdata, 1),
292 bb.data.getVar("IPKGBUILDCMD",d,1), pkg, pkgoutdir)) 287 bb.data.getVar("IPKGBUILDCMD",d,1), pkg, pkgoutdir))
293 if ret != 0: 288 if ret != 0:
289 bb.utils.unlockfile(lf)
294 raise bb.build.FuncFailed("ipkg-build execution failed") 290 raise bb.build.FuncFailed("ipkg-build execution failed")
295 291
296 for script in ["preinst", "postinst", "prerm", "postrm", "control" ]: 292 for script in ["preinst", "postinst", "prerm", "postrm", "control" ]:
@@ -303,7 +299,7 @@ python do_package_ipk () {
303 os.rmdir(controldir) 299 os.rmdir(controldir)
304 except OSError: 300 except OSError:
305 pass 301 pass
306 unlockfile(lf) 302 bb.utils.unlockfile(lf)
307} 303}
308 304
309python () { 305python () {