swiftlang / swiftly

A Swift toolchain installer and manager, written in Swift.
https://swiftlang.github.io/swiftly/
Apache License 2.0
490 stars 28 forks source link

Uninstall deleted active swift version, not the specified. #140

Closed carlynorama closed 3 months ago

carlynorama commented 3 months ago

Hi, I was running 0.2.0, but just today updated to 0.3.0 by running the install script without deleting the previous version of swiftly because 0.2.0 didn't have update working yet.

I went to delete a toolchain I wasn't going to use anymore, and instead it deleted the active toolchain and switched to the one I was deleting.

It was fine, I recovered easily in this case, but should nuke swiftly and all it's folders from orbit to make the move from 0.2.0 -> 0.3.0 or a problem with the actual uninstall command?

In window one:

user:~$ swiftly list
Installed release toolchains
----------------------------
Swift 5.10.0
Swift 5.9.2

Installed snapshot toolchains
-----------------------------
main-snapshot-2024-07-15 (in use)
5.10-snapshot-2024-02-14
main-snapshot-2024-02-14

In window 2, just for full disclosure

user:~$ swiftly install latest
...
Swift 5.10.1 installed successfully!

Back in window 1

user:~$ swiftly uninstall 5.10.0
The following toolchains will be uninstalled:
  Swift 5.10.0
Proceed? (Y/n): Y

Error: Found symlink that points to non-swiftly managed executable: /home/eloise/.local/share/swiftly/toolchains/main-snapshot-2024-07-15/usr/bin/repl_swift
user:~$ swiftly list
Installed release toolchains
----------------------------
Swift 5.10.1
Swift 5.10.0 (in use)
Swift 5.9.2

Installed snapshot toolchains
-----------------------------
5.10-snapshot-2024-02-14
main-snapshot-2024-02-14

I think the mistake (if its in the code and not the lack of fresh install) has to be in: https://github.com/swiftlang/swiftly/blob/bcfd8439a078893c11d3331c193e2b6a7b431887/Sources/Swiftly/Uninstall.swift

Because I don't see how this could have gone wrong? (I'm on Linux) https://github.com/swiftlang/swiftly/blob/bcfd8439a078893c11d3331c193e2b6a7b431887/Sources/LinuxPlatform/Linux.swift#L108

carlynorama commented 3 months ago

rm'd the appropriate directories (found by find ~ -iname *swiftly* or you know the directions ) and reinstalled.

Issue dissapears. Weirdly I did have to install main-snapshot twice, but that maybe because I didn't deinstall the toolchains first? I just rm'd the dir? Or something else I was playing with in another window??)

(It's possible that the installer could be improved at detecting a previous install/ownsership of toolchains issues better, or the delete could warn better, but it's such early days and the current install base so small and the new updater already written I'm not sure how often this will actually come up)

adam-fowler commented 3 months ago

@carlynorama When you say you ran swiftly in 2 windows did you do that at the same time? Because if that is the order you ran the different commands it doesn't seem to make sense. ie the main snapshot was the in use version of swift but when you ran update it updated the 5.10 install

carlynorama commented 3 months ago

Yes, at the same time. Let's see if i can clear it up bit.

Before the submitted logs

The story begins

Super weird. I submitted the issue and stopped for the night.

This Morning

This morning I noticed there was still some pointing-to-outside-swiftly messages when trying to switch toolchains with use. I figured that this really must be my sloppy install hygine, and decided to clear everything swiftly out and start fresh. I did not do an ls -al on these directories to check their permissions. That would have been good data to have in hindsight.

It seems to all be working now. I installed

I followed those installs up with a swiftly uninstall 5.9 with the main-snapshot again the chosen toolchain. It behaved as expected (5.9 gone, m-s still in use). What I did NOT check was having a 5.10.x or 5.9.x installed and deleting it while installing a 5.10.n or 5.9.n.

This is a wee little Ubuntu machine I can wipe with very low stress. Would it be helpful for me to delete swiftly again, uninstalling the toolchains correctly this time, reinstall 0.2.0, and try to recreate? I'm comfortable calling this user error, but if there's data wanted, I can try to collect it.

carlynorama commented 3 months ago

Note, using use stopped working, nor could I fully uninstall all. Was getting a "The file doesn't exist." for both failures when interacting with main-snapshot-2024-07-15

Did

rm -r ~/.local/bin/swiftly 
rm -r ~/.local/share/swiftly/ 

AND

find ~/.local/bin/ -maxdepth 1 -type l 
find ~/.local/bin/ -maxdepth 1 -type l -delete

THEN reinstalled 0.3.0

NOW everything really works as expected.

adam-fowler commented 3 months ago

I think the fact you were running swiftly in two windows at the same time is probably the issue. We haven't tested for this at all.

carlynorama commented 3 months ago

I agree with that assessment. Surviving multi-window-operation is a big big lift. I wouldn't honestly actually really expect it from a 0.3.0, as I said I was dinking around too fast on a Friday on an inconsequential dev box. Did want to note manual deleting the symlinks for the next time I get myself into a jam.

Thanks for even taking a look!