From d58fdaa2cde86feeeb6865b9ecbdae70c94dff3a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 8 Oct 2019 15:00:25 +0200 Subject: [PATCH 1/4] [unpackfs] Stub of special handling for a single file --- src/modules/unpackfs/main.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/modules/unpackfs/main.py b/src/modules/unpackfs/main.py index fd3f97353..b6cdd76a0 100644 --- a/src/modules/unpackfs/main.py +++ b/src/modules/unpackfs/main.py @@ -303,6 +303,10 @@ class UnpackOperation: try: if entry.is_file(): source = entry.source + if entry.total <= 1: + # If there is one file, *and* the target does not exist (as a file or dir) + # but the dirname of the target does, we should copy just one file and rename. + pass else: source = imgmountdir From 05c039812689666d3386f39f211a3f5e11308239 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 8 Oct 2019 16:19:39 +0200 Subject: [PATCH 2/4] [unpackfs] Support multiple items better - it's ok if item one creates directories where item two will write, so don't check for existence of all directories on start-up. Reported by ArcoLinux. --- src/modules/unpackfs/main.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/modules/unpackfs/main.py b/src/modules/unpackfs/main.py index b6cdd76a0..0c511b959 100644 --- a/src/modules/unpackfs/main.py +++ b/src/modules/unpackfs/main.py @@ -378,6 +378,7 @@ def run(): unpack = list() + is_first = True for entry in job.configuration["unpack"]: source = os.path.abspath(entry["source"]) sourcefs = entry["sourcefs"] @@ -385,10 +386,14 @@ def run(): if not os.path.isdir(destination): utils.warning(("The destination \"{}\" in the target system is not a directory").format(destination)) - return (_("Bad unsquash configuration"), - _("The destination \"{}\" in the target system is not a directory").format(destination)) + if is_first: + return (_("Bad unsquash configuration"), + _("The destination \"{}\" in the target system is not a directory").format(destination)) + else: + utils.debug(".. assuming that the previous targets will create that directory.") unpack.append(UnpackEntry(source, sourcefs, destination)) + is_first = False unpackop = UnpackOperation(unpack) From 4acf63fd9adbca56e6431bc1d317db2e110f179a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 8 Oct 2019 17:31:51 +0200 Subject: [PATCH 3/4] [unpackfs] Document fields of the UnpackEntry - Document fields - While here, remove code for special-casing single-file copies. Those already work, based on rsync. --- src/modules/unpackfs/main.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/modules/unpackfs/main.py b/src/modules/unpackfs/main.py index 0c511b959..3a64c6284 100644 --- a/src/modules/unpackfs/main.py +++ b/src/modules/unpackfs/main.py @@ -52,6 +52,17 @@ class UnpackEntry: __slots__ = ['source', 'sourcefs', 'destination', 'copied', 'total'] def __init__(self, source, sourcefs, destination): + """ + @p source is the source file name (might be an image file, or + a directory, too) + @p sourcefs is a type indication; "file" is special, as is + "squashfs". + @p destination is where the files from the source go. This is + **already** prefixed by rootMountPoint, so should be a + valid absolute path within the host system. + + The members copied and total are filled in by the copying process. + """ self.source = source self.sourcefs = sourcefs self.destination = destination @@ -85,7 +96,6 @@ def list_excludes(destination): return lst - def file_copy(source, dest, progress_cb): """ Extract given image using rsync. @@ -303,10 +313,6 @@ class UnpackOperation: try: if entry.is_file(): source = entry.source - if entry.total <= 1: - # If there is one file, *and* the target does not exist (as a file or dir) - # but the dirname of the target does, we should copy just one file and rename. - pass else: source = imgmountdir From 57c0b2088c266d7d9feed7a9a0ebe3a35f0494ef Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 11 Oct 2019 15:36:39 +0200 Subject: [PATCH 4/4] [unpackfs] Allow naming a non-directory for single files - this enables renaming files on copy --- src/modules/unpackfs/main.py | 6 +++--- src/modules/unpackfs/unpackfs.conf | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/modules/unpackfs/main.py b/src/modules/unpackfs/main.py index 3a64c6284..a9e6ea067 100644 --- a/src/modules/unpackfs/main.py +++ b/src/modules/unpackfs/main.py @@ -58,9 +58,9 @@ class UnpackEntry: @p sourcefs is a type indication; "file" is special, as is "squashfs". @p destination is where the files from the source go. This is - **already** prefixed by rootMountPoint, so should be a + **already** prefixed by rootMountPoint, so should be a valid absolute path within the host system. - + The members copied and total are filled in by the copying process. """ self.source = source @@ -390,7 +390,7 @@ def run(): sourcefs = entry["sourcefs"] destination = os.path.abspath(root_mount_point + entry["destination"]) - if not os.path.isdir(destination): + if not os.path.isdir(destination) and sourcefs != "file": utils.warning(("The destination \"{}\" in the target system is not a directory").format(destination)) if is_first: return (_("Bad unsquash configuration"), diff --git a/src/modules/unpackfs/unpackfs.conf b/src/modules/unpackfs/unpackfs.conf index d994e351a..e81a90b0a 100644 --- a/src/modules/unpackfs/unpackfs.conf +++ b/src/modules/unpackfs/unpackfs.conf @@ -60,8 +60,13 @@ # - source: ../src/modules/dummycpp # sourcefs: file # destination: "/tmp/derp" +# +# The *destination* and *source* are handed off to rsync, so the semantics +# of trailing slashes apply. In order to *rename* a file as it is +# copied, specify one single file (e.g. CHANGES) and a full pathname +# for its destination name, as in the example below. unpack: - source: ../CHANGES sourcefs: file - destination: "/tmp" + destination: "/tmp/changes.txt"