diff options
author | Richard Purdie <richard@openedhand.com> | 2007-10-23 21:57:31 +0000 |
---|---|---|
committer | Richard Purdie <richard@openedhand.com> | 2007-10-23 21:57:31 +0000 |
commit | 6e23136cc799c75f81840e933707c3411fbcd584 (patch) | |
tree | eaca9a47193eda6c478e1b0b6f7270cb9b8d4bbb /meta/classes/package.bbclass | |
parent | 26b7ef0d11c053ca2a9aa2ba06d10c1ddddcb8ad (diff) | |
download | poky-6e23136cc799c75f81840e933707c3411fbcd584.tar.gz |
package.bbclass: Make populate_packages copy files, not move them during do_package
git-svn-id: https://svn.o-hand.com/repos/poky/trunk@2950 311d38ba-8fff-0310-9ca6-ca027cbcb966
Diffstat (limited to 'meta/classes/package.bbclass')
-rw-r--r-- | meta/classes/package.bbclass | 85 |
1 files changed, 82 insertions, 3 deletions
diff --git a/meta/classes/package.bbclass b/meta/classes/package.bbclass index 58de841666..e17627eaac 100644 --- a/meta/classes/package.bbclass +++ b/meta/classes/package.bbclass | |||
@@ -318,6 +318,76 @@ 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 | ||
321 | def 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 | |||
321 | python populate_packages () { | 391 | python populate_packages () { |
322 | import glob, stat, errno, re | 392 | import glob, stat, errno, re |
323 | 393 | ||
@@ -380,6 +450,8 @@ python populate_packages () { | |||
380 | pkgdest = bb.data.getVar('PKGDEST', d, 1) | 450 | pkgdest = bb.data.getVar('PKGDEST', d, 1) |
381 | os.system('rm -rf %s' % pkgdest) | 451 | os.system('rm -rf %s' % pkgdest) |
382 | 452 | ||
453 | seen = [] | ||
454 | |||
383 | for pkg in package_list: | 455 | for pkg in package_list: |
384 | localdata = bb.data.createCopy(d) | 456 | localdata = bb.data.createCopy(d) |
385 | root = os.path.join(pkgdest, pkg) | 457 | root = os.path.join(pkgdest, pkg) |
@@ -410,11 +482,17 @@ python populate_packages () { | |||
410 | continue | 482 | continue |
411 | if (not os.path.islink(file)) and (not os.path.exists(file)): | 483 | if (not os.path.islink(file)) and (not os.path.exists(file)): |
412 | continue | 484 | continue |
485 | if file in seen: | ||
486 | continue | ||
487 | seen.append(file) | ||
488 | if os.path.isdir(file): | ||
489 | bb.mkdirhier(os.path.join(root,file)) | ||
490 | continue | ||
413 | fpath = os.path.join(root,file) | 491 | fpath = os.path.join(root,file) |
414 | dpath = os.path.dirname(fpath) | 492 | dpath = os.path.dirname(fpath) |
415 | bb.mkdirhier(dpath) | 493 | bb.mkdirhier(dpath) |
416 | ret = bb.movefile(file,fpath) | 494 | ret = copyfile(file, fpath) |
417 | if ret is None or ret == 0: | 495 | if ret is False or ret == 0: |
418 | raise bb.build.FuncFailed("File population failed") | 496 | raise bb.build.FuncFailed("File population failed") |
419 | del localdata | 497 | del localdata |
420 | os.chdir(workdir) | 498 | os.chdir(workdir) |
@@ -423,7 +501,8 @@ python populate_packages () { | |||
423 | for root, dirs, files in os.walk(dvar): | 501 | for root, dirs, files in os.walk(dvar): |
424 | for f in files: | 502 | for f in files: |
425 | path = os.path.join(root[len(dvar):], f) | 503 | path = os.path.join(root[len(dvar):], f) |
426 | unshipped.append(path) | 504 | if ('.' + path) not in seen: |
505 | unshipped.append(path) | ||
427 | 506 | ||
428 | if unshipped != []: | 507 | if unshipped != []: |
429 | bb.note("the following files were installed but not shipped in any package:") | 508 | bb.note("the following files were installed but not shipped in any package:") |