summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2015-09-08 11:39:08 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-09-09 14:25:04 +0100
commit9383af78adc854a6f6de8b1520edf3cea0c477a6 (patch)
tree152b781c7ff296b4d3e4758fe1353c30848294c0
parent0d0b8425eaf74a6d7f3d9f6471e6edca1a273c06 (diff)
downloadopenembedded-core-contrib-9383af78adc854a6f6de8b1520edf3cea0c477a6.tar.gz
openembedded-core-contrib-9383af78adc854a6f6de8b1520edf3cea0c477a6.tar.bz2
openembedded-core-contrib-9383af78adc854a6f6de8b1520edf3cea0c477a6.zip
devtool: improve modified file preservation to handle directory structures
Allow the _add_md5() function to be called with a directory in order to recursively add the files under it. Additionally, we need to skip preserving empty directories (since directories aren't listed in the md5 file). Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--scripts/lib/devtool/standard.py30
1 files changed, 21 insertions, 9 deletions
diff --git a/scripts/lib/devtool/standard.py b/scripts/lib/devtool/standard.py
index ee00c6d7b0..a5a20e3ae8 100644
--- a/scripts/lib/devtool/standard.py
+++ b/scripts/lib/devtool/standard.py
@@ -362,14 +362,23 @@ def _extract_source(srctree, keep_temp, devbranch, d):
return initial_rev
def _add_md5(config, recipename, filename):
- """Record checksum of a recipe to the md5-file of the workspace"""
+ """Record checksum of a file (or recursively for a directory) to the md5-file of the workspace"""
import bb.utils
- md5 = bb.utils.md5_file(filename)
- with open(os.path.join(config.workspace_path, '.devtool_md5'), 'a') as f:
- f.write('%s|%s|%s\n' % (recipename, os.path.relpath(filename, config.workspace_path), md5))
+
+ def addfile(fn):
+ md5 = bb.utils.md5_file(fn)
+ with open(os.path.join(config.workspace_path, '.devtool_md5'), 'a') as f:
+ f.write('%s|%s|%s\n' % (recipename, os.path.relpath(fn, config.workspace_path), md5))
+
+ if os.path.isdir(filename):
+ for root, _, files in os.walk(os.path.dirname(filename)):
+ for f in files:
+ addfile(os.path.join(root, f))
+ else:
+ addfile(filename)
def _check_preserve(config, recipename):
- """Check if a recipe was manually changed and needs to be saved in 'attic'
+ """Check if a file was manually changed and needs to be saved in 'attic'
directory"""
import bb.utils
origfile = os.path.join(config.workspace_path, '.devtool_md5')
@@ -830,10 +839,13 @@ def reset(args, config, basepath, workspace):
preservepath = os.path.join(config.workspace_path, 'attic', pn)
def preservedir(origdir):
if os.path.exists(origdir):
- for fn in os.listdir(origdir):
- logger.warn('Preserving %s in %s' % (fn, preservepath))
- bb.utils.mkdirhier(preservepath)
- shutil.move(os.path.join(origdir, fn), os.path.join(preservepath, fn))
+ for root, dirs, files in os.walk(origdir):
+ for fn in files:
+ logger.warn('Preserving %s in %s' % (fn, preservepath))
+ bb.utils.mkdirhier(preservepath)
+ shutil.move(os.path.join(origdir, fn), os.path.join(preservepath, fn))
+ for dn in dirs:
+ os.rmdir(os.path.join(root, dn))
os.rmdir(origdir)
preservedir(os.path.join(config.workspace_path, 'recipes', pn))