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

Add version information to "bat cache" files to prevent incompatibilities #882

Closed
sharkdp opened this issue Mar 23, 2020 · 2 comments · Fixed by #931
Closed

Add version information to "bat cache" files to prevent incompatibilities #882

sharkdp opened this issue Mar 23, 2020 · 2 comments · Fixed by #931
Assignees
Labels
feature-request New feature or request
Milestone

Comments

@sharkdp
Copy link
Owner

sharkdp commented Mar 23, 2020

There are numerous reports of bugs that emerged from cached assets that were generated with an older version of bat (#425, #853, #797, maybe #704). Even if no bugs appear, new syntaxes/themes appear to be missing because the old assets have not been re-generated.

One way to prevent this would be to store version information with the cached assets. This way, we could check for compatibility upon loading.

The version information should probably be stored in a separate text file with a very simple format which is unlikely to change in the future. Maybe just a simple assets.yaml file with:

version: "7.4.0"
@sharkdp sharkdp added the feature-request New feature or request label Mar 23, 2020
@eth-p
Copy link
Collaborator

eth-p commented Mar 24, 2020

A couple of small considerations:

  1. What should happen with a missing version file? Treat it as an unknown and incompatible syntax/theme set?

  2. What should we do if the user has an incompatible syntax/theme set?

My thoughts on the second consideration:

I don't think deleting it automatically would the correct course of action. If users update bat and find their theme or syntax mappings missing without any explanation, they might consider it a bug.

Ruling that out would leave us with two options: Warn the user and proceed anyways; or print an error and exit.

Personally, I prefer printing a stern warning and continuing. Let the user proceed at their own risk knowing the potential consequences.

@sharkdp
Copy link
Owner Author

sharkdp commented Mar 24, 2020

  1. What should happen with a missing version file? Treat it as an unknown and incompatible syntax/theme set?

Yes. We would assume that these are artifacts from a version of bat that did not have this feature and simply declare these files as incompatible.

I don't think deleting it automatically would the correct course of action. If users update bat and find their theme or syntax mappings missing without any explanation, they might consider it a bug.

Ruling that out would leave us with two options: Warn the user and proceed anyways; or print an error and exit.

A third option might be to regenerate the files from the config folder "on the fly". Now this would of course only work if (1) the orignal path with themes and syntaxes still exists in unmodified form and (2) if we know that path.

I think both points could be solved by storing additional information in the metadata file. It might be as simple as storing a file path and a hash (across all files in the syntaxes and themes folders):

version: "7.4.0"
source:
  path: /home/shark/.config/bat
  hash: "9333753eab96a4daca9a1f69bb8a15ef"

@sharkdp sharkdp added this to the v0.14 milestone Apr 11, 2020
@sharkdp sharkdp self-assigned this Apr 21, 2020
sharkdp added a commit that referenced this issue Apr 21, 2020
When saving/reading user-provided syntaxes or themes, `bat` will now maintain a
`metadata.yaml` file which includes information about the `bat` version which was
used to create the cached files. When loading cached files, we now print an error
if they have been created with an incompatible version

closes #882
sharkdp added a commit that referenced this issue Apr 21, 2020
When saving/reading user-provided syntaxes or themes, `bat` will now maintain a
`metadata.yaml` file which includes information about the `bat` version which was
used to create the cached files. When loading cached files, we now print an error
if they have been created with an incompatible version

closes #882
sharkdp added a commit that referenced this issue Apr 21, 2020
When saving/reading user-provided syntaxes or themes, `bat` will now maintain a
`metadata.yaml` file which includes information about the `bat` version which was
used to create the cached files. When loading cached files, we now print an error
if they have been created with an incompatible version

closes #882
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants