From 5462d7a6b3343c4513e2c16faac5de34d4756eda Mon Sep 17 00:00:00 2001 From: jorgee Date: Mon, 25 Nov 2024 10:17:37 +0100 Subject: [PATCH] Fix overlapping in conda enviroment creation when equivalent but different relative paths Signed-off-by: jorgee --- .../groovy/nextflow/conda/CondaCache.groovy | 12 ++++++++++-- .../groovy/nextflow/conda/CondaCacheTest.groovy | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/modules/nextflow/src/main/groovy/nextflow/conda/CondaCache.groovy b/modules/nextflow/src/main/groovy/nextflow/conda/CondaCache.groovy index 17c605f19b..8fd27aff5f 100644 --- a/modules/nextflow/src/main/groovy/nextflow/conda/CondaCache.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/conda/CondaCache.groovy @@ -359,8 +359,8 @@ class CondaCache { * The {@link DataflowVariable} which hold (and pull) the local image file */ @PackageScope - DataflowVariable getLazyImagePath(String condaEnv) { - + DataflowVariable getLazyImagePath(String rawCondaEnv) { + def condaEnv = normalizeCondaEnv(rawCondaEnv) if( condaEnv in condaPrefixPaths ) { log.trace "${binaryName} found local environment `$condaEnv`" return condaPrefixPaths[condaEnv] @@ -399,4 +399,12 @@ class CondaCache { return result } + String normalizeCondaEnv(String rawCondaEnv) { + // Check if it's a path (as in getPrefixPath) + if( !isYamlUriPath(rawCondaEnv) && ( isYamlFilePath(rawCondaEnv) || isTextFilePath(rawCondaEnv) || rawCondaEnv.contains('/') ) ) { + final path = rawCondaEnv as Path + return path.toAbsolutePath().normalize().toString() + } + return rawCondaEnv + } } diff --git a/modules/nextflow/src/test/groovy/nextflow/conda/CondaCacheTest.groovy b/modules/nextflow/src/test/groovy/nextflow/conda/CondaCacheTest.groovy index 9a8baf952c..b582e5e117 100644 --- a/modules/nextflow/src/test/groovy/nextflow/conda/CondaCacheTest.groovy +++ b/modules/nextflow/src/test/groovy/nextflow/conda/CondaCacheTest.groovy @@ -569,4 +569,21 @@ class CondaCacheTest extends Specification { cleanup: folder?.deleteDir() } + + def 'should normalize paths' () { + + given: + def cache = new CondaCache() + + expect: + cache.normalizeCondaEnv(RAW_CONDA_ENV) == EXPECTED + + where: + RAW_CONDA_ENV | EXPECTED + 'bwa=1.1.1' | 'bwa=1.1.1' + 'http://url.com/path/env.yml' | 'http://url.com/path/env.yml' + '/path/to/../directory' | '/path/directory' + '/path/./to/file.txt' | '/path/to/file.txt' + '/path/./to/file.yml' | '/path/to/file.yml' + } }