mirror of
https://github.com/ij-plugins/ijp-imagej-launcher.git
synced 2024-11-13 16:29:01 -08:00
Address issue with relative paths not being created correctly in native code on Windows
Possible Scala-Native bug in java.nio.file.Path.relativize native implementation
This commit is contained in:
parent
2178cc98c7
commit
8f6f1bbda5
1 changed files with 19 additions and 3 deletions
|
|
@ -1,6 +1,6 @@
|
|||
package ij_plugins.imagej_launcher
|
||||
|
||||
import os.Path
|
||||
import os.{Path, RelPath}
|
||||
|
||||
import scala.util.control.NonFatal
|
||||
|
||||
|
|
@ -23,7 +23,8 @@ object Updater:
|
|||
os.walk(updateDir)
|
||||
.filter(os.isFile)
|
||||
.foreach { src =>
|
||||
val dst = ijDir / src.relativeTo(updateDir)
|
||||
// val relativeDir = src.relativeTo(updateDir)
|
||||
val dst = ijDir / relativeTo(src, updateDir)
|
||||
if os.size(src) == 0 then
|
||||
logger.debug(s"remove: $dst")
|
||||
if !dryRun then os.remove(dst)
|
||||
|
|
@ -45,6 +46,21 @@ object Updater:
|
|||
ex.printStackTrace()
|
||||
Left(s"Failed to perform update: ${ex.getMessage} - ${ex.getClass.getSimpleName}")
|
||||
|
||||
private def relativeTo(src: Path, base: Path): RelPath =
|
||||
// This does what src.relativeTo(base) should do
|
||||
// Problems is in the native code on Windows, it creates relative path by adding `../` at the beginning of the path
|
||||
// rather than creating a relative path
|
||||
// Implementation is very limited and assumes specific relation between src and base that should hold in our case
|
||||
|
||||
val srcStr = src.toString
|
||||
val baseStr = base.toString
|
||||
require(baseStr.nonEmpty)
|
||||
require(srcStr.startsWith(baseStr))
|
||||
|
||||
val relStr = srcStr.drop(baseStr.length + 1)
|
||||
RelPath(relStr)
|
||||
|
||||
|
||||
private def deleteEmptyDirs(dir: Path, logger: Logger): Unit =
|
||||
logger.debug(s"Cleaning directory: $dir")
|
||||
os.list(dir)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue