Skip to content

Commit a58ed7c

Browse files
committed
Restore Original Console.scala to preserve workaround
1 parent 894998f commit a58ed7c

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

console/src/main/scala/io/joern/console/Console.scala

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,25 @@ class Console[T <: Project](loader: WorkspaceLoader[T], baseDir: Path = FileUtil
3939
implicit object ConsoleImageViewer extends ImageViewer {
4040
def view(imagePathStr: String): Try[String] = {
4141
// We need to copy the file as the original one is only temporary
42-
// and gets removed immediately after running this viewer instance synchronously via .run().
43-
FileUtil.usingTemporaryFile(suffix = ".svg") { tmpFile =>
44-
Paths.get(imagePathStr).copyTo(tmpFile, copyOption = StandardCopyOption.REPLACE_EXISTING)
45-
46-
val result = Try {
47-
val command = if (scala.util.Properties.isWin) { Seq("cmd.exe", "/C", config.tools.imageViewer) }
48-
else { Seq(config.tools.imageViewer) }
49-
ExternalCommand
50-
.run(command :+ tmpFile.absolutePathAsString)
51-
} match {
52-
case Success(_) =>
53-
// We never handle the actual result anywhere.
54-
// Hence, we just pass a success message.
55-
Success(s"Running viewer for '$tmpFile' finished.")
56-
case Failure(exc) =>
57-
System.err.println("Executing image viewer failed. Is it installed? ")
58-
System.err.println(exc)
59-
Failure(exc)
60-
}
61-
62-
result
42+
// and gets removed immediately after running this viewer instance asynchronously via .run().
43+
val tmpFile = FileUtil.newTemporaryFile(suffix = ".svg")
44+
Paths.get(imagePathStr).copyTo(tmpFile, copyOption = StandardCopyOption.REPLACE_EXISTING)
45+
46+
FileUtil.deleteOnExit(tmpFile, swallowIOExceptions = true)
47+
Try {
48+
val command = if (scala.util.Properties.isWin) { Seq("cmd.exe", "/C", config.tools.imageViewer) }
49+
else { Seq(config.tools.imageViewer) }
50+
ExternalCommand
51+
.run(command :+ tmpFile.absolutePathAsString)
52+
} match {
53+
case Success(_) =>
54+
// We never handle the actual result anywhere.
55+
// Hence, we just pass a success message.
56+
Success(s"Running viewer for '$tmpFile' finished.")
57+
case Failure(exc) =>
58+
System.err.println("Executing image viewer failed. Is it installed? ")
59+
System.err.println(exc)
60+
Failure(exc)
6361
}
6462
}
6563
}

0 commit comments

Comments
 (0)