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

Store state files in $XDG_STATE_HOME by default #3185

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bartekpacia
Copy link
Contributor

This PR is targeted at #3176

@bartekpacia
Copy link
Contributor Author

@JoeKar So far I only updated the docs. Please let me know if such changes make sense, so I can start implementing them.

@bartekpacia bartekpacia marked this pull request as draft March 17, 2024 17:43
@dmaluka
Copy link
Collaborator

dmaluka commented Mar 17, 2024

This isn't gonna be backwards compatible, is it?

@bartekpacia
Copy link
Contributor Author

bartekpacia commented Mar 17, 2024

I was thinking about it, but in the initial proposal I decided to omit this. But I definitely would like to make this change completely painless for everyone. Making anyone lose time over such a minor change would be unprofessional.

By "backward compatibility", do you mean that if ~/.config/micro/backups and ~/.config/micro/buffers exist, they should be used and whatever is in ~/.local/state/micro should be ignored?

Another option would be to copy ~/.config/micro/backups and ~/.config/micro/buffers to ~/.local/state/micro.

@dmaluka
Copy link
Collaborator

dmaluka commented Mar 17, 2024

Dunno. Neither option seems perfect.

@JoeKar
Copy link
Collaborator

JoeKar commented Mar 17, 2024

The backward compatibility will be a nasty thing.

Another option would be to copy ~/.config/micro/backups and ~/.config/micro/buffers to ~/.local/state/micro.

In that case you will do this with every startup, right? Maybe it's better to move it then and maintain the new location only. 🤔

@bartekpacia
Copy link
Contributor Author

bartekpacia commented Mar 17, 2024

Maybe it's better to move it then and maintain the new location only.

Yeah, it's also an option.

The situation where the change I'm planning to make would cause problems seems very rare: Micro would have to crash, the user would have update in the meantime, and then the backup would be missing.

@clipcarl
Copy link

clipcarl commented Jun 22, 2024

micro_state_dir.patch.txt

Here is a patch to separate micro's state files from micro's config files. With this patch files that were previously searched for in $MICRO_CONFIG_HOME/buffers or $MICRO_CONFIG_HOME/backups are now searched for in $MICRO_STATE_HOME/buffers or $MICRO_STATE_HOME/backups respectively. If $MICRO_STATE_HOME/buffers does not exist $XDG_STATE_HOME/micro/buffers is used instead. If that doesn't exist either $HOME/.local/state/micro/buffers is used. Ditto for $MICRO_STATE_HOME/backups.

This patch simply adds a config.StateDir variable (alongside the existing config.ConfigDir) and uses it for state stuff. The patch will create the state directory if it doesn't already exist but does not touch the old location.

I don't do anything for migration because IMO it's not worth adding code that will sit in micro forever to address the minor one-time slight annoyance of history and cursor positions being reset. I think a small external migration script would be better for that (not included).

If anyone would like to test this without the hassle of building micro from source a statically linked binary for 64-bit Linux (x86_64) can be found here. It should work on any x86_64 Linux distribution. A statically linked binary for 64-bit Arm Linux (aarch64) can be found here for those of you using 64 bit ARM servers or Pis.

@Andriamanitra
Copy link
Contributor

@clipcarl could you make the change as a Github pull request to make it easier to review?

@clipcarl
Copy link

@clipcarl could you make the change as a Github pull request to make it easier to review?

Honestly I've never used Github for development (I'm old-school) so I'm not sure how to do that!

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.

None yet

5 participants