-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
os.path.dirname not doing what you think in file.makedirs_ if the path excludes a trailing slash #14019
Comments
Ooh, good catch. At the very least we should do 3, but we should probably take additional steps as well. Can you clarify, just for completeness, which version of salt you're looking at, and where those lines of code come from? Thanks! |
We're on 2014.1.5 on the master and minion in question. Those lines are from modules/file.py in the makedirs_ function (lines 2818-2827 in the version in the copy of the source from EPEL). |
Thanks. I'm going to run some tests and look at this later. |
@basepi We can check if the path that the user enters ends with a trailing slash or not. If it does then we have no problem but if it doesn't then we can append a trailing slash to it and that's all.
Do you want me to work on this? |
@nmadhok Try the case where the directory doesn't exist and you omit the trailing slash i.e. /etc/foo It will report that Directory '/etc/foo' already exists. |
@mikejford Yeah i just figured. Working on this. Thanks for finding the bug! |
Thanks for tackling this, @nmadhok ! |
Here try this @mikejford! Fix:
Note that the following works too:
Both fixes won't get the directory path in case the user gives the path as The fix to that is to change the order:
|
@nmadhok I think you got something out of order in your sample above. There's three closing parens in the samples that show the dirname, and two closing parens in the sample with the path with a file. When you run the last with a dirname as a path, it cuts the last value from the string still.
|
@basepi I think there's a fundamental question about what the action of makedirs should be. If it's supposed to replicate the functionality of mkdir -p from unix, then the name argument should simply be considered a full directory path that is desired. There shouldn't be a consideration of filenames at all except for the case that the node already exists as a file type. |
@mikejford You're right. I didn't test the directories with The correct way to go i feel should be using The user shouldn't specify path to a file but the directory path itself. |
@nmadhok The merged code doesn't use the version you believe is the correct form. That's where I'm still taking issue. |
@mikejford Changing it right away. Thanks for pointing it out. |
Changed the docs. #14488 |
@basepi This issue can be closed! |
I just ran a simple test of what's going on in makedirs_ because I couldn't understand why a directory wasn't being created on the minion. The sample below shows a directory I know to exist on the host, and the command that is being used in makedirs_ to assign the path to dirname. Note that I did not include the trailing slash on the path.
The message to the user is wrong, since dirname was the value that was tested by os.path.isdir but path is the value sent back to the user in the return message.
I'm not sure what would be preferable here as a solution:
The text was updated successfully, but these errors were encountered: