From e53a45065b9ed8199b7377660a8556384b07beda Mon Sep 17 00:00:00 2001 From: Noah S-C Date: Wed, 12 May 2021 14:08:30 +0100 Subject: [PATCH] skip outputting lsif snapshot for files located outside the sourceroot (#195) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ólafur Páll Geirsson --- .../lsif_java/commands/SnapshotLsifCommand.scala | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lsif-java/src/main/scala/com/sourcegraph/lsif_java/commands/SnapshotLsifCommand.scala b/lsif-java/src/main/scala/com/sourcegraph/lsif_java/commands/SnapshotLsifCommand.scala index b60ad4b2..449e5d7b 100644 --- a/lsif-java/src/main/scala/com/sourcegraph/lsif_java/commands/SnapshotLsifCommand.scala +++ b/lsif-java/src/main/scala/com/sourcegraph/lsif_java/commands/SnapshotLsifCommand.scala @@ -49,8 +49,8 @@ case class SnapshotLsifCommand( @PositionalArguments() input: List[Path] = List(Paths.get("dump.lsif")) ) extends Command { - private val finalOutput = AbsolutePath.of(output, sourceroot) def sourceroot: Path = AbsolutePath.of(app.env.workingDirectory) + private val finalOutput = AbsolutePath.of(output, sourceroot) def run(): Int = { Files.walkFileTree(finalOutput, new DeleteVisitor()) @@ -59,7 +59,12 @@ case class SnapshotLsifCommand( in = AbsolutePath.of(inputPath, sourceroot) doc <- SnapshotLsifCommand.parseTextDocument(in, sourceroot) } { - SnapshotCommand.writeSnapshot(doc, finalOutput) + val docPath = AbsolutePath + .of(Paths.get(doc.getUri), sourceroot) + .toRealPath() + if (docPath.toAbsolutePath.startsWith(sourceroot)) { + SnapshotCommand.writeSnapshot(doc, finalOutput) + } } 0 }