1616
1717package nextflow.processor
1818
19+ import nextflow.file.CopyOptions
20+
21+ import java.nio.file.StandardCopyOption
22+ import java.nio.file.StandardOpenOption
23+
1924import static nextflow.util.CacheHelper.*
2025
2126import java.nio.file.FileAlreadyExistsException
@@ -425,10 +430,16 @@ class PublishDir {
425430
426431 if ( ! sameRealPath && shouldOverwrite(source, destination) ) {
427432 log. warn " Overwriting file at ${ destination.toUriString()} "
428- FileHelper . deletePath(destination)
429- processFileImpl(source, destination)
433+
434+ if (destination. getFileSystem(). provider(). getScheme(). equals(" latch" )) {
435+ processFileImpl(source, destination, true )
436+ } else {
437+ FileHelper . deletePath(destination)
438+ processFileImpl(source, destination)
439+ }
440+
430441 } else {
431- log. debug " Skipping file . File already exists at ${ destination.toUriString()} "
442+ log. debug " Skipping upload . File already exists at ${ destination.toUriString()} "
432443 }
433444 }
434445
@@ -498,7 +509,7 @@ class PublishDir {
498509 return sourceHash != targetHash
499510 }
500511
501- protected void processFileImpl ( Path source , Path destination ) {
512+ protected void processFileImpl ( Path source , Path destination , boolean overwrite = false ) {
502513 log. trace " publishing file: $source -[$mode ]-> $destination "
503514
504515 if ( ! mode || mode == Mode . SYMLINK ) {
@@ -512,10 +523,18 @@ class PublishDir {
512523 FilesEx . mklink(source, [hard :true ], destination)
513524 }
514525 else if ( mode == Mode . MOVE ) {
515- FileHelper . movePath(source, destination)
526+ if (overwrite) {
527+ FileHelper . movePath(source, destination, StandardCopyOption . REPLACE_EXISTING )
528+ } else {
529+ FileHelper . movePath(source, destination)
530+ }
516531 }
517532 else if ( mode == Mode . COPY ) {
518- FileHelper . copyPath(source, destination)
533+ if (overwrite) {
534+ FileHelper . copyPath(source, destination, StandardCopyOption . REPLACE_EXISTING )
535+ } else {
536+ FileHelper . copyPath(source, destination)
537+ }
519538 }
520539 else if ( mode == Mode . COPY_NO_FOLLOW ) {
521540 FileHelper . copyPath(source, destination, LinkOption . NOFOLLOW_LINKS )
0 commit comments