[SERVER-7046] On windows, mongo.exe should be written to %HOMEDRIVE%%%HOMEPATH%\.dbshell not .\dbshell Created: 16/Sep/12 Updated: 15/Feb/13 Resolved: 16/Sep/12 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Shell |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | Justin Dearing | Assignee: | Tad Marshall |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | Windows | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Windows |
||
| Issue Links: |
|
||||||||
| Backwards Compatibility: | Minor Change | ||||||||
| Operating System: | Windows | ||||||||
| Participants: | |||||||||
| Description |
|
When you run mongo.exe from the command line, it makes the .dbshell file in the working director, not in your user folder (e.g c:\Users\zippy or c:\Documents and Settings\zippy). Most ports of unix utilities write their dotfiles there, and this is expected behavior. |
| Comments |
| Comment by Tad Marshall [ 17/Sep/12 ] |
|
We're using the C runtime function 'fopen()' to open the file and we're passing it ' C:\Users\jdearing\.dbshell' (with the leading space) in your example. I guess the CRT has some interesting logic where when the path begins with a space it prepends the current working directory. Unless this causes issues with a lot of users, we'll probably just require that %USERPROFILE% be correctly set (as it should be by default). Thanks for testing it! |
| Comment by Justin Dearing [ 17/Sep/12 ] |
|
Tad, Just some followup, I ran mongo.exe 2.0.7 in c:\Users\jdearing\Documents\deleteme with procmon running. If I dont set HOME=%USERPROFILE% it opens C:\Users\jdearing\Documents\deleteme\.dbshell: 9:11:45.4172054 PM mongo.exe 6904 CreateFile C:\Users\jdearing\Documents\deleteme\.dbshell mongo NAME NOT FOUND Desired Access: Generic Read, Disposition: Open, Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: N, ShareMode: Read, Write, AllocationSize: n/a I do SET HOME=%USERPROFILE% it opens C:\Users\jdearing\.dbshell: 9:18:39.2361413 PM mongo.exe 3872 ReadFile C:\Users\jdearing\.dbshell mongo END OF FILE Offset: 96, Length: 4,096 An interesting edge case, if I do SET HOME= %USERPROFILE% then %HOME% is " C:\users\jdearing" (note the prepended space). Now if I run mongo it calls CreateFile on "C:\Users\jdearing\Documents\deleteme\ C:\Users\jdearing\.dbshell": 9:20:32.8800465 PM mongo.exe 8784 CreateFile C:\Users\jdearing\Documents\deleteme\ C:\Users\jdearing\.dbshell mongo NAME INVALID Desired Access: Generic Read, Disposition: Open, Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: N, ShareMode: Read, Write, AllocationSize: n/a In 2.2 its using the USERPROFILE variable on my machine. for all of the cases above behavior is the same if you manually set or unset USERPROFILE. |
| Comment by Scott Hernandez (Inactive) [ 16/Sep/12 ] |
|
HOME is not a normal windows env. var, afaik. You would need to add this manually, and that isn't really a fix for normal windows users. USERPROFILE is the standard var for this as defined by microsoft/windows and the one this patch added. It is equiv. to the unix home env. var. https://github.com/mongodb/mongo/blob/master/src/mongo/shell/shell_utils.cpp#L59 |
| Comment by Tad Marshall [ 16/Sep/12 ] |
|
Justin, can you see if HOME is defined in your environment, and if not whether defining it fixes the problem? Can you also verify that version 2.2.0 works correctly? |
| Comment by Scott Hernandez (Inactive) [ 16/Sep/12 ] |
|
This is not backported to 2.0.X; if we want to backport then mark the orig. issue such. |
| Comment by Tad Marshall [ 16/Sep/12 ] |
|
Version 2.0.7 apparently is looking for HOME instead of USERPROFILE. On my Windows 7 machine, I have both of these set. I'm not sure what determines whether or not one or the other of these is set. They could be have been created by something I installed and not be present on a "clean" install, or perhaps some upgrade path (e.g. Vista to Windows 7) sets them and another doesn't. I'm happy to change the code (or take a pull request) if you figure out what the right change is. I agree with you, .dbshell should go in your "user home" directory. |
| Comment by Justin Dearing [ 16/Sep/12 ] |
|
I am on Windows 7 and mongo 2.0.7 (I will upgrade and test, sorry for not checking my mongo version). %USERPROFILE% is properly set, and ss64.com says that is also set in XP, http://ss64.com/nt/syntax-variables.html Justin |
| Comment by Tad Marshall [ 16/Sep/12 ] |
|
The current code tries to use the contents of the USERPROFILE environment variable on Windows, and falls back to the behavior described above if it is not set. See shellHistoryInit() in src/mongo/shell/dbshell.cpp and getUserDir() in src/mongo/shell/shell_utils.cpp. Justin, do you have a USERPROFILE variable set? What version of Windows are you testing this on? We should probably have a more complete fallback algorithm if USERPROFILE is not set. There are additional ways that we could find the "home" directory beyond depending on a single environment variable. |