Skip to content

Commit

Permalink
Update IO.toURI to avoid syscalls
Browse files Browse the repository at this point in the history
  • Loading branch information
jtjeferreira authored and eed3si9n committed Nov 27, 2020
1 parent b8434fd commit f1dec11
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion io/src/main/scala/sbt/io/IO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1174,11 +1174,18 @@ object IO {
/** Converts the given File to a URI. If the File is relative, the URI is relative, unlike File.toURI*/
def toURI(f: File): URI =
if (f.isAbsolute) {
f.toPath.toUri
//not using f.toURI to avoid filesystem syscalls
//we use empty string as host to force file:// instead of just file:
new URI(FileScheme, "", normalizeName(slashify(f.getAbsolutePath)), null)
} else {
// need to use the three argument URI constructor because the single argument version doesn't encode
new URI(null, normalizeName(f.getPath), null)
}

private[this] def slashify(name: String) = {
if(name.nonEmpty && name.head != File.separatorChar) File.separatorChar + name
else name
}

/**
* Resolves `f` against `base`, which must be an absolute directory.
Expand Down

0 comments on commit f1dec11

Please sign in to comment.