mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
file: Recover from unexpectedly disappearing files (#42281)
This commit is contained in:
parent
8eb1e8c0e6
commit
198b62b906
1 changed files with 17 additions and 11 deletions
|
@ -33,7 +33,7 @@ author:
|
||||||
options:
|
options:
|
||||||
path:
|
path:
|
||||||
description:
|
description:
|
||||||
- 'path to the file being managed. Aliases: I(dest), I(name)'
|
- Path to the file being managed.
|
||||||
required: true
|
required: true
|
||||||
aliases: [ dest, name ]
|
aliases: [ dest, name ]
|
||||||
state:
|
state:
|
||||||
|
@ -212,6 +212,7 @@ def get_state(path):
|
||||||
''' Find out current state '''
|
''' Find out current state '''
|
||||||
|
|
||||||
b_path = to_bytes(path, errors='surrogate_or_strict')
|
b_path = to_bytes(path, errors='surrogate_or_strict')
|
||||||
|
try:
|
||||||
if os.path.lexists(b_path):
|
if os.path.lexists(b_path):
|
||||||
if os.path.islink(b_path):
|
if os.path.islink(b_path):
|
||||||
return 'link'
|
return 'link'
|
||||||
|
@ -224,6 +225,11 @@ def get_state(path):
|
||||||
return 'file'
|
return 'file'
|
||||||
|
|
||||||
return 'absent'
|
return 'absent'
|
||||||
|
except OSError as e:
|
||||||
|
if e.errno == errno.ENOENT: # It may already have been removed
|
||||||
|
return 'absent'
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
# This should be moved into the common file utilities
|
# This should be moved into the common file utilities
|
||||||
|
|
Loading…
Reference in a new issue