diff options
author | Joshua Watt <JPEWhacker@gmail.com> | 2021-06-01 21:36:48 -0500 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2021-06-20 09:43:39 +0100 |
commit | 953031000a13569cc6084d1c8733a08d51ab8229 (patch) | |
tree | 366ad78fc678ad3c3b7b894e3eb7a4b00e07209f /meta | |
parent | bc5e349c1551c69e136d0c61e37064a1ca7ebe3b (diff) | |
download | poky-953031000a13569cc6084d1c8733a08d51ab8229.tar.gz |
classes/reproducible_build: Use atomic rename for SDE file
If an existing source date epoch file was found during do_unpack, it was
deleted and a new one would be written in its place. This causes a race
with check-before-use code in get_source_date_epoch_value. Resolve the
problem by making do_unpack write the new source date epoch to a
temporary file, then do an atomic rename to ensure it's always present,
and change the check-before-use code to use a EAFP exception instead of
checking for file existence.
[YOCTO #14384]
(From OE-Core rev: 8b2fd4e5e0841b81b4f709b061b655e2266dd4da)
Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
(cherry picked from commit 0b5e3b33187bf78a2d62cc886463e4b27d6bd228)
Signed-off-by: Anuj Mittal <anuj.mittal@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r-- | meta/classes/reproducible_build.bbclass | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/meta/classes/reproducible_build.bbclass b/meta/classes/reproducible_build.bbclass index f06e00d70d..1277764fab 100644 --- a/meta/classes/reproducible_build.bbclass +++ b/meta/classes/reproducible_build.bbclass | |||
@@ -77,17 +77,16 @@ python create_source_date_epoch_stamp() { | |||
77 | import oe.reproducible | 77 | import oe.reproducible |
78 | 78 | ||
79 | epochfile = d.getVar('SDE_FILE') | 79 | epochfile = d.getVar('SDE_FILE') |
80 | # If it exists we need to regenerate as the sources may have changed | 80 | tmp_file = "%s.new" % epochfile |
81 | if os.path.isfile(epochfile): | ||
82 | bb.debug(1, "Deleting existing SOURCE_DATE_EPOCH from: %s" % epochfile) | ||
83 | os.remove(epochfile) | ||
84 | 81 | ||
85 | source_date_epoch = oe.reproducible.get_source_date_epoch(d, d.getVar('S')) | 82 | source_date_epoch = oe.reproducible.get_source_date_epoch(d, d.getVar('S')) |
86 | 83 | ||
87 | bb.debug(1, "SOURCE_DATE_EPOCH: %d" % source_date_epoch) | 84 | bb.debug(1, "SOURCE_DATE_EPOCH: %d" % source_date_epoch) |
88 | bb.utils.mkdirhier(d.getVar('SDE_DIR')) | 85 | bb.utils.mkdirhier(d.getVar('SDE_DIR')) |
89 | with open(epochfile, 'w') as f: | 86 | with open(tmp_file, 'w') as f: |
90 | f.write(str(source_date_epoch)) | 87 | f.write(str(source_date_epoch)) |
88 | |||
89 | os.rename(tmp_file, epochfile) | ||
91 | } | 90 | } |
92 | 91 | ||
93 | def get_source_date_epoch_value(d): | 92 | def get_source_date_epoch_value(d): |
@@ -97,7 +96,7 @@ def get_source_date_epoch_value(d): | |||
97 | 96 | ||
98 | epochfile = d.getVar('SDE_FILE') | 97 | epochfile = d.getVar('SDE_FILE') |
99 | source_date_epoch = int(d.getVar('SOURCE_DATE_EPOCH_FALLBACK')) | 98 | source_date_epoch = int(d.getVar('SOURCE_DATE_EPOCH_FALLBACK')) |
100 | if os.path.isfile(epochfile): | 99 | try: |
101 | with open(epochfile, 'r') as f: | 100 | with open(epochfile, 'r') as f: |
102 | s = f.read() | 101 | s = f.read() |
103 | try: | 102 | try: |
@@ -110,7 +109,7 @@ def get_source_date_epoch_value(d): | |||
110 | bb.warn("SOURCE_DATE_EPOCH value '%s' is invalid. Reverting to SOURCE_DATE_EPOCH_FALLBACK" % s) | 109 | bb.warn("SOURCE_DATE_EPOCH value '%s' is invalid. Reverting to SOURCE_DATE_EPOCH_FALLBACK" % s) |
111 | source_date_epoch = int(d.getVar('SOURCE_DATE_EPOCH_FALLBACK')) | 110 | source_date_epoch = int(d.getVar('SOURCE_DATE_EPOCH_FALLBACK')) |
112 | bb.debug(1, "SOURCE_DATE_EPOCH: %d" % source_date_epoch) | 111 | bb.debug(1, "SOURCE_DATE_EPOCH: %d" % source_date_epoch) |
113 | else: | 112 | except FileNotFoundError: |
114 | bb.debug(1, "Cannot find %s. SOURCE_DATE_EPOCH will default to %d" % (epochfile, source_date_epoch)) | 113 | bb.debug(1, "Cannot find %s. SOURCE_DATE_EPOCH will default to %d" % (epochfile, source_date_epoch)) |
115 | 114 | ||
116 | d.setVar('__CACHED_SOURCE_DATE_EPOCH', str(source_date_epoch)) | 115 | d.setVar('__CACHED_SOURCE_DATE_EPOCH', str(source_date_epoch)) |