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
User Home Folder and Documents Folder are incorrectly determined which leads to problems #bug #58
Comments
We don't use a hardcoded path for the home directory. We use https://docs.python.org/2.7/library/os.path.html#os.path.expanduser Please set correctly HOME and USERPROFILE environment variables. |
Please reopen the issue. The issues (bugs) still exist.I do not understand why the issue was closed without verifying the details and applying the provided reproduction steps. You are referring to a Phython function that PlatformIO is using but only mentioning that does not solve any of the issues that I am addressing. It is even possible that part of the issues is caused by that Python function. Please read my above description fully and VERIFY the issues by applying the reproduction steps. In response to your post, First
Second
says:
And WORSE: PlatformIO blatantly creates a Documents folder in UserProfile when the Documents Folder is not in its default location. How to fix the issues
Avoid these PitfallsNote the facts below and prevent any pitfalls caused by making 'your own' (incorrect) assumptions:
Attached is a simple C# example (GetUserFolderLocations.cpp.txt) with instructions that is very easy to run (without requiring an IDE). It demonstrates how UserProfile, Documents Folder and Home Folder locations can be correctly determined and displays their values. |
|
1. Please provide an output from python -c "import os; print os.path.expanduser('~')"
D:\Users\ PioUser>python -c "import os; print os.path.expanduser('~')"
C:\Users\ PioUser
and
D:\Users\PioUser>GetUserFolderLocations
UserProfile path is: C:\Users\PioUser
Home folder path is: D:\Users\PioUser
Documents folder path is: D:\Users PioUser\Documents
2. When creating new project please uncheck "Default location" and you will be able to use custom project folder.
Really? That would be a user experience hell.
It is PlatformIO that needs to be fixed, not its users. :-)
|
Thanks for reopening the issue. |
Could I close this issue? |
No of course you cannot close this issue. You should get it fixed in PlatformIO ! I like PlatformIO and I value the efforts from the PlatformIO team, |
In any case, we have separate issue which will allow to override default location for projects platformio/platformio-core#1161 |
Documents folder is THE STANDARD for user documents (which includes sourcecode etc.) in Windows. Can't believe that you have just closed the issue again. If you want to deliver good software you must properly follow the rules and guidelines for the platforms you are supporting, which in this case is Windows. |
Please provide an output of |
I am not going to dump that fully here (privacy). |
Do you see env var which is related to |
No, but that is what I already explained in my descriptions above: Avoid these PitfallsNote the facts below and prevent any pitfalls caused by making 'your own' (incorrect) assumptions:
(Thanks Microsoft...) Another option would be to read them from the registry, but this may also not be possible to do with Python (I don't know). |
When using Linux I can confirm that the PlatformIO extension in VSCode always tries to use %HOME%/Documents/PlatformIO/Projects. There is apparently no way to redefine this as a user as a general setting, which is quite annoying if one wants to use a custom directory structure in the HOME folder. I try to use a simple link %HOME%/Documents/PlatformIO/Projects to the project folder I would like to use, but the link was overwritten when a new project was created. |
Have you tried to overwrite it via http://docs.platformio.org/en/latest/userguide/cmd_settings.html#projects-dir ? |
Okay, it was not clear that the general pio settings are working here. Yes, the projects folder is also changed in vscode ide. |
This is still an issue. I use a limited sized SSD for my system drive and have an HDD for non-essential programs and data, that includes my Documents folder. I would prefer to have the Projects folder in that Documents folder, not on the system drive. Doing lots of development work on an SSD drastically reduces the write cycle lifespan of the drive! My home directory is C:\users\galbi but my Documents folder is at D:\Documents. To reproduce the problem yourself open an Explorer window using WIN+E, this should open the window at the "This PC" location. At the top you have the user folders. Right click Documents and select properties. There should be a "Location" tab, go to that. Now change the location of the Documents folder from there (the "Move..." button will move existing files to the new location which can take time). The correct way to get that location is reading it from the registry entries: You should never assume it's in the default location off of the user home directory. A quick Google on how to read the registry in Python reveals it can be done using the _winreg library. I'm new to Python so I can not give further details but I am sure you know how to obtain and use the library. Alternatively you could allow manual setting of the PlatformIO folder, or even just the Projects folder :) |
No, the registry is not the correct way to get these settings! The only CORRECT way to get these settings is by calling the Windows API (as described in the top post). I spent quite some efforts on this after opening the issue and I even did write some sample Python code to call the relevant Windows API but I have not bothered since (because there is a workaround). The workaround was already mentioned by @ivankravets above: Use the projects_dir setting to set a (global) custom projects directory. While the workaround works, it is ugly that one needs to use it for something that can be fixed in PlatformIO itself. |
We plan to add GUI for |
It is nice to have a GUI for |
The Windows API is just as subject to change as the registry so it's not future proof either, nothing is in the programming world. Just take a look at the API function you quoted, SHGetKnownFolderPath, it has gone through at least 3 name changes to get to how it's named now! The Windows API also gives software access to the registry which is where software is suposed to store settings, that's what the registry was designed for, to replace the multitude of .ini files. So accessing the registry directly is allowed making using the API not the only correct way. As Platform IO is written in Python for cross platform compatibility, used in VSC on Linux, MacOS and Windows, this issue is made more complex. I assume it would be easier to just read the registry directly in the place of using environment variables in Windows than to try and make it use the Windows API. As I said, I am new to Python so it's beyond my scope. But I am not new to Windows API and programming for Windows using C++, I've been doing it since the days of Windows 3.1, professionally until 2000 and on & off since then as one of many programming hobbies :) |
Still, using the registry is just bad practice. API is public interface, registry is implementation details. Api access from Python is possible. I have done it when I opened this issue. |
Well, we have given them the info on how to fix it, whether or not they impliment either way is yet to be seen but looking at the time span between your OP and today where it's still an issue it looks like they just do not take it seriously enough. But it is serious for users like me who do not want to do compiling and development work on an SSD which has a finite number of times it can be written to. For now I will have to use symbolic links to force it to use the D: drive. Not ideal but it works :) |
I just came here after spending hours to try and fix the problems created by this issue and was astonished to read that it has been a known issue since 2017. In my case, I use OneDrive, which moves the Documents folder (and references to it) to inside the OneDrive folder. Every_single_one of my windows applications know how to deal with this, by just following Windows recommended practices, EXCEPT for PIO. The fact that this issue keeps getting closed without a fix reflects very poorly on the quality of the Platformio project. |
@qvdm Have you read all comments in this issue? If no, please re-read. The issue is very specific to your OS. PlatformIO is cross-platform tool and Windows is one of the OS which it supports. We use Python API to get the user home directory. There is a setting which you can override if don't like default value. See http://docs.platformio.org/en/latest/userguide/cmd_settings.html#projects-dir
Do you have enough software/architect expertise to say that? P.S: This is free and open source project. I recommend helping improve it instead of claiming that this is "very poor and low-quality project". |
People in this thread, could you open your system terminal and type command below:
Do you see a valid value for your documents directory? |
The command above reports the correct location of the documents directory for me (i.e. not the location that Platformio uses). |
Resolved in platformio/platformio-core@ffcf6b8 Please re-test with upcoming PlatformIO Core 4.0 => https://community.platformio.org/t/platformio-core-4-0-beta/8304 |
PlatformIO incorrectly determines the locations of the user's Home Folder and Documents Folder.
This leads to serious problems when the folders are not in the default situation, which is often the case when developers put these on a separate (e.g. D:) drive (separate user data from OS).
PlatformIO appears to assume that Windows has a 'Home Directory' just like Linux but Windows has not. Windows has the concept of a 'User Folder' but it is not identical to and does not behave identical to a user Home Directory on Linux (this is explained below).
WHEN DO THE ISSUES HAPPEN
but e.g. D:\Users\<username>.
WHAT HAPPENS
The Documents Folder is a special directory in Windows. Its location should be queried via a special Windows API. But PlatformIO incorrectly assumes that it is allways C:%HOMEPATH%\Documents which is WRONG!
Because PlatformIO uses an incorrect location for the Documents Folder it will put all projects in the wrong drive/location and the user is UNABLE to change this incorrect PlatformIO behavior.
PlatformIO project will be on the wrong drive!
REPRODUCTION STEPS
Requirement: You will need an additional drive to the C: drive (D: will be most logical).
Steps to reproduce:
(This can later be reversed to restore the original situation.)
(This proces can be reversed later by repeating similarly and relocate back to C:).
(This can be reversed later by removing the string again or change the D: to C:).
When you open a command prompt the current directory will now be the new Home Folder on the D: drive.
HOW TO VERIFY THE PROBLEMS
After performing the reproduction step:
PlatformIO IDE (installer) has created a 'Documents' directory and it has placed the PlatformIO and Projects in there, on the C: drive!
Notice that the real Documents Folder (which was previously relocated) is still located at the D: drive, NOT the C: drive.
HOW TO FIX:
Notes: The Home Folder can point to the same location as User Folder but it can also be different and even point to a different drive.
DO NOT make assumptions based on (non-)existence of C:\Users\<username>\Documents (nor on %HOMEDRIVE%%HOMEPATH%\Documents) because it cannot be relied upon.
Notes: The location of Documents can be different from User Folder and different from Home Folder (meaning it does not have to be a subdirectory of them) and can even be located on a different drive.
The (relocated) location of the Documents folder is technically unrelated to the location(s) of User Folder and Home Folder.
WHAT PLATFORMIO CURRENTLY DOES WRONG
PlatformIO appears to use Home Folder as the 'user's root folder' which is displayed in file dialogs under 'Places' as the user's username.
PlatformIO uses only HOMEPATH for determining the Home Folder location but not HOMEDRIVE and uses a hard-coded "C:" for HOMEDRIVE instead.
PlatformIO assumes that the Documents folder is a subdirectory of the Home Folder, which is true only in default situations but not in many common non-default situations.
PlatformIO should use Windows API's to query for the actual location of the Documents special folder instead.
When PlatformIO does not find the Documents folder where it expects it then it creates a Documents folder there itself (bad!). PlatformIO should never touch the Documents Folder itself and leave that to the operating system.
DETAILED DESCRIPTION OF THE UNDERLYING ISSUES
Windows does not have a well defined concept of 'User Home Directory' like Linux. Windows has a concept called the 'User Folder" which is similar but not identical to a user's Home directory on Linux (a folder is a directory).
In recent Windows versions Microsoft is hiding the user from the concept of the 'User Folder' (probably because it is inconsistent and not well defined). Windows is presenting the user special folders like Documents, Pictures, Music, Desktop, Downloads etc. instead.
PlatformIO on Windows uses the User Folder like it uses the User Home Directory on Linux.
But it determines the 'Home Folder' incorrectly. It does not take into account the drive and uses a hard-coded value for the drive instead. This does not become visible in default situations but it leads to problems in (common) non-default situations.
In recent Windows versions (Windows 8 and onward at least) there is a "Users" directory in the root of the C: drive. This is where Windows stores User Folders.
I will use a sample male user with username piouser in the rest of the text. Piouser's User Folder is: C:\Users\piouser.
The User Folder contains at least the following:
Applications that do not conform to Windows guidelines for location of user-related (configuration) data will often make their own - sometimes false - assumptions. PlatformIO included.
In practice it is often desired to separate storage of the operating system from storage of user data (documents, source code etc.') and put these on different disks. Reasons can be related to making of backups, easier repair of corrupt OS images, performance and can be related to the type and size of available disks.
Windows unfortunately does not allow a User Folder to be stored on a different disk than where the operating system is stored (C:). It cannot successfully cope with that.
Feature:
It is possible to place special folders like Documents, Pictures, Video, Videos, Downloads, Desktop etc. in a different location on a different disk! This is supported by the Windows operating system.
This is done by changing the Location property of a special folder and then letting Windows move its contents.
IMPORTANT: When taking the Documents special folder as an example, when Documents is relocated/moved (by changing its Location property) to different location e.g. on a different drive, then it will be REMOVED from its old location in the User Folder and nothing will be put in its place as a place holder, not even a symbolic link. So it is not possible to determine the new location of Documents by inspecting the User Folder, nor do any environment variables exist to assist that. The current location of the Documents folder (and other special folders) can only be determined reliably by quering the operating system via Windows API's.
(I always create a directory D:\Users to separate the storage location (disk) for user data storage from the storage location (disk) of the operating system (many Windows developers do). In that new Users directory I create a 'Home Folder' (e.g. D:\Users\piouser) and then relocate al Special Folders from my User Folder to my new Home Folder (e.g. C:\Users\piouser\Documents to D:\Users\piouser\Documents.)
If directory C:\Users\piouser\Documents is missing this should alarm an installer that the situation is not default and indicates that the Documents folder has been relocated. An application should never make it's own assumptions and always query the operating system for the actual location of standard Special Folders.
But the PlatformIO installer does NOT. If PLatformIO finds C:\Users\piouser\Documents missing then it will just create a C:\Users\piouser\Documents (ouch) and create a PlatformIO subdirectory (with Projects subdirectory) in the self-created Documents directory. This is bad practice and leads to problems for (common) non-default situations.
Feature:
User Folders are located on the C: drive in C:\Users but there is also the concept of 'Home folder'.
'Home folder' is the directory pointed to by a combination of the environment variables HOMEDRIVE and HOMEPATH.
HOMEDRIVE contains only the drive and HOMEPATH contains the path relative to the root of the drive (but not the drive). In Linux ~ refers to the full path of the user's Home directory. Not so in Windows (and there is nothing comparable to ~ on Linux).
Feature:
'Home folder' and therefore the values of HOMEDRIVE and HOMEPATH are determined by the value of: 'User properties/Profile tab/Home folder/Local path'. This value is empty by default which means that Home folder points to the same location as User Folder but they can also be different and Home folder can even point to a different drive.
Feature
Changing the value of Home folder/Local path does effect the values of HOMEDRIVE and HOMEPATH but it does not have any effect on (the use of) the User Folder, nor does it have any effect on standard Special Folders, neither in their default location nor when relocated.
So it turns out that User Folder, Home Folder and Special Folders are inconsistent and they can all point to different locations and different drives which does not make things easier.
The text was updated successfully, but these errors were encountered: