Skip to content

Commit

Permalink
Files.copy(tempFile, installedFile)
Browse files Browse the repository at this point in the history
  • Loading branch information
drernie committed Sep 10, 2023
1 parent 51eb557 commit 3770b5d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ import nextflow.Session
import nextflow.file.FileSystemTransferAware
import nextflow.quilt.jep.QuiltParser
import nextflow.quilt.jep.QuiltPackage
import sun.nio.fs.UnixFileSystemProvider
import sun.nio.fs.MacOSXFileSystemProvider

/**
* Implements NIO File system provider for Quilt Blob Storage
Expand Down Expand Up @@ -85,22 +87,33 @@ class QuiltFileSystemProvider extends FileSystemProvider implements FileSystemTr
return path.getFileSystem().provider()
}

boolean canUpload(Path source, Path target) {
log.debug("QuiltFileSystemProvider.canUpload[${source}] -> ${target}")
return false
static boolean localProvider(Path path) {
FileSystemProvider provider = provider(path)
log.debug("QuiltFileSystemProvider.localProvider[${path}] -> ${provider}")
return provider instanceof UnixFileSystemProvider ||
provider instanceof MacOSXFileSystemProvider
}

boolean canDownload(Path source, Path target) {
log.debug("QuiltFileSystemProvider.canDownload[${source}] -> ${target}")
return false
return localProvider(target) && source instanceof QuiltPath
}

boolean canUpload(Path source, Path target) {
log.debug("QuiltFileSystemProvider.canUpload[${source}] -> ${target}")
return localProvider(source) && target instanceof QuiltPath
}

void download(Path source, Path target, CopyOption... options) throws IOException {
throw new UnsupportedOperationException("Operation 'download' is not supported by QuiltFileSystem")
QuiltPath qSource = asQuiltPath(source)
Path local_source = qSource.localPath()
Files.copy(local_source, target, options)
}

void upload(Path source, Path target, CopyOption... options) throws IOException {
throw new UnsupportedOperationException("Operation 'upload' is not supported by QuiltFileSystem")
QuiltPath qTarget = asQuiltPath(target)
Path local_target = qTarget.localPath()
Files.copy(source, local_target, options)
}

/**
Expand Down Expand Up @@ -359,7 +372,7 @@ class QuiltFileSystemProvider extends FileSystemProvider implements FileSystemTr

@Override
void copy(Path from, Path to, CopyOption... options) throws IOException {
//log.debug("Attempting `copy`: ${from} -> ${to}")
log.debug("Attempting `copy`: ${from} -> ${to}")
assert provider(from) == provider(to)
if (from == to) {
return // nothing to do -- just return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,31 @@ class QuiltPackageTest extends QuiltSpecification {
Files.exists(installPath)
}

void 'should copy temp files into install folder'() {
given:
String filename = 'test.txt'
Path installPath = pkg.packageDest()
Path tempFile = File.createTempFile('test', '.txt').toPath()
println("tempFile: "+tempFile);
Path installedFile = Paths.get(installPath.toString(), filename)
expect:
Files.exists(tempFile)
Files.exists(installPath)
!Files.exists(installedFile)
Files.copy(tempFile, installedFile)
Files.exists(installedFile)
}

void 'should copy package files to temp Path'() {
given:
Path installPath = pkg.packageDest()
expect:
Files.exists(installPath)
Files.isDirectory(installPath)
Files.readAttributes(installPath, BasicFileAttributes)
}


void 'should get attributes for package folder'() {
given:
def root = qpath.getRoot()
Expand All @@ -106,6 +131,7 @@ class QuiltPackageTest extends QuiltSpecification {
Files.readAttributes(qpath, BasicFileAttributes)
}


void 'should return null on failed install'() {
given:
def url2 = TEST_URL.replace('quilt-', 'quilted-')
Expand All @@ -125,11 +151,6 @@ class QuiltPackageTest extends QuiltSpecification {
qpath.deinstall()
then:
!Files.exists(qpath.localPath(false))

/*when:
Files.readAttributes(qpath, BasicFileAttributes)
then:
thrown(java.nio.file.NoSuchFileException)*/
}

void 'should iterate over installed files '() {
Expand Down

0 comments on commit 3770b5d

Please sign in to comment.