Skip to content

Clear out state.json when we find and empty settings.json#11448

Merged
2 commits merged intomainfrom
dev/migrie/b/11119-remove-state-too
Oct 11, 2021
Merged

Clear out state.json when we find and empty settings.json#11448
2 commits merged intomainfrom
dev/migrie/b/11119-remove-state-too

Conversation

@zadjii-msft
Copy link
Member

If we find that the settings file doesn't exist, or is empty, then let's quick
delete the state file as well. If the user does have a state file, and not a
settings, then they probably tried to reset their settings. It might have data
in it that was only relevant for a previous iteration of the settings file. If
we don't, we'll load the old state and ignore all dynamic profiles (for
example)!

We'll remove all of the data in the ApplicationState object and reset it to
the defaults.

This will delete the state file!

That's the sure-fire way to make sure the data doesn't come back. If we leave
it untouched, then when we go to write the file back out, we'll first re-read
it's contents and try to overlay our new state. However, nullopts won't remove
keys from the JSON, so we'll end up with the original state in the file.

  If we find that the settings file doesn't exist, or is empty, then let's quick
  delete the state file as well. If the user does have a state file, and not a
  settings, then they probably tried to reset their settings. It might have data
  in it that was only relevant for a previous iteration of the settings file. If
  we don't, we'll load the old state and ignore all dynamic profiles (for
  example)!

  We'll remove all of the data in the `ApplicationState` object and reset it to
  the defaults.

  This will delete the state file!

  That's the sure-fire way to make sure the data doesn't come back. If we leave
  it untouched, then when we go to write the file back out, we'll first re-read
  it's contents and try to overlay our new state. However, nullopts won't remove
  keys from the JSON, so we'll end up with the original state in the file.

  * [x] Closes #11119
  * [x] Tested on a cold launch of the Terminal with an existing `state.json`
    and an empty `settings.json`
  * [x] Tested a hot-reload of deleting the `settings.json`
@ghost ghost added Area-Settings Issues related to settings and customizability, for console or terminal Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal. labels Oct 7, 2021

#define MTSM_APPLICATION_STATE_GEN(type, name, key, ...) \
{ \
auto state = _state.lock(); \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may like to refactor this to do the whole thing under one lock over _state; @lhecker?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will also, i think, try to enqueue the throttler once per setting. It won't fire, but it's not necessary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest I don't quite get why we have to mark all fields as changed in the first place...
When we re-read the file it will not exist, so it shouldn't be possible for the old data to come back.

In that case I'd just write _state.lock() = {};.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_state.lock() = {};

now that's some witchcraft if I've ever seen it

I'll try that. I was just marking them as changed because I was trying to avoid the DeleteFile() but (maybe accidentally) left that in

@DHowett DHowett added zPreview-Service-Consider AutoMerge Marked for automatic merge by the bot when requirements are met and removed zPreview-Service-Consider AutoMerge Marked for automatic merge by the bot when requirements are met labels Oct 8, 2021
@ghost
Copy link

ghost commented Oct 11, 2021

Hello @DHowett!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 8dd3173 into main Oct 11, 2021
@ghost ghost deleted the dev/migrie/b/11119-remove-state-too branch October 11, 2021 15:51
PankajBhojwani pushed a commit that referenced this pull request Oct 13, 2021
If we find that the settings file doesn't exist, or is empty, then let's quick
delete the state file as well. If the user does have a state file, and not a
settings, then they probably tried to reset their settings. It might have data
in it that was only relevant for a previous iteration of the settings file. If
we don't, we'll load the old state and ignore all dynamic profiles (for
example)!

We'll remove all of the data in the `ApplicationState` object and reset it to
the defaults.

This will delete the state file!

That's the sure-fire way to make sure the data doesn't come back. If we leave
it untouched, then when we go to write the file back out, we'll first re-read
it's contents and try to overlay our new state. However, nullopts won't remove
keys from the JSON, so we'll end up with the original state in the file.

* [x] Closes #11119
* [x] Tested on a cold launch of the Terminal with an existing `state.json`
and an empty `settings.json`
* [x] Tested a hot-reload of deleting the `settings.json`
PankajBhojwani pushed a commit that referenced this pull request Oct 15, 2021
If we find that the settings file doesn't exist, or is empty, then let's quick
delete the state file as well. If the user does have a state file, and not a
settings, then they probably tried to reset their settings. It might have data
in it that was only relevant for a previous iteration of the settings file. If
we don't, we'll load the old state and ignore all dynamic profiles (for
example)!

We'll remove all of the data in the `ApplicationState` object and reset it to
the defaults.

This will delete the state file!

That's the sure-fire way to make sure the data doesn't come back. If we leave
it untouched, then when we go to write the file back out, we'll first re-read
it's contents and try to overlay our new state. However, nullopts won't remove
keys from the JSON, so we'll end up with the original state in the file.

* [x] Closes #11119
* [x] Tested on a cold launch of the Terminal with an existing `state.json`
and an empty `settings.json`
* [x] Tested a hot-reload of deleting the `settings.json`

(cherry picked from commit 8dd3173)
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Settings Issues related to settings and customizability, for console or terminal AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Profiles missing after resetting config

4 participants