Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Add makedirs support to file.rename

Fix #1447
  • Loading branch information...
commit 8e51797e0f41cf91fb23d0d23ca6a1cec1c07deb 1 parent b9b0a36
@thatch45 thatch45 authored
Showing with 16 additions and 10 deletions.
  1. +16 −10 salt/states/
26 salt/states/
@@ -1668,17 +1668,14 @@ def rename(name, source, force=False, makedirs=False):
The location of the file to rename to
- The location
+ The location of the file to move to the location specified with name
- source_hash:
- This can be either a file which contains a source hash string for
- the source, or a source hash string. The source hash string is the
- hash algorithm followed by the hash of the file:
- md5=e138491e9d5b97023cea823fe17bac22
+ force:
+ If the target location is present then the file will not be moved,
+ specify "force: True" to overwrite the target file
- user
- The user to own the file, this defaults to the user salt is running as
- on the minion
+ makedirs:
+ If the target subdirectories don't exist create them
ret = {
@@ -1709,7 +1706,16 @@ def rename(name, source, force=False, makedirs=False):
ret['result'] = None
return ret
+ # Run makedirs
+ dname = os.path.dirname(name)
+ if not os.path.isdir(dname):
+ if makedirs:
+ os.makedirs(dname)
+ else:
+ return _error(
+ ret,
+ 'The target directory {0} is not present'.format(dname))
+ # All tests pass, move the file into place
shutil.move(source, name)
except (IOError, OSError):

0 comments on commit 8e51797

Please sign in to comment.
Something went wrong with that request. Please try again.