Skip to content

Commit a7bbeaa

Browse files
committed
close streams
1 parent d06c867 commit a7bbeaa

File tree

2 files changed

+24
-17
lines changed
  • plugins/amazonq/shared/jetbrains-community
    • src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts
    • tst/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts

2 files changed

+24
-17
lines changed

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/LspUtils.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,15 @@ fun extractZipFile(zipFilePath: Path, destDir: Path) {
8585
URI("jar:${zipFilePath.toUri()}"),
8686
mapOf(ZIP_PROPERTY_POSIX to destDir.hasPosixFilePermissions())
8787
).use { zipfs ->
88-
Files.walk(zipfs.getPath("/"))
89-
.filter { !it.isDirectory() }
90-
.forEach { zipEntry ->
91-
val destPath = Paths.get(destDir.toString(), zipEntry.toString())
92-
destPath.createParentDirectories()
93-
Files.copy(zipEntry, destPath, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES)
94-
}
88+
Files.walk(zipfs.getPath("/")).use { paths ->
89+
paths
90+
.filter { !it.isDirectory() }
91+
.forEach { zipEntry ->
92+
val destPath = Paths.get(destDir.toString(), zipEntry.toString())
93+
destPath.createParentDirectories()
94+
Files.copy(zipEntry, destPath, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES)
95+
}
96+
}
9597
}
9698
} catch (e: Exception) {
9799
throw LspException("Failed to extract zip file: ${e.message}", LspException.ErrorCode.UNZIP_FAILED, cause = e)

plugins/amazonq/shared/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/LspUtilsTest.kt

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,15 @@ class LspUtilsTest {
3636

3737
val sourceZip = tempDir.resolve("source.zip")
3838
ZipOutputStream(Files.newOutputStream(sourceZip)).use { zip ->
39-
Files.walk(source).filter { it.isRegularFile() }.forEach {
40-
zip.putNextEntry(source.relativize(it).toString(), it)
39+
Files.walk(source).use { paths ->
40+
paths
41+
.filter { it.isRegularFile() }
42+
.forEach {
43+
zip.putNextEntry(source.relativize(it).toString(), it)
44+
}
45+
val precedingSlashFile = source.resolve("file4").also { it.writeText("contents4") }
46+
zip.putNextEntry("/${source.relativize(precedingSlashFile)}", precedingSlashFile)
4147
}
42-
43-
val precedingSlashFile = source.resolve("file4").also { it.writeText("contents4") }
44-
zip.putNextEntry("/${source.relativize(precedingSlashFile)}", precedingSlashFile)
4548
}
4649

4750
extractZipFile(sourceZip, target)
@@ -80,11 +83,13 @@ class LspUtilsTest {
8083
ZIP_PROPERTY_POSIX to true,
8184
)
8285
).use { zipfs ->
83-
Files.walk(source)
84-
.filter { !it.isDirectory() }
85-
.forEach { file ->
86-
Files.copy(file, zipfs.getPath("/").resolve(source.relativize(file).toString()), StandardCopyOption.COPY_ATTRIBUTES)
87-
}
86+
Files.walk(source).use { paths ->
87+
paths
88+
.filter { it.isRegularFile() }
89+
.forEach { file ->
90+
Files.copy(file, zipfs.getPath("/").resolve(source.relativize(file).toString()), StandardCopyOption.COPY_ATTRIBUTES)
91+
}
92+
}
8893
}
8994

9095
extractZipFile(sourceZip, target)

0 commit comments

Comments
 (0)