@@ -66,15 +66,15 @@ abstract class ZipArchive(override val jpath: JPath) extends AbstractFile with E
66
66
def absolute : AbstractFile = unsupported()
67
67
68
68
/** ''Note: This library is considered experimental and should not be used unless you know what you are doing.'' */
69
- sealed abstract class Entry (path : String ) extends VirtualFile (baseName(path), path) {
69
+ sealed abstract class Entry (path : String , val parent : Entry ) extends VirtualFile (baseName(path), path) {
70
70
// have to keep this name for compat with sbt's compiler-interface
71
71
def getArchive : ZipFile = null
72
72
override def underlyingSource : Option [ZipArchive ] = Some (self)
73
73
override def toString : String = self.path + " (" + path + " )"
74
74
}
75
75
76
76
/** ''Note: This library is considered experimental and should not be used unless you know what you are doing.'' */
77
- class DirEntry (path : String ) extends Entry (path) {
77
+ class DirEntry (path : String , parent : Entry ) extends Entry (path, parent ) {
78
78
val entries : mutable.HashMap [String , Entry ] = mutable.HashMap ()
79
79
80
80
override def isDirectory : Boolean = true
@@ -98,7 +98,7 @@ abstract class ZipArchive(override val jpath: JPath) extends AbstractFile with E
98
98
case Some (v) => v
99
99
case None =>
100
100
val parent = ensureDir(dirs, dirName(path), null )
101
- val dir = new DirEntry (path)
101
+ val dir = new DirEntry (path, parent )
102
102
parent.entries(baseName(path)) = dir
103
103
dirs(path) = dir
104
104
dir
@@ -120,8 +120,9 @@ final class FileZipArchive(jpath: JPath) extends ZipArchive(jpath) {
120
120
private class LazyEntry (
121
121
name : String ,
122
122
time : Long ,
123
- size : Int
124
- ) extends Entry (name) {
123
+ size : Int ,
124
+ parent : DirEntry
125
+ ) extends Entry (name, parent) {
125
126
override def lastModified : Long = time // could be stale
126
127
override def input : InputStream = {
127
128
val zipFile = openZipFile()
@@ -140,15 +141,16 @@ final class FileZipArchive(jpath: JPath) extends ZipArchive(jpath) {
140
141
// faster than LazyEntry.
141
142
private class LeakyEntry (
142
143
zipFile : ZipFile ,
143
- zipEntry : ZipEntry
144
- ) extends Entry (zipEntry.getName) {
144
+ zipEntry : ZipEntry ,
145
+ parent : DirEntry
146
+ ) extends Entry (zipEntry.getName, parent) {
145
147
override def lastModified : Long = zipEntry.getTime
146
148
override def input : InputStream = zipFile.getInputStream(zipEntry)
147
149
override def sizeOption : Option [Int ] = Some (zipEntry.getSize.toInt)
148
150
}
149
151
150
152
@ volatile lazy val (root, allDirs): (DirEntry , collection.Map [String , DirEntry ]) = {
151
- val root = new DirEntry (" /" )
153
+ val root = new DirEntry (" /" , null )
152
154
val dirs = mutable.HashMap [String , DirEntry ](" /" -> root)
153
155
val zipFile = openZipFile()
154
156
val entries = zipFile.entries()
@@ -163,10 +165,11 @@ final class FileZipArchive(jpath: JPath) extends ZipArchive(jpath) {
163
165
new LazyEntry (
164
166
zipEntry.getName(),
165
167
zipEntry.getTime(),
166
- zipEntry.getSize().toInt
168
+ zipEntry.getSize().toInt,
169
+ dir
167
170
)
168
171
else
169
- new LeakyEntry (zipFile, zipEntry)
172
+ new LeakyEntry (zipFile, zipEntry, dir )
170
173
171
174
dir.entries(f.name) = f
172
175
}
@@ -195,15 +198,15 @@ final class FileZipArchive(jpath: JPath) extends ZipArchive(jpath) {
195
198
196
199
final class ManifestResources (val url : URL ) extends ZipArchive (null ) {
197
200
def iterator (): Iterator [AbstractFile ] = {
198
- val root = new DirEntry (" /" )
201
+ val root = new DirEntry (" /" , null )
199
202
val dirs = mutable.HashMap [String , DirEntry ](" /" -> root)
200
203
val manifest = new Manifest (input)
201
204
val iter = manifest.getEntries().keySet().iterator().asScala.filter(_.endsWith(" .class" )).map(new ZipEntry (_))
202
205
203
206
for (zipEntry <- iter) {
204
207
val dir = getDir(dirs, zipEntry)
205
208
if (! zipEntry.isDirectory) {
206
- val f = new Entry (zipEntry.getName) {
209
+ val f = new Entry (zipEntry.getName, dir ) {
207
210
override def lastModified = zipEntry.getTime()
208
211
override def input = resourceInputStream(path)
209
212
override def sizeOption = None
0 commit comments