Skip to content
Snippets Groups Projects
Commit 2c360e07 authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Merge branch 'feature-ln-fix' into 'develop'

Feature ln fix

@w.arindrarto , could you check this first?

the ' single-quotes are giving me trouble in executing as a InProgressFunction.

See merge request !26
parents 79a81076 05977cb2
No related branches found
No related tags found
No related merge requests found
package nl.lumc.sasc.biopet.extensions
import java.io.File
import scala.sys.process.Process
import scala.sys.process.{ Process, ProcessLogger }
import org.broadinstitute.gatk.queue.function.InProcessFunction
import org.broadinstitute.gatk.utils.commandline.{ Input, Output }
import nl.lumc.sasc.biopet.core.config.Configurable
......@@ -71,15 +71,21 @@ class Ln(val root: Configurable) extends InProcessFunction with Configurable {
if (relative) {
// workaround until we have `ln` that works with relative path (i.e. `ln -r`)
"ln -s '" + inRelative + "' '" + outCanonical + "'"
"ln -s " + inRelative + " " + outCanonical
} else {
"ln -s '" + inCanonical + "' '" + outCanonical + "'"
"ln -s " + inCanonical + " " + outCanonical
}
}
override def run {
val process = Process(cmd).run
logger.info("cmd: '" + cmd + "', exitcode: " + process.exitValue)
val stdout = new StringBuffer()
val stderr = new StringBuffer()
val process = Process(cmd).run(ProcessLogger(stdout append _ + "\n", stderr append _ + "\n"))
val exitcode = process.exitValue
if (exitcode != 0) {
throw new Exception("Error creating symbolic link, this was the original message: \n" + stderr)
}
logger.info("cmd: '" + cmd + "', exitcode: " + exitcode)
}
}
......
......@@ -19,7 +19,7 @@ class LnUnitTest extends TestNGSuite with Matchers {
ln.relative = true
ln.in = new File("/dir/nested/target.txt")
ln.out = new File("/dir/nested/link.txt")
ln.cmd should ===("ln -s 'target.txt' '/dir/nested/link.txt'")
ln.cmd should ===("ln -s target.txt /dir/nested/link.txt")
}
@Test(description = "Target is one level above link, relative set to true")
......@@ -28,7 +28,7 @@ class LnUnitTest extends TestNGSuite with Matchers {
ln.relative = true
ln.in = new File("/dir/target.txt")
ln.out = new File("/dir/nested/link.txt")
ln.cmd should ===("ln -s '../target.txt' '/dir/nested/link.txt'")
ln.cmd should ===("ln -s ../target.txt /dir/nested/link.txt")
}
@Test(description = "Target is two levels above link, relative set to true")
......@@ -37,7 +37,7 @@ class LnUnitTest extends TestNGSuite with Matchers {
ln.relative = true
ln.in = new File("/target.txt")
ln.out = new File("/dir/nested/link.txt")
ln.cmd should ===("ln -s '../../target.txt' '/dir/nested/link.txt'")
ln.cmd should ===("ln -s ../../target.txt /dir/nested/link.txt")
}
@Test(description = "Target is a child of a directory one level above link, relative set to true")
......@@ -46,7 +46,7 @@ class LnUnitTest extends TestNGSuite with Matchers {
ln.relative = true
ln.in = new File("/dir/another_nested/target.txt")
ln.out = new File("/dir/nested/link.txt")
ln.cmd should ===("ln -s '../another_nested/target.txt' '/dir/nested/link.txt'")
ln.cmd should ===("ln -s ../another_nested/target.txt /dir/nested/link.txt")
}
@Test(description = "Target is one level below link, relative set to true")
......@@ -55,7 +55,7 @@ class LnUnitTest extends TestNGSuite with Matchers {
ln.relative = true
ln.in = new File("/dir/nested/deeper/target.txt")
ln.out = new File("/dir/nested/link.txt")
ln.cmd should ===("ln -s 'deeper/target.txt' '/dir/nested/link.txt'")
ln.cmd should ===("ln -s deeper/target.txt /dir/nested/link.txt")
}
@Test(description = "Target is two levels below link, relative set to true")
......@@ -64,7 +64,7 @@ class LnUnitTest extends TestNGSuite with Matchers {
ln.relative = true
ln.in = new File("/dir/nested/even/deeper/target.txt")
ln.out = new File("/dir/nested/link.txt")
ln.cmd should ===("ln -s 'even/deeper/target.txt' '/dir/nested/link.txt'")
ln.cmd should ===("ln -s even/deeper/target.txt /dir/nested/link.txt")
}
@Test(description = "Relative set to false")
......@@ -73,7 +73,7 @@ class LnUnitTest extends TestNGSuite with Matchers {
ln.relative = false
ln.in = new File("/dir/nested/target.txt")
ln.out = new File("/dir/nested/link.txt")
ln.cmd should ===("ln -s '/dir/nested/target.txt' '/dir/nested/link.txt'")
ln.cmd should ===("ln -s /dir/nested/target.txt /dir/nested/link.txt")
}
// TODO: test for case where abosolute is true and input paths are relative?
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment