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

PATCH: Micro puts state information in config directory #3376

Open
clipcarl opened this issue Jul 10, 2024 · 1 comment
Open

PATCH: Micro puts state information in config directory #3376

clipcarl opened this issue Jul 10, 2024 · 1 comment

Comments

@clipcarl
Copy link

micro_state_dir.patch.txt

I posted this patch in a different issue a few weeks ago but it doesn't look like anyone saw it there so I figured I should create a new issue for it.

This patch fixes a problem reported in multiple issues (at least #3185, #3176 and #2004).

Micro puts state data in its configuration directory instead of a separate state data directory. This state data can grow very large which makes copying micro configuration to a new computer over a slow link much slower than expected. Since this state data can also include text, history and other information from previous files edited this could lead to an inadvertent disclosure of private or confidential information if the config directory is copied to a system where other people have access.

This patch separates micro's state files from micro's config files. With this patch state information is now stored in $MICRO_STATE_HOME so for example 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 does not exist $XDG_STATE_HOME/micro/ is used instead. If that doesn't exist either $HOME/.local/state/micro/ is used.

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 directories if they don'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.

@niten94
Copy link
Contributor

niten94 commented Jul 12, 2024

The configuration directory can be set in command line arguments and checked as config.ConfigDir in plugins so micro.go and initlua.go in cmd/micro will have to be changed so that the same can be done. The man page in assets/packaging also has to be updated.

The code in config.InitConfigDir is duplicated so I think it would be better if a generic function is used with the configuration and state directory. There was a variable with underscore in name added in InitConfigDir but I do not think underscore is mixed in identifiers in Go code. err is usually reassigned if the variable was already defined in functions.

The directory environment variables are not usually set and the variables would have to be looked up even when trying to check options.md fast, so I think it is better if the default values are written in options.md. It may be better changing how the description of the state directory in options.md is written so that it does not seem repetitive.

Pull requests are used when sending changes and patch files are not usually used in projects in GitHub, so please consider changing the patch to one. I think this page will help.

I have not used and applied patch files before but there may be other people not familiar with them. I was able to apply it when running this command in directory with micro source code:
patch -p1 < micro_state_dir.patch.txt

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

No branches or pull requests

2 participants