Commit 5ecb3f1a authored by Mohamed, Fawzi Roberto (fawzi)'s avatar Mohamed, Fawzi Roberto (fawzi)
Browse files

ensure cleanup, avoid extra tmpdir creation

parent df450dd9
......@@ -42,6 +42,7 @@ class DirectNormalizer(
}
def cleanup(): Unit = {
generator.cleanup()
}
def workerJValue: jn.JValue = {
......
......@@ -46,6 +46,7 @@ class ExternalNormalizerGenerator(
val resList: Seq[String] = Seq(),
val dirMap: Map[String, String] = Map(),
val extraCmdVars: Map[String, String] = Map(),
val wantsTmp: Boolean = false,
override val metaInfoEnv: meta.MetaInfoEnv = meta.KnownMetaInfoEnvs.all,
override val archiveDependencies: Set[String] = Set(),
override val contextDependencies: Set[String] = Set()
......@@ -86,6 +87,7 @@ class ExternalNormalizerGenerator(
val envDir = lab.LocalEnv.defaultSettings.procTmpDir.resolve("parserEnvs")
Files.createDirectories(envDir, lab.LocalEnv.directoryPermissionsAttributes)
val tDir = Files.createTempDirectory(envDir, name, lab.LocalEnv.directoryPermissionsAttributes)
val ttDir = Files.createDirectories(tDir.resolve("tmp"), lab.LocalEnv.directoryPermissionsAttributes)
try {
SimpleExternalParserGenerator.copyAndRenameFromResources(resList, tDir, dirMap)
if (trace) logger.info(s"Did setup of environment for parser $name in $tDir")
......@@ -127,7 +129,11 @@ class ExternalNormalizer(
val generator: ExternalNormalizerGenerator
) extends Normalizer with StrictLogging {
Files.createDirectories(lab.LocalEnv.defaultSettings.procTmpDir, lab.LocalEnv.directoryPermissionsAttributes)
val tmpDir: Path = Files.createTempDirectory(lab.LocalEnv.defaultSettings.procTmpDir, "normalizerTmp", lab.LocalEnv.directoryPermissionsAttributes)
val tmpDir: Path = if (generator.wantsTmp)
Files.createTempDirectory(lab.LocalEnv.defaultSettings.procTmpDir, "normalizerTmp", lab.LocalEnv.directoryPermissionsAttributes)
else
generator.envDir.resolve("tmp")
if (trace) logger.info(s"parser $name created tmpDir for optimized parser at $tmpDir")
def name: String = generator.name
......@@ -181,9 +187,11 @@ class ExternalNormalizer(
}
def cleanup(): Unit = {
if (trace)
logger.info(s"normalizer of ${name} deleting temporary directory $tmpDir")
lab.LocalEnv.deleteRecursively(tmpDir)
if (generator.wantsTmp) {
if (trace)
logger.info(s"normalizer of ${name} deleting temporary directory $tmpDir")
lab.LocalEnv.deleteRecursively(tmpDir)
}
}
}
......@@ -98,7 +98,8 @@ class SimpleExternalParserGenerator(
val mainFileMatchWeak: Boolean = false,
val metaInfoEnv: Option[meta.MetaInfoEnv] = None,
val ancillaryFilesPrefilter: AncillaryFilesPrefilter.Value = AncillaryFilesPrefilter.SubtreeDepth1,
val isStrict: Boolean = false
val isStrict: Boolean = false,
val wantsTmp: Boolean = false
) extends ParserGenerator with StrictLogging {
def setupEnv(): Path = {
......@@ -108,6 +109,7 @@ class SimpleExternalParserGenerator(
val envDir = lab.LocalEnv.defaultSettings.procTmpDir.resolve("parserEnvs")
Files.createDirectories(envDir, lab.LocalEnv.directoryPermissionsAttributes)
val tDir = Files.createTempDirectory(envDir, name, lab.LocalEnv.directoryPermissionsAttributes)
val ttDir = Files.createDirectories(tDir.resolve("tmp"), lab.LocalEnv.directoryPermissionsAttributes)
try {
SimpleExternalParserGenerator.copyAndRenameFromResources(resList, tDir, dirMap)
if (trace) logger.info(s"Did setup of environment for parser $name in $tDir")
......@@ -163,7 +165,10 @@ class SimpleExternalParserGenerator(
override def optimizedParser(optimizations: Seq[MetaInfoOps]): OptimizedParser = {
Files.createDirectories(lab.LocalEnv.defaultSettings.procTmpDir, lab.LocalEnv.directoryPermissionsAttributes)
val tmpDir = Files.createTempDirectory(lab.LocalEnv.defaultSettings.procTmpDir, "parserTmp", lab.LocalEnv.directoryPermissionsAttributes)
val tmpDir = if (wantsTmp)
Files.createTempDirectory(lab.LocalEnv.defaultSettings.procTmpDir, "parserTmp", lab.LocalEnv.directoryPermissionsAttributes)
else
envDir.resolve("tmp")
if (trace) logger.info(s"parser $name created tmpDir for optimized parser at $tmpDir")
val allReplacements = extraCmdVars +
("envDir" -> envDir.toString()) +
......@@ -872,7 +877,9 @@ class SimpleExternalParser(
}
def cleanup(): Unit = {
if (trace) logger.info(s"optimized parser of ${parserGenerator.name} deleting temporary directory $tmpDir")
lab.LocalEnv.deleteRecursively(tmpDir)
if (parserGenerator.wantsTmp) {
if (trace) logger.info(s"optimized parser of ${parserGenerator.name} deleting temporary directory $tmpDir")
lab.LocalEnv.deleteRecursively(tmpDir)
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment