@@ -133,8 +133,9 @@ struct File {
133133 compressionStream. addTask {
134134 try Task . checkCancellation ( )
135135 let position = _position
136- let data = [ UInt8] ( unsafeUninitializedCapacity: blockSize + blockSize / 16 ) { buffer, count in
137- data [ position..< min ( position + blockSize, data. endIndex) ] . withUnsafeBufferPointer { data in
136+ let end = min ( position + blockSize, data. endIndex)
137+ let data = [ UInt8] ( unsafeUninitializedCapacity: ( end - position) + ( end - position) / 16 ) { buffer, count in
138+ data [ position..< end] . withUnsafeBufferPointer { data in
138139 count = compression_encode_buffer ( buffer. baseAddress!, buffer. count, data. baseAddress!, data. count, nil , COMPRESSION_LZFSE)
139140 guard count < buffer. count else {
140141 count = 0
@@ -365,7 +366,7 @@ public struct Unxip {
365366
366367 // The assumption is that all directories are provided without trailing slashes
367368 func parentDirectory< S: StringProtocol > ( of path: S ) -> S . SubSequence {
368- return path [ ..< path. lastIndex ( of: " / " ) !]
369+ path [ ..< path. lastIndex ( of: " / " ) !]
369370 }
370371
371372 // https://bugs.swift.org/browse/SR-15816
@@ -384,9 +385,11 @@ public struct Unxip {
384385 continue
385386 }
386387
387- if let ( original, task) = hardlinks [ file. identifier] {
388+ if let ( original, originalTask) = hardlinks [ file. identifier] {
389+ let task = parentDirectoryTask ( for: file)
390+ assert ( task != nil , file. name)
388391 _ = taskStream. addRunningTask {
389- await task. value
392+ _ = await ( originalTask . value , task? . value)
390393 warn ( link ( original, file. name) , " linking " )
391394 }
392395 continue
@@ -399,6 +402,7 @@ public struct Unxip {
399402 let task = parentDirectoryTask ( for: file)
400403 assert ( task != nil , file. name)
401404 _ = taskStream. addRunningTask {
405+ await task? . value
402406 warn ( symlink ( String ( data: Data ( file. data. map ( Array . init) . reduce ( [ ] , + ) ) , encoding: . utf8) , file. name) , " symlinking " )
403407 setStickyBit ( on: file)
404408 }
0 commit comments