Skip to content

Commit 9ca820d

Browse files
authored
Merge pull request coder#109 from coder/improve-old-cli-cleanup
Fix: auto close stream open dirs
2 parents 5203e03 + 8c21dd8 commit 9ca820d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/main/kotlin/com/coder/gateway/sdk/CoderCLIManager.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.coder.gateway.sdk
33
import com.intellij.openapi.diagnostic.Logger
44
import java.io.InputStream
55
import java.net.URL
6+
import java.nio.file.FileVisitOption
67
import java.nio.file.Files
78
import java.nio.file.Path
89
import java.nio.file.Paths
@@ -67,9 +68,14 @@ class CoderCLIManager(url: URL, buildVersion: String) {
6768
}
6869

6970
fun removeOldCli() {
70-
Files.walk(Path.of(tmpDir)).sorted().map { it.toFile() }.filter { it.name.contains(cliNamePrefix) && !it.name.contains(cliFileName) }.forEach {
71-
logger.info("Removing $it because it is an old coder cli")
72-
it.delete()
71+
val tmpPath = Path.of(tmpDir)
72+
if (Files.isReadable(tmpPath)) {
73+
Files.walk(tmpPath, 1).use {
74+
it.sorted().map { pt -> pt.toFile() }.filter { fl -> fl.name.contains(cliNamePrefix) && !fl.name.contains(cliFileName) }.forEach { fl ->
75+
logger.info("Removing $fl because it is an old coder cli")
76+
fl.delete()
77+
}
78+
}
7379
}
7480
}
7581

0 commit comments

Comments
 (0)