Allow writing byte strings with safe_write

Heat files map keeps file contents as byte string in
some cases (i.e. shell scripts). Decode them before
writing to archive.

Closes-Bug: #1915368
Change-Id: I3af14190ebb9d7efbb063299037bd51e38eccd83
This commit is contained in:
ramishra 2021-02-11 10:25:31 +05:30
parent f20fa8aaea
commit 3f6bfbaa69
1 changed files with 5 additions and 0 deletions

View File

@ -2402,6 +2402,11 @@ def safe_write(path, data):
path
)
try:
data = data.decode('utf-8', 'ignore')
except (UnicodeDecodeError, AttributeError):
pass
try:
with os.fdopen(os.open(path,
os.O_CREAT | os.O_TRUNC | os.O_WRONLY, 0o666),