mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Double check whether the parent directory really exists using stat()
Fixes #7760
This commit is contained in:
parent
360d8b0fc2
commit
aac194e639
1 changed files with 9 additions and 0 deletions
|
@ -190,6 +190,15 @@ def main():
|
||||||
md5sum_dest = module.md5(dest)
|
md5sum_dest = module.md5(dest)
|
||||||
else:
|
else:
|
||||||
if not os.path.exists(os.path.dirname(dest)):
|
if not os.path.exists(os.path.dirname(dest)):
|
||||||
|
try:
|
||||||
|
# os.path.exists() can return false in some
|
||||||
|
# circumstances where the directory does not have
|
||||||
|
# the execute bit for the current user set, in
|
||||||
|
# which case the stat() call will raise an OSError
|
||||||
|
os.stat(os.path.dirname(dest))
|
||||||
|
except OSError, e:
|
||||||
|
if "permission denied" in str(e).lower():
|
||||||
|
module.fail_json(msg="Destination directory %s is not accessible" % (os.path.dirname(dest)))
|
||||||
module.fail_json(msg="Destination directory %s does not exist" % (os.path.dirname(dest)))
|
module.fail_json(msg="Destination directory %s does not exist" % (os.path.dirname(dest)))
|
||||||
if not os.access(os.path.dirname(dest), os.W_OK):
|
if not os.access(os.path.dirname(dest), os.W_OK):
|
||||||
module.fail_json(msg="Destination %s not writable" % (os.path.dirname(dest)))
|
module.fail_json(msg="Destination %s not writable" % (os.path.dirname(dest)))
|
||||||
|
|
Loading…
Add table
Reference in a new issue