Created
October 20, 2014 22:43
-
-
Save abadger/e37c0a50f5bf7f08dbc2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/files/file.py b/files/file.py | |
index ff9feb4..be7b05a 100644 | |
--- a/files/file.py | |
+++ b/files/file.py | |
@@ -151,56 +151,58 @@ def main(): | |
elif os.path.isdir(path): | |
prev_state = 'directory' | |
elif os.stat(path).st_nlink > 1: | |
prev_state = 'hard' | |
else: | |
# could be many other things, but defaulting to file | |
prev_state = 'file' | |
# state should default to file, but since that creates many conflicts, | |
# default to 'current' when it exists. | |
if state is None: | |
if prev_state != 'absent': | |
state = prev_state | |
else: | |
state = 'file' | |
# source is both the source of a symlink or an informational passing of the src for a template module | |
# or copy module, even if this module never uses it, it is needed to key off some things | |
if src is not None: | |
src = os.path.expanduser(src) | |
- | |
- # original_basename is used by other modules that depend on file. | |
- if os.path.isdir(path) and state not in ["link", "absent"]: | |
- if params['original_basename']: | |
- basename = params['original_basename'] | |
- else: | |
- basename = os.path.basename(src) | |
- params['path'] = path = os.path.join(path, basename) | |
else: | |
if state in ['link','hard']: | |
if follow: | |
# use the current target of the link as the source | |
src = os.readlink(path) | |
else: | |
module.fail_json(msg='src and dest are required for creating links') | |
+ # original_basename is used by other modules that depend on file. | |
+ if os.path.isdir(path) and state not in ["link", "absent"]: | |
+ basename = None | |
+ if params['original_basename']: | |
+ basename = params['original_basename'] | |
+ elif src is not None: | |
+ basename = os.path.basename(src) | |
+ if basename: | |
+ params['path'] = path = os.path.join(path, basename) | |
+ | |
# make sure the target path is a directory when we're doing a recursive operation | |
recurse = params['recurse'] | |
if recurse and state != 'directory': | |
module.fail_json(path=path, msg="recurse option requires state to be 'directory'") | |
file_args = module.load_file_common_arguments(params) | |
changed = False | |
if state == 'absent': | |
if state != prev_state: | |
if not module.check_mode: | |
if prev_state == 'directory': | |
try: | |
shutil.rmtree(path, ignore_errors=False) | |
except Exception, e: | |
module.fail_json(msg="rmtree failed: %s" % str(e)) | |
else: | |
try: | |
os.unlink(path) | |
except Exception, e: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment