@@ -143,11 +143,13 @@ fileprivate extension InjectorV3 {
143143 var tarReader = TarReader ( fileHandle: tarHandle)
144144 var processedBundles = Set < String > ( )
145145 var bundleContents : [ String : [ ( info: TarEntryInfo , data: Data ? ) ] ] = [ : ]
146+
146147 while let entry = try tarReader. read ( ) {
147148 if entry. info. type == . regular && entry. info. name. hasSuffix ( " .dylib " ) {
148149 guard let entryData = entry. data else {
149150 continue
150151 }
152+
151153 let dylibName = URL ( fileURLWithPath: entry. info. name, relativeTo: targetURL) . lastPathComponent
152154 guard !dylibName. hasPrefix ( " . " ) else {
153155 continue
@@ -159,20 +161,16 @@ fileprivate extension InjectorV3 {
159161 try entryData. write ( to: entryURL)
160162 hasAnyDylib = true
161163 } else if entry. info. type == . directory && entry. info. name. hasSuffix ( " .bundle " ) {
162- // Extract bundle name
163164 let bundleName = URL ( fileURLWithPath: entry. info. name) . lastPathComponent
164- // Avoid processing duplicate or nested bundles
165165 guard !processedBundles. contains ( bundleName) else {
166166 continue
167167 }
168- // Track that we're processing this bundle
168+
169169 processedBundles. insert ( bundleName)
170- // Store bundle entries for later processing
171170 bundleContents [ entry. info. name] = [ ]
172171
173172 DDLogWarn ( " Found bundle \( entry. info. name) name \( bundleName) " , ddlog: logger)
174173 } else {
175- // Collect contents for all bundles
176174 for (bundlePath, _) in bundleContents {
177175 if entry. info. name. starts ( with: bundlePath + " / " ) {
178176 bundleContents [ bundlePath] ? . append ( ( entry. info, entry. data) )
@@ -184,36 +182,28 @@ fileprivate extension InjectorV3 {
184182 if !hasAnyDylib {
185183 throw Error . generic ( NSLocalizedString ( " No dylib found in the Debian package. " , comment: " " ) )
186184 }
185+
187186 let fileManager = FileManager . default
188- // Process collected bundle contents
189187 for (bundlePath, contents) in bundleContents {
190188 let bundleName = URL ( fileURLWithPath: bundlePath) . lastPathComponent
191-
192189 DDLogInfo ( " Preparing to copy bundle \( bundlePath) " , ddlog: logger)
193-
194- // Destination for the bundle
190+
195191 let destinationBundleURL = targetURL. appendingPathComponent ( bundleName)
196- // Remove existing bundle if it exists
197192 if fileManager. fileExists ( atPath: destinationBundleURL. path) {
198193 try fileManager. removeItem ( at: destinationBundleURL)
199194 }
200- // Create destination directory for the bundle
195+
201196 try fileManager. createDirectory ( at: destinationBundleURL, withIntermediateDirectories: true )
202-
203- // Copy bundle contents
197+
204198 for entry in contents {
205- // Get relative path within the bundle
206199 let relativePath = String ( entry. info. name. dropFirst ( bundlePath. count + 1 ) )
207200 let destinationPath = destinationBundleURL. appendingPathComponent ( relativePath)
208- // Handle different entry types
201+
209202 switch entry. info. type {
210203 case . directory:
211- // Create subdirectories
212204 try fileManager. createDirectory ( at: destinationPath, withIntermediateDirectories: true )
213205 case . regular:
214- // Ensure destination directory exists
215206 try fileManager. createDirectory ( at: destinationPath. deletingLastPathComponent ( ) , withIntermediateDirectories: true )
216- // Write file contents
217207 guard let fileData = entry. data else {
218208 DDLogWarn ( " Unable to read data for \( entry. info. name) " , ddlog: logger)
219209 continue
@@ -223,7 +213,7 @@ fileprivate extension InjectorV3 {
223213 continue
224214 }
225215 }
226-
216+
227217 DDLogInfo ( " Successfully copied bundle \( bundleName) " , ddlog: logger)
228218 }
229219 }
0 commit comments