1
0
Fork 0

commands: better error msgs when creating directory and hardened dir mode

The directory mode should be already hardened with the umask on most systems,
so it shouldn't be the default 0x777, but rather be explicit with the saner
0x755.

Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
This commit is contained in:
Jaroslav Škarvada 2026-03-03 20:24:50 +01:00
parent 38d4414a85
commit 1f8cb72734
No known key found for this signature in database
GPG key ID: D8E1C00E076E840B

View file

@ -108,9 +108,15 @@ class commands:
d = os.path.dirname(f)
if os.path.isdir(d):
makedir = False
if makedir:
try:
os.makedirs(d, mode=0o755)
except (OSError, IOError) as e:
if isinstance(no_error, bool) and not no_error or \
isinstance(no_error, list) and e.errno not in no_error:
self._error("Unable to create directory '%s', error: '%s'" % (d, e))
return False
try:
if makedir:
os.makedirs(d)
if ignore_same and self.read_file(f, no_error=True).strip() == str(data):
self._debug("Skipping the write to file '%s', the content would not change" % f)
return True