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:
commit
ba8ee0871c
1 changed files with 8 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue