[oe-commits] org.oe.dev package.bbclass: Stop do_package from being destructive by copying instead of moving files (from poky). The copyfile function will be moved to bitbake in due course.

rpurdie commit openembedded-commits at lists.openembedded.org
Mon Nov 5 20:21:42 UTC 2007


package.bbclass: Stop do_package from being destructive by copying instead of moving files (from poky). The copyfile function will be moved to bitbake in due course.

Author: rpurdie at openembedded.org
Branch: org.openembedded.dev
Revision: 32fb34a3d6b83b091f671bba6f6fb90146a59544
ViewMTN: http://monotone.openembedded.org/revision/info/32fb34a3d6b83b091f671bba6f6fb90146a59544
Files:
1
classes/package.bbclass
Diffs:

#
# mt diff -r1c37802f675e2b4ebbb302f90f516adf37617e96 -r32fb34a3d6b83b091f671bba6f6fb90146a59544
#
# 
# 
# patch "classes/package.bbclass"
#  from [c40a90879037567f4894a6044537289dc71ffe3c]
#    to [1713a1d39b0249350a2277e9d734d92d920aaf16]
# 
============================================================
--- classes/package.bbclass	c40a90879037567f4894a6044537289dc71ffe3c
+++ classes/package.bbclass	1713a1d39b0249350a2277e9d734d92d920aaf16
@@ -318,6 +318,76 @@ 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
 
@@ -380,6 +450,8 @@ python populate_packages () {
 	pkgdest = bb.data.getVar('PKGDEST', d, 1)
 	os.system('rm -rf %s' % pkgdest)
 
+	seen = []
+
 	for pkg in package_list:
 		localdata = bb.data.createCopy(d)
 		root = os.path.join(pkgdest, pkg)
@@ -410,11 +482,17 @@ python populate_packages () {
 					continue
 			if (not os.path.islink(file)) and (not os.path.exists(file)):
 				continue
+			if file in seen:
+				continue
+			seen.append(file)
+			if os.path.isdir(file):
+				bb.mkdirhier(os.path.join(root,file))
+				continue
 			fpath = os.path.join(root,file)
 			dpath = os.path.dirname(fpath)
 			bb.mkdirhier(dpath)
-			ret = bb.movefile(file,fpath)
-			if ret is None or ret == 0:
+			ret = copyfile(file, fpath)
+			if ret is False or ret == 0:
 				raise bb.build.FuncFailed("File population failed")
 		del localdata
 	os.chdir(workdir)
@@ -423,7 +501,8 @@ python populate_packages () {
 	for root, dirs, files in os.walk(dvar):
 		for f in files:
 			path = os.path.join(root[len(dvar):], f)
-			unshipped.append(path)
+			if ('.' + path) not in seen:
+				unshipped.append(path)
 
 	if unshipped != []:
 		bb.note("the following files were installed but not shipped in any package:")






More information about the Openembedded-commits mailing list