@@ -143,11 +143,13 @@ fileprivate extension InjectorV3 {
143
143
var tarReader = TarReader ( fileHandle: tarHandle)
144
144
var processedBundles = Set < String > ( )
145
145
var bundleContents : [ String : [ ( info: TarEntryInfo , data: Data ? ) ] ] = [ : ]
146
+
146
147
while let entry = try tarReader. read ( ) {
147
148
if entry. info. type == . regular && entry. info. name. hasSuffix ( " .dylib " ) {
148
149
guard let entryData = entry. data else {
149
150
continue
150
151
}
152
+
151
153
let dylibName = URL ( fileURLWithPath: entry. info. name, relativeTo: targetURL) . lastPathComponent
152
154
guard !dylibName. hasPrefix ( " . " ) else {
153
155
continue
@@ -159,20 +161,16 @@ fileprivate extension InjectorV3 {
159
161
try entryData. write ( to: entryURL)
160
162
hasAnyDylib = true
161
163
} else if entry. info. type == . directory && entry. info. name. hasSuffix ( " .bundle " ) {
162
- // Extract bundle name
163
164
let bundleName = URL ( fileURLWithPath: entry. info. name) . lastPathComponent
164
- // Avoid processing duplicate or nested bundles
165
165
guard !processedBundles. contains ( bundleName) else {
166
166
continue
167
167
}
168
- // Track that we're processing this bundle
168
+
169
169
processedBundles. insert ( bundleName)
170
- // Store bundle entries for later processing
171
170
bundleContents [ entry. info. name] = [ ]
172
171
173
172
DDLogWarn ( " Found bundle \( entry. info. name) name \( bundleName) " , ddlog: logger)
174
173
} else {
175
- // Collect contents for all bundles
176
174
for (bundlePath, _) in bundleContents {
177
175
if entry. info. name. starts ( with: bundlePath + " / " ) {
178
176
bundleContents [ bundlePath] ? . append ( ( entry. info, entry. data) )
@@ -184,36 +182,28 @@ fileprivate extension InjectorV3 {
184
182
if !hasAnyDylib {
185
183
throw Error . generic ( NSLocalizedString ( " No dylib found in the Debian package. " , comment: " " ) )
186
184
}
185
+
187
186
let fileManager = FileManager . default
188
- // Process collected bundle contents
189
187
for (bundlePath, contents) in bundleContents {
190
188
let bundleName = URL ( fileURLWithPath: bundlePath) . lastPathComponent
191
-
192
189
DDLogInfo ( " Preparing to copy bundle \( bundlePath) " , ddlog: logger)
193
-
194
- // Destination for the bundle
190
+
195
191
let destinationBundleURL = targetURL. appendingPathComponent ( bundleName)
196
- // Remove existing bundle if it exists
197
192
if fileManager. fileExists ( atPath: destinationBundleURL. path) {
198
193
try fileManager. removeItem ( at: destinationBundleURL)
199
194
}
200
- // Create destination directory for the bundle
195
+
201
196
try fileManager. createDirectory ( at: destinationBundleURL, withIntermediateDirectories: true )
202
-
203
- // Copy bundle contents
197
+
204
198
for entry in contents {
205
- // Get relative path within the bundle
206
199
let relativePath = String ( entry. info. name. dropFirst ( bundlePath. count + 1 ) )
207
200
let destinationPath = destinationBundleURL. appendingPathComponent ( relativePath)
208
- // Handle different entry types
201
+
209
202
switch entry. info. type {
210
203
case . directory:
211
- // Create subdirectories
212
204
try fileManager. createDirectory ( at: destinationPath, withIntermediateDirectories: true )
213
205
case . regular:
214
- // Ensure destination directory exists
215
206
try fileManager. createDirectory ( at: destinationPath. deletingLastPathComponent ( ) , withIntermediateDirectories: true )
216
- // Write file contents
217
207
guard let fileData = entry. data else {
218
208
DDLogWarn ( " Unable to read data for \( entry. info. name) " , ddlog: logger)
219
209
continue
@@ -223,7 +213,7 @@ fileprivate extension InjectorV3 {
223
213
continue
224
214
}
225
215
}
226
-
216
+
227
217
DDLogInfo ( " Successfully copied bundle \( bundleName) " , ddlog: logger)
228
218
}
229
219
}
0 commit comments