made zip file system error instead of return null if the specified root path isn't a directory

This commit is contained in:
Florian Nücke 2014-03-16 09:01:03 +01:00
parent b3a737c57c
commit 62f5a7a993

View File

@ -82,9 +82,12 @@ object ZipFileInputStreamFileSystem {
Option(cache.get(file.getPath + ":" + innerPath, new Callable[ArchiveDirectory] { Option(cache.get(file.getPath + ":" + innerPath, new Callable[ArchiveDirectory] {
def call = { def call = {
val zip = new ZipFile(file.getPath) val zip = new ZipFile(file.getPath)
val cleanedPath = innerPath.stripPrefix("/").stripSuffix("/") + "/" try {
val rootEntry = zip.getEntry(cleanedPath) val cleanedPath = innerPath.stripPrefix("/").stripSuffix("/") + "/"
val result = if (rootEntry != null && rootEntry.isDirectory) { val rootEntry = zip.getEntry(cleanedPath)
if (rootEntry == null || !rootEntry.isDirectory) {
throw new IllegalArgumentException(s"Root path $innerPath doesn't exist or is not a directory in ZIP file ${file.getName}.")
}
val directories = mutable.Set.empty[ArchiveDirectory] val directories = mutable.Set.empty[ArchiveDirectory]
val files = mutable.Set.empty[ArchiveFile] val files = mutable.Set.empty[ArchiveFile]
val iterator = zip.entries() val iterator = zip.entries()
@ -111,9 +114,9 @@ object ZipFileInputStreamFileSystem {
} }
root root
} }
else null finally {
zip.close() zip.close()
result }
} }
})) match { })) match {
case Some(archive) => new ZipFileInputStreamFileSystem(archive) case Some(archive) => new ZipFileInputStreamFileSystem(archive)