From f0203a072c20a5c82074b713cc0b61654ccfabb1 Mon Sep 17 00:00:00 2001 From: Kevin Kofler Date: Fri, 28 Nov 2014 18:29:34 +0100 Subject: [PATCH] unpackfs: Automatically detect the exclude list from the mounts. See issue #173. --- src/modules/unpackfs/main.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/modules/unpackfs/main.py b/src/modules/unpackfs/main.py index 0ae17d08a..2d62b07ba 100644 --- a/src/modules/unpackfs/main.py +++ b/src/modules/unpackfs/main.py @@ -42,6 +42,19 @@ class UnpackEntry: ON_POSIX = 'posix' in sys.builtin_module_names +def list_excludes(destination): + prefix = destination.replace('//', '/') + if not prefix.endswith('/'): + prefix = prefix + '/' + lst = [] + for line in open('/etc/mtab').readlines(): + device, mount_point, _ = line.split(" ", 2) + if mount_point.startswith(prefix): + # -1 to include the / at the end of the prefix + lst.extend(['--exclude', mount_point[len(prefix)-1:]]) + return lst + + def file_copy(source, dest, progress_cb): # Environment used for executing rsync properly # Setting locale to C (fix issue with tr_TR locale) @@ -53,7 +66,10 @@ def file_copy(source, dest, progress_cb): # "/dest", then files will be copied in "/dest/bar". source += "/" - process = subprocess.Popen(['rsync', '-aHAXr', '--exclude', '/dev/', '--exclude', '/proc/', '--exclude', '/sys/', '--exclude', '/run/', '--progress', source, dest], + args = ['rsync', '-aHAXr'] + args.extend(list_excludes(dest)) + args.extend(['--progress', source, dest]) + process = subprocess.Popen(args, env=at_env, bufsize=1, stdout=subprocess.PIPE,