Skip to content

Call getCanonicalPath instead of getAbsolutePath #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions io/src/main/scala/sbt/io/IO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ object IO {
*/
def relativize(base: File, file: File): Option[String] =
{
val pathString = file.getAbsolutePath
val pathString = file.getCanonicalPath
baseFileString(base) flatMap
{
baseString =>
Expand All @@ -553,7 +553,7 @@ object IO {
private def baseFileString(baseFile: File): Option[String] =
{
if (baseFile.isDirectory) {
val cp = baseFile.getAbsolutePath
val cp = baseFile.getCanonicalPath
assert(cp.length > 0)
val normalized = if (cp.charAt(cp.length - 1) == File.separatorChar) cp else cp + File.separatorChar
Some(normalized)
Expand Down
26 changes: 26 additions & 0 deletions io/src/test/scala/sbt/io/IOSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package sbt.io

import java.io.File
import java.nio.file.Files

import org.scalatest.{ FlatSpec, Matchers }

/**
* Created by Lloyd on 4/14/16.
*
* Copyright 2016
*/
class IOSpec extends FlatSpec with Matchers {

it should "relativize" in {
val tempDir = Files.createTempDirectory("io-relativize")
val tempFile = Files.createTempFile(tempDir, "meh", "file")
val tempDirInDir = Files.createTempDirectory(tempDir, "inside-dir")

val dirFromDirInDir = new File(tempDirInDir.toFile, "..")

IO.relativize(tempDir.toFile, tempFile.toFile).isDefined shouldBe true
IO.relativize(dirFromDirInDir, tempFile.toFile).isDefined shouldBe true
}

}