Skip to content

Commit

Permalink
Added safe delete and updated dependencies (#242)
Browse files Browse the repository at this point in the history
* Added safe delete and updated dependencies

* Rewrote case entry if statement as part of guard
  • Loading branch information
DavidBakerEffendi authored Mar 11, 2022
1 parent e03a1ba commit 7a28e38
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added

- `OverflowDb::safeRemove` to handle exceptions when deleting nodes.

### Changed

- Updated Joern, CPG, and Logback versions.

## [1.0.18] - 2022-03-09

### Changed
Expand Down
8 changes: 4 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name := "Plume"
inThisBuild(
List(
organization := "com.github.plume-oss",
version := "1.0.18",
version := "1.0.18-SNAP",
scalaVersion := "2.13.7",
crossScalaVersions := Seq("2.13.7", "3.1.1"),
resolvers ++= Seq(
Expand All @@ -14,8 +14,8 @@ inThisBuild(
)
)

val cpgVersion = "1.3.509"
val joernVersion = "1.1.606"
val cpgVersion = "1.3.514"
val joernVersion = "1.1.611"
val sootVersion = "4.2.1"
val tinkerGraphVersion = "3.4.8"
val neo4jVersion = "4.4.3"
Expand All @@ -25,7 +25,7 @@ val jacksonVersion = "2.13.2"
val scalajHttpVersion = "2.4.2"
val lz4Version = "1.8.0"
val slf4jVersion = "1.7.36"
val logbackVersion = "1.2.10"
val logbackVersion = "1.2.11"
val scalatestVersion = "3.2.11"
val circeVersion = "0.14.1"

Expand Down
18 changes: 13 additions & 5 deletions src/main/scala/com/github/plume/oss/drivers/OverflowDbDriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ final case class OverflowDbDriver(
// Do node operations first
dg.diffGraph.iterator.foreach {
case Change.RemoveNode(nodeId) =>
cpg.graph.node(nodeId).remove()
safeRemove(cpg.graph.node(nodeId))
case Change.RemoveNodeProperty(nodeId, propertyKey) =>
cpg.graph.node(nodeId).removeProperty(propertyKey)
case Change.CreateNode(node) =>
Expand Down Expand Up @@ -206,7 +206,7 @@ final case class OverflowDbDriver(
propertiesFromObjectArray(edgeKeyValues).foreach { case (k, v) => e.setProperty(k, v) }
case None =>
}
case c: BatchedUpdate.RemoveNode => cpg.graph.node(c.node.id()).remove()
case c: BatchedUpdate.RemoveNode => safeRemove(cpg.graph.node(c.node.id()))
case c: BatchedUpdate.SetNodeProperty =>
cpg.graph.node(c.node.id()).setProperty(c.label, c.value)
}
Expand Down Expand Up @@ -236,18 +236,26 @@ final case class OverflowDbDriver(
val typeDecls = fileChildren.collect { case x: TypeDecl => x }
val namespaceBlocks = fileChildren.collect { case x: NamespaceBlock => x }
// Remove TYPE nodes
typeDecls.flatMap(_.in(EdgeTypes.REF)).foreach(_.remove())
typeDecls.flatMap(_.in(EdgeTypes.REF)).foreach(n => safeRemove(n))
// Remove NAMESPACE_BLOCKs and their AST children (TYPE_DECL, METHOD, etc.)
val nodesToDelete = mutable.Set.empty[Node]
namespaceBlocks.foreach(
accumNodesToDelete(_, nodesToDelete, EdgeTypes.AST, EdgeTypes.CONDITION)
)
nodesToDelete.foreach(_.remove)
nodesToDelete.foreach(n => safeRemove(n))
// Finally remove FILE node
f.remove()
safeRemove(f)
}
}

private def safeRemove(n: Node): Unit = Try(if (n != null) n.remove()) match {
case Failure(e) if cpg.graph.node(n.id()) != null =>
logger.warn(
s"Exception '${e.getMessage}' occurred while deleting node: [${n.id()}] ${n.label()}"
)
case Success(_) =>
}

override def propertyFromNodes(nodeType: String, keys: String*): List[Map[String, Any]] =
cpg.graph
.nodes(nodeType)
Expand Down

0 comments on commit 7a28e38

Please sign in to comment.