@@ -62,6 +62,25 @@ object ZipArchive {
62
62
if (front) path.substring(0 , idx + 1 )
63
63
else path.substring(idx + 1 )
64
64
}
65
+ def pathToDotted (path : String ): String = {
66
+ if (path == " /" ) " "
67
+ else {
68
+ val slashEnd = path.endsWith(" /" )
69
+ val len = path.length - (if (slashEnd) 1 else 0 )
70
+ val result = new Array [Char ](len)
71
+ var i = 0
72
+ while (i < len) {
73
+ val char = path.charAt(i)
74
+ result(i) = if (char == '/' ) '.' else char
75
+ i += 1
76
+ }
77
+ new String (result)
78
+ }
79
+ }
80
+ def dottedToPath (dotted : String ): String = {
81
+ val sb = new java.lang.StringBuilder (dotted.length)
82
+ dotted.replace('.' , '/' ) + " /"
83
+ }
65
84
}
66
85
import ZipArchive ._
67
86
/** ''Note: This library is considered experimental and should not be used unless you know what you are doing.'' */
@@ -101,7 +120,7 @@ abstract class ZipArchive(override val file: JFile, release: Option[String]) ext
101
120
}
102
121
}
103
122
104
- private def ensureDir (dirs : mutable.Map [String , DirEntry ], path : String , zipEntry : ZipEntry ): DirEntry =
123
+ private def ensureDir (dirs : mutable.Map [String , DirEntry ], path : String , zipEntry : ZipEntry ): DirEntry = {
105
124
// OPT inlined from getOrElseUpdate; saves ~50K closures on test run.
106
125
// was:
107
126
// dirs.getOrElseUpdate(path, {
@@ -110,15 +129,17 @@ abstract class ZipArchive(override val file: JFile, release: Option[String]) ext
110
129
// parent.entries(baseName(path)) = dir
111
130
// dir
112
131
// })
113
- dirs get path match {
132
+ val dotted = pathToDotted(path)
133
+ dirs get dotted match {
114
134
case Some (v) => v
115
135
case None =>
116
136
val parent = ensureDir(dirs, dirName(path), null )
117
- val dir = new DirEntry (path)
137
+ val dir = new DirEntry (path)
118
138
parent.entries(baseName(path)) = dir
119
- dirs(path ) = dir
139
+ dirs(dotted ) = dir
120
140
dir
121
141
}
142
+ }
122
143
123
144
protected def getDir (dirs : mutable.Map [String , DirEntry ], entry : ZipEntry ): DirEntry = {
124
145
if (entry.isDirectory) ensureDir(dirs, entry.getName, entry)
@@ -171,9 +192,9 @@ final class FileZipArchive(file: JFile, release: Option[String]) extends ZipArch
171
192
override def sizeOption : Option [Int ] = Some (zipEntry.getSize.toInt)
172
193
}
173
194
174
- lazy val (root, allDirs ) = {
195
+ lazy val (root, allDirsByDottedName ) = {
175
196
val root = new DirEntry (" /" )
176
- val dirs = mutable.HashMap [String , DirEntry ](" / " -> root)
197
+ val dirs = mutable.HashMap [String , DirEntry ](" " -> root)
177
198
val zipFile = openZipFile()
178
199
val enum = zipFile.entries()
179
200
@@ -206,6 +227,9 @@ final class FileZipArchive(file: JFile, release: Option[String]) extends ZipArch
206
227
(root, dirs)
207
228
}
208
229
230
+ @ deprecated(" Use allDirsByDottedName after converting keys from relative paths to dotted names" , " 2.13" )
231
+ lazy val allDirs : mutable.HashMap [String , DirEntry ] = allDirsByDottedName.map { case (k, v) => (dottedToPath(k), v) }
232
+
209
233
def iterator : Iterator [Entry ] = root.iterator
210
234
211
235
def name = file.getName
0 commit comments