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

Bug: default value (and location) of g:gutentags_tagfile causes data loss #37

Closed
pitchforks opened this issue Jul 30, 2015 · 7 comments
Closed

Comments

@pitchforks
Copy link
Contributor

If gutentags_project_root already contains a file named tags, it will be silently overwritten. If this file isn't tracked by the version control tool yet, this will cause data loss. If this file is already tracked - the version control tool will still be annoying about the content of this file getting changed everytime vim-gutentags overwrites it.

Having any less common default name for the tags file won't completely remove the risk of filename collisions. A better approach is probably to put these files somewhere else, outside gutentags_project_root, in a temporary directory perhaps?

@ludovicchabant
Copy link
Owner

Hi!

Having a tags file at the root of your project that isn't a Ctags (or other similar program) output file is a bit dangerous IMHO. Gutentags is not the only program of its kind who would put (or expect) such a file. Furthermore, the default value for tags in Vim is ./tags,tags, so it expects that file to be in the project tree at least (anywhere from next to a given source file, all the way to the root of your disk).

So frankly I can't think of a better default value. That said, you can set the g:gutentags_cache_dir to a place on your computer where Gutentags would store all the tags files. This will keep them away from your projects' directories.

@pitchforks
Copy link
Contributor Author

I am fine with using a custom g:gutentags_cache_dir, it excludes the chance of vim-gutentags accidentally overwriting a file named tags that's not a tags file. However, can vim-gutentags detect if the file named tags is actually a tags file or not, and notify the user about it if it is not? I bumped into this problem because I actually have a personal private repository with a file named tags in its root and I've remembered this when reading the documentation for vim-gutentags. So I went to that repository with vim-gutentags enabled on purpose, wanting to see what will it do. It just overwrote my tags file. I certainly don't recall it telling me about it.

@ludovicchabant
Copy link
Owner

Yeah it wouldn't tell you about it because it would be totally expected to find a file there. I suppose that, on start, Gutentags could check the first line of an existing tags file (the first few lines seem to start with !_TAG_), but I'll have to think about this more. We would need to also check if other versions of ctags write something else...

@pitchforks
Copy link
Contributor Author

We would need to also check if other versions of ctags write something else...

If you decide to go for this, I assume that having logic that checks for one pattern in place will be fine. Since the list of patterns to look for can be extended later if needed, just like it happened with g:gutentags_project_root. After all, checking if the first line in a file contains a certain pattern is a read-only operation. It shouldn't cause any trouble if the check will be incomplete in the beginning (just one pattern to look for).

@ludovicchabant
Copy link
Owner

Hey, I have a fix ready but I want to test it some more with very big tags files to see if reading the first line doesn't slow down the overall process.

@pitchforks
Copy link
Contributor Author

Sure. Though I see no reason why reading a line from a big file would be very different from reading a line from any file, as long as the line itself isn't huge.

@ludovicchabant
Copy link
Owner

I forgot to close this.... fixed with ce4716a.

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