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

Clean command: removes installation from state if directory missing. #73

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

amanjeev
Copy link
Member

@amanjeev amanjeev commented Jan 7, 2025

This was a bug that if the directory of the installation is missing from the file system, and the installation is still present in the state file, the clean command will not remove the installation from the state file. This was certainly a problem because if there is accidental deletion of the toolchain directory, we need to be able to clean up the state file too.

Start with a clean state.json.

For best results, delete the entire criticalup installation directory.

Install project 1

Use this manifest to install first project. Name this file project1.toml.

manifest-version = 1

[products.ferrocene]
release = "stable-24.11.0"
packages = [
    "cargo-${rustc-host}",
    "rustc-${rustc-host}",
]

Install this project

criticalup install

Check state.json

state.json file should contain an installation with ID "c8f887068792bbf1f09ce4b6ddbe84fd7d9dcde18407d608968c26b89862d15e".

Delete the installation directory

In the appropriate location of toolchain installations, find the directory where this is installed and delete the toolchain of this project only.

DO NOT delete the root directory of CriticalUp configs and installation.

On Linux, you can see this at ~/.local/share/criticalup/toolchains/c8f887068792bbf1f09ce4b6ddbe84fd7d9dcde18407d608968c26b89862d15e/.

Run clean

criticalup clean

Result: you should see that the state.json file does not have the installation of the above.

@amanjeev amanjeev self-assigned this Jan 7, 2025
@amanjeev amanjeev marked this pull request as ready for review January 8, 2025 14:56
@amanjeev amanjeev requested a review from Hoverbear January 8, 2025 14:56

let state_file_in_root = root.join("state.json");
let mut state_file = std::fs::File::create(&state_file_in_root).unwrap();
let content = json!({
Copy link
Member

Choose a reason for hiding this comment

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

I don't love that this is effectively StateRepr but untyped. :(

But I understand why.

@Hoverbear
Copy link
Member

Can we remove the duplication? We don't need two lines per uninstall:

 INFO Cleaning cache directory
 INFO Deleting unused installation 4b5c4cf4ddc1fed309f16e08c095c23fb0d0dd7bbed973d6a40f5da572cf407b
 INFO deleting unused installation directory /home/ana/.local/share/criticalup/toolchains/4b5c4cf4ddc1fed309f16e08c095c23fb0d0dd7bbed973d6a40f5da572cf407b
 INFO Deleting unused installation 5a8eab457f324aa3a77e88ad3e0de45d55f8411258359e0da8947aeb2a60229c
 INFO deleting unused installation directory /home/ana/.local/share/criticalup/toolchains/5a8eab457f324aa3a77e88ad3e0de45d55f8411258359e0da8947aeb2a60229c
 INFO Deleting unused installation 9158204fe36f19745e8436eb745fb93423c322de8c8815855df3db77ce92982e
 INFO deleting unused installation directory /home/ana/.local/share/criticalup/toolchains/9158204fe36f19745e8436eb745fb93423c322de8c8815855df3db77ce92982e
 INFO Deleting unused installation 9addff84231802d06415d8dfa419916e2017d303586eaab2c144007089b3c9dc
 INFO deleting unused installation directory /home/ana/.local/share/criticalup/toolchains/9addff84231802d06415d8dfa419916e2017d303586eaab2c144007089b3c9dc
 INFO deleting untracked installation directory /home/ana/.local/share/criticalup/toolchains/c0c4a3905b2493592eda0ed036e15d930e25b3516a494c2168b957f6fc873d65
 INFO deleting untracked installation directory /home/ana/.local/share/criticalup/toolchains/71acafd7460acae4d76578004399063537c4c4cbc7e8f48891e0cb0b3a4992f6

This was a bug that if the directory of the installation is
missing from the file system, and the installation is still
present in the state file, the clean command will not remove the
installation from the state file. This was certainly a problem
because if there is accidental deletion of the toolchain
directory, we need to be able to clean up the state file too.
@amanjeev amanjeev force-pushed the amanjeev/clean-command-uiux branch from d67915a to 31a0e21 Compare January 9, 2025 19:24
@amanjeev amanjeev requested a review from Hoverbear January 9, 2025 22:51
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.

2 participants