Gentoo Archives: gentoo-catalyst

From: Felix Bier <Felix.Bier@×××××××××××××.com>
To: "gentoo-catalyst@l.g.o" <gentoo-catalyst@l.g.o>
Subject: Re: [Newsletter] Re: [gentoo-catalyst] Re: [PATCH 1/2] Ensure deep copying of config defaults
Date: Tue, 10 Nov 2020 00:59:07
Message-Id: 870e91b2aee98b4b9a52e369d466e53444b1a273.camel@rohde-schwarz.com
In Reply to: Re: [gentoo-catalyst] Re: [PATCH 1/2] Ensure deep copying of config defaults by Matt Turner
1 This commit adds deep copying operations when initializing config
2 objects from a default config. This prevents the config from being
3 a shallow copy of the default, ensuring that modifications to the
4 config do not modify the default.
5
6 In particular, this fixes a check in write_make_conf, where the PORTDIR
7 variable is supposed to be only written to the generated make.conf when
8 a non-default repo_basedir is set in /etc/catalyst/catalyst.conf.
9 This check is never satisfied, because confvalues is a shallow copy of
10 confdefaults, therefore both will always hold the same value for
11 repo_basedir.
12
13 For self.mounts / MOUNT_DEFAULTS this problem can also be observed, the
14 modifications done to self.mounts are also visible in MOUNT_DEFAULTS.
15 I am not aware of any bugs due to this shallow copy, but I would prefer
16 adding a deep copy to prevent future bugs, in case a comparision
17 against the default mounts is ever needed.
18
19 Signed-off-by: Felix Bier <felix.bier@×××××××××××××.com>
20 ---
21 catalyst/base/stagebase.py | 3 ++-
22 catalyst/main.py | 3 ++-
23 2 files changed, 4 insertions(+), 2 deletions(-)
24
25 diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
26 index a75dbdf9..21cf96a0 100644
27 --- a/catalyst/base/stagebase.py
28 +++ b/catalyst/base/stagebase.py
29 @@ -1,4 +1,5 @@
30
31 +import copy
32 import os
33 import platform
34 import shutil
35 @@ -187,7 +188,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
36 file_locate(self.settings, ["portage_confdir"], expand=0)
37
38 # Setup our mount points.
39 - self.mount = MOUNT_DEFAULTS.copy()
40 + self.mount = copy.deepcopy(MOUNT_DEFAULTS)
41
42 self.mount['portdir']['source'] = self.snapshot
43 self.mount['portdir']['target'] = self.settings['repo_basedir'] + '/' + self.settings['repo_name']
44 diff --git a/catalyst/main.py b/catalyst/main.py
45 index 5536471a..48daf004 100644
46 --- a/catalyst/main.py
47 +++ b/catalyst/main.py
48 @@ -1,4 +1,5 @@
49 import argparse
50 +import copy
51 import datetime
52 import hashlib
53 import os
54 @@ -19,7 +20,7 @@ from catalyst.defaults import (confdefaults, option_messages,
55 from catalyst.support import CatalystError
56 from catalyst.version import get_version
57
58 -conf_values = confdefaults
59 +conf_values = copy.deepcopy(confdefaults)
60
61
62 def version():
63 --
64 2.29.2