Skip to content

Commit dc42197

Browse files
feat: check for lincensePaths, and left out Toolchains dir
1 parent 12f246e commit dc42197

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

Sources/Swiftly/SelfUninstall.swift

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ struct SelfUninstall: SwiftlyCommand {
126126
await ctx.print("Swiftly binary found at \(swiftlyBinary), removing it...")
127127
}
128128
try await fs.remove(atPath: swiftlyBin / "swiftly")
129-
}
129+
}
130130

131131
let entries = try await fs.ls(atPath: swiftlyBin)
132132
if entries.isEmpty {
@@ -156,12 +156,38 @@ struct SelfUninstall: SwiftlyCommand {
156156
}
157157
if let homeFiles = homeFiles, homeFiles.contains("env.fish") {
158158
if verbose {
159-
await ctx.print("Removing swiftly env.fish file at \(swiftlyHome / "env.fish")...")
159+
await ctx.print("Removing swiftly env.fish file at \(swiftlyHome / "env.fish")...")
160160
}
161161
try await fs.remove(atPath: swiftlyHome / "env.fish")
162162
}
163+
164+
// we should also check for share/doc/swiftly/license/LICENSE.txt
165+
let licensePath = swiftlyHome / "share/doc/swiftly/license/LICENSE.txt"
166+
if
167+
try await fs.exists(atPath: licensePath)
168+
{
169+
if verbose {
170+
await ctx.print("Removing swiftly license file at \(licensePath)...")
171+
}
172+
try await fs.remove(atPath: licensePath)
173+
}
174+
175+
// removes each of share/doc/swiftly/license directories if they are empty
176+
let licenseDir = swiftlyHome / "share/doc/swiftly/license"
177+
if try await fs.exists(atPath: licenseDir) {
178+
let licenseEntries = try await fs.ls(atPath: licenseDir)
179+
if licenseEntries.isEmpty {
180+
if verbose {
181+
await ctx.print("Swiftly license directory at \(licenseDir) is empty, removing it...")
182+
}
183+
try await fs.remove(atPath: licenseDir)
184+
}
185+
}
186+
163187
// if now the swiftly home directory is empty, remove it
164188
let homeEntries = try await fs.ls(atPath: swiftlyHome)
189+
await ctx.print("Checking swiftly home directory entries...")
190+
await ctx.print("still present: \(homeEntries.joined(separator: ", "))")
165191
if homeEntries.isEmpty {
166192
if verbose {
167193
await ctx.print("Swiftly home directory at \(swiftlyHome) is empty, removing it...")

Tests/SwiftlyTests/SelfUninstallTests.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,18 @@ import Testing
2525
try await fs.exists(atPath: swiftlyBinDir) == false,
2626
"swiftly bin directory should be removed"
2727
)
28-
#expect(
29-
try await fs.exists(atPath: swiftlyHomeDir) == false,
30-
"swiftly home directory should be removed"
31-
)
28+
if try await fs.exists(atPath: swiftlyHomeDir) {
29+
let contents = try await fs.ls(atPath: swiftlyHomeDir)
30+
#expect(
31+
contents == ["Toolchains"] || contents.isEmpty,
32+
"swiftly home directory should only contain 'toolchains' or be empty"
33+
)
34+
} else {
35+
#expect(
36+
true,
37+
"swiftly home directory should be removed"
38+
)
39+
}
3240
}
3341
}
3442

0 commit comments

Comments
 (0)