Skip to content

Commit

Permalink
Fix collectFile cache over remote storage [ci fast]
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
  • Loading branch information
pditommaso committed Feb 12, 2023
1 parent 9a3b421 commit 762ba19
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import java.nio.file.attribute.BasicFileAttributes
import com.google.common.hash.HashCode
import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import nextflow.Global
import nextflow.extension.FilesEx
import nextflow.io.SkipLinesInputStream
import nextflow.util.CacheHelper
Expand Down Expand Up @@ -237,7 +238,8 @@ abstract class FileCollector implements Closeable {

// verify if a cached list exists
final hash = makeHash()?.toString()
Path temp = hash ? FileHelper.getLocalTempPath().resolve("${hash}.collect-file") : null

final Path temp = hash ? Global.session.workDir.resolve('collect-file').resolve(hash) : null

// try to retrieve cached files
List<Path> items = null
Expand All @@ -250,7 +252,11 @@ abstract class FileCollector implements Closeable {
items = saveTo0(target)
// save the list of collected files
if( cacheable && temp ) {
cacheCollectedFile(items, temp)
if( FilesEx.mkdirs(temp.parent) ) {
cacheCollectedFile(items, temp)
} else {
throw new IOException("Unable to create temporary directory: ${temp.toUriString()} -- Make sure a file with the same name doesn't already exist and you have write permissions")
}
}
}

Expand Down Expand Up @@ -289,14 +295,14 @@ abstract class FileCollector implements Closeable {
List<Path> items = (List<Path>)KryoHelper.deserialize(temp)
def notFound = items.find { Path p -> !p.exists() }
if( notFound ) throw new NoSuchFileException("Missing cached file: $notFound")
log.debug "Retrieved cached collect-files from: ${temp} -- cached files: ${items}"
log.debug "Retrieved cached collect-files from: ${temp.toUriString()}"
return items
}
catch( NoSuchFileException e ) {
log.debug "Missed collect-file cache -- cause: ${e}"
}
catch( Exception e ) {
log.debug "Unable retrieve cached collect-files from: ${temp}", e
log.debug "Unable retrieve cached collect-files from: ${temp.toUriString()}", e
temp.delete()
}
return null
Expand Down

0 comments on commit 762ba19

Please sign in to comment.