Use last path component of a URI in the staged path.

This commit is contained in:
Mark Harrah 2013-06-23 19:57:30 -04:00
parent 1a3ea6fb8b
commit 6f0028e50d
1 changed files with 14 additions and 1 deletions

View File

@ -148,6 +148,19 @@ object Resolvers
def uniqueSubdirectoryFor(uri: URI, in: File) = {
in.mkdirs()
new File(in, Hash.halfHashString(uri.normalize.toASCIIString))
val base = new File(in, Hash.halfHashString(uri.normalize.toASCIIString))
val last = shortName(uri) match { case Some(n) => normalizeDirectoryName(n); case None => "root" }
new File(base, last)
}
private[this] def shortName(uri: URI): Option[String] =
Option(uri.withoutMarkerScheme.getPath).flatMap {
_.split("/").map(_.trim).filterNot(_.isEmpty).lastOption
}
private[this] def normalizeDirectoryName(name: String): String =
StringUtilities.normalize(dropExtensions(name))
private[this] def dropExtensions(name: String): String = name.takeWhile(_ != '.')
}