1
0
Fork 0

Merge pull request #830 from yarda/write_to_file-errors-check

commands: better error msgs when creating directory and hardened dir mode
This commit is contained in:
Jaroslav Škarvada 2026-03-05 17:19:32 +01:00 committed by GitHub
commit ba8ee0871c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

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