Skip to content
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

Use XDG conventions on macOS too #319

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

utkarshgupta137
Copy link

Fixes #311.

@dbrgn
Copy link
Owner

dbrgn commented Apr 22, 2023

Hi, thanks for the PR. Some questions before I take a closer look:

  • In the base configuration (if no XDG variables are set), will this use the same directories as before on non-macOS systems? Have you verified that this does not modify the directory paths on Windows and Linux?
  • In #311, the request was to use XDG conventions if XDG variables are set, but not by default. This makes sense, as we should follow the local OS conventions by default. Does etcetera implement this logic? From what I can tell, it will always use XDG conventions. This would be a breaking change for Tealdeer users on macOS (not just the cache will be created a second time in a different location without the old cache being cleaned up, but if a config file is present in the previous location, it will be ignored).

@utkarshgupta137
Copy link
Author

utkarshgupta137 commented Apr 22, 2023

Hi, thanks for the PR. Some questions before I take a closer look:

* In the base configuration (if no XDG variables are set), will this use the same directories as before on non-macOS systems? Have you verified that this does not modify the directory paths on Windows and Linux?

* In [#311](https://github.com/dbrgn/tealdeer/issues/311), the request was to use XDG conventions _if_ XDG variables are set, but not by default. This makes sense, as we should follow the local OS conventions by default. Does etcetera implement this logic? From what I can tell, it will always use XDG conventions. This would be a breaking change for Tealdeer users on macOS (not just the cache will be created a second time in a different location without the old cache being cleaned up, but if a config file is present in the previous location, it will be ignored).

Ugh, looks like app_dirs2 doesn't follow the convention on Windows of most other "dirs" crates out there. Linux users won't be affected, but I can modify the code to retain the same behavior on Windows. I don't use CLI tools on Windows, so I've no strong opinions about it.

No, right now this PR makes no effort to maintain backward compatibility on macOS. IMO, no macOS users expect the config file to be located in ~/Library/Application Support. Almost every CLI tool which uses the dirs/dirs-next crates & other clones has open or closed issues of users wanting to use the XDG conventions on macOS. But I've yet to come across a case where the inverse is true. I've written more about this here.
Secondly, I don't think it is a good idea to half-ass the XDG convention. If a user who has previously not set it decides to set it for whatever reason, then they may be confused why some unrelated tool is broken. Same if they remove it for any reason.
However, since you probably want to maintain backward compatibility, I can add migration code to move the old data to the new location, similar to this: https://github.com/cantino/mcfly/pull/349/files#diff-4f91d834bba4a3a432715f3ccf4ebc7c10d7ecfb974f1e78f56108dd80581a53R392-R404

@utkarshgupta137
Copy link
Author

Fixed & test on Windows:

PS C:\Users\Utkarsh Gupta\Downloads\tealdeer-main> ..\tealdeer-windows-x86_64-msvc.exe --show-paths
Config dir:       C:\Users\Utkarsh Gupta\AppData\Roaming\tealdeer\tealdeer\ (OS convention)
Config path:      C:\Users\Utkarsh Gupta\AppData\Roaming\tealdeer\tealdeer\config.toml
Cache dir:        C:\Users\Utkarsh Gupta\AppData\Local\tealdeer\tealdeer (OS convention)
Pages dir:        C:\Users\Utkarsh Gupta\AppData\Local\tealdeer\tealdeer\tldr-pages\
Custom pages dir: C:\Users\Utkarsh Gupta\AppData\Local\tealdeer\tealdeer\pages\ (OS convention)

PS C:\Users\Utkarsh Gupta\Downloads\tealdeer-main> .\target\release\tldr.exe --show-paths
Config dir:       C:\Users\Utkarsh Gupta\AppData\Roaming\tealdeer\tealdeer\ (Windows convention)
Config path:      C:\Users\Utkarsh Gupta\AppData\Roaming\tealdeer\tealdeer\config.toml
Cache dir:        C:\Users\Utkarsh Gupta\AppData\Local\tealdeer\tealdeer (Windows convention)
Pages dir:        C:\Users\Utkarsh Gupta\AppData\Local\tealdeer\tealdeer\tldr-pages\
Custom pages dir: C:\Users\Utkarsh Gupta\AppData\Local\tealdeer\tealdeer\pages (Windows convention)

@utkarshgupta137
Copy link
Author

utkarshgupta137 commented Apr 22, 2023

I should mention that is weird that app_dirs2 uses the same location for cache & user data. The popular directories and most of its clones put the data & config together, not the data & cache.
Edit: According to many articles, the Local folder is not supposed to be synced while the Roaming folder is supposed to be synced. So I guess it would make sense to have the custom pages dir in the Roaming folder. Again, I don't use CLI on Windows, so I don't have a strong opinion.

@utkarshgupta137
Copy link
Author

@dbrgn If you want, I can add a fallback to ~/Library/Application Support as well.

@utkarshgupta137
Copy link
Author

@dbrgn ping

@niklasmohrin
Copy link
Collaborator

Let's discuss the transition period in the issue thread first :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Respect XDG_* variables on macos if set
3 participants