1
1
#import < Foundation/Foundation.h>
2
+ #include < sys/stat.h>
2
3
#include " AppList.h"
3
4
#include " common.h"
4
5
@@ -135,6 +136,7 @@ int backupApp(NSString* bundlePath)
135
136
return 0 ;
136
137
}
137
138
139
+ // if the app package is changed/upgraded, the directory structure may change and some paths may become invalid.
138
140
int restoreApp (NSString * bundlePath)
139
141
{
140
142
SYSLOG (" restoreApp=%@" , bundlePath);
@@ -200,24 +202,39 @@ int enableForApp(NSString* bundlePath)
200
202
201
203
ASSERT ([fm createSymbolicLinkAtPath: [jbroot (bundlePath) stringByAppendingString: @" /.jbroot" ] withDestinationPath: jbroot (@" /" ) error: nil ]);
202
204
203
- ASSERT (spawnBootstrap ((char *[]){" /usr/bin/uicache" ," -p" , bundlePath.UTF8String , NULL }, nil , nil ) == 0 );
205
+ NSString * log =nil ;
206
+ NSString * err=nil ;
207
+ if (spawnBootstrap ((char *[]){" /usr/bin/uicache" ," -p" , bundlePath.UTF8String , NULL }, &log , &err) != 0 ) {
208
+ STRAPLOG (" %@\n ERR:%@" , log , err);
209
+ ABORT ();
210
+ }
204
211
}
205
212
else if ([appInfo[@" CFBundleIdentifier" ] hasPrefix: @" com.apple." ]
206
213
|| [NSFileManager .defaultManager fileExistsAtPath: [bundlePath stringByAppendingString: @" /../_TrollStore" ]])
207
214
{
208
215
ASSERT (backupApp (bundlePath) == 0 );
209
216
210
217
ASSERT ([fm createSymbolicLinkAtPath: [bundlePath stringByAppendingString: @" /.jbroot" ] withDestinationPath: jbroot (@" /" ) error: nil ]);
211
-
212
- ASSERT (spawnBootstrap ((char *[]){" /usr/bin/uicache" ," -s" ," -p" , rootfsPrefix (bundlePath).UTF8String , NULL }, nil , nil ) == 0 );
218
+
219
+ NSString * log =nil ;
220
+ NSString * err=nil ;
221
+ if (spawnBootstrap ((char *[]){" /usr/bin/uicache" ," -s" ," -p" , rootfsPrefix (bundlePath).UTF8String , NULL }, &log , &err) != 0 ) {
222
+ STRAPLOG (" %@\n ERR:%@" , log , err);
223
+ ABORT ();
224
+ }
213
225
}
214
226
else
215
227
{
216
228
ASSERT (backupApp (bundlePath) == 0 );
217
229
218
230
ASSERT ([fm createSymbolicLinkAtPath: [bundlePath stringByAppendingString: @" /.jbroot" ] withDestinationPath: jbroot (@" /" ) error: nil ]);
219
231
220
- ASSERT (spawnBootstrap ((char *[]){" /usr/bin/uicache" ," -s" ," -p" , rootfsPrefix (bundlePath).UTF8String , NULL }, nil , nil ) == 0 );
232
+ NSString * log =nil ;
233
+ NSString * err=nil ;
234
+ if (spawnBootstrap ((char *[]){" /usr/bin/uicache" ," -s" ," -p" , rootfsPrefix (bundlePath).UTF8String , NULL }, &log , &err) != 0 ) {
235
+ STRAPLOG (" %@\n ERR:%@" , log , err);
236
+ ABORT ();
237
+ }
221
238
}
222
239
223
240
return 0 ;
@@ -242,17 +259,36 @@ int disableForApp(NSString* bundlePath)
242
259
else if ([appInfo[@" CFBundleIdentifier" ] hasPrefix: @" com.apple." ]
243
260
|| [NSFileManager .defaultManager fileExistsAtPath: [bundlePath stringByAppendingString: @" /../_TrollStore" ]])
244
261
{
262
+
263
+ struct stat st;
264
+ if (lstat ([bundlePath stringByAppendingString: @" /.jbroot" ].fileSystemRepresentation , &st)==0 )
265
+ ASSERT ([fm removeItemAtPath: [bundlePath stringByAppendingString: @" /.jbroot" ] error: nil ]);
266
+ if (lstat ([bundlePath stringByAppendingString: @" /.prelib" ].fileSystemRepresentation , &st)==0 )
267
+ ASSERT ([fm removeItemAtPath: [bundlePath stringByAppendingString: @" /.prelib" ] error: nil ]);
268
+ if (lstat ([bundlePath stringByAppendingString: @" /.preload" ].fileSystemRepresentation , &st)==0 )
269
+ ASSERT ([fm removeItemAtPath: [bundlePath stringByAppendingString: @" /.preload" ] error: nil ]);
270
+ if (lstat ([bundlePath stringByAppendingString: @" /.rebuild" ].fileSystemRepresentation , &st)==0 )
271
+ ASSERT ([fm removeItemAtPath: [bundlePath stringByAppendingString: @" /.rebuild" ] error: nil ]);
272
+
245
273
ASSERT (restoreApp (bundlePath) == 0 );
246
- ASSERT ([fm removeItemAtPath: [bundlePath stringByAppendingString: @" /.jbroot " ] error: nil ]);
274
+
247
275
ASSERT (spawnBootstrap ((char *[]){" /usr/bin/uicache" ," -s" ," -p" , rootfsPrefix (bundlePath).UTF8String , NULL }, nil , nil ) == 0 );
248
276
}
249
277
else
250
278
{
251
279
// should be an appstored app
252
280
253
- ASSERT (restoreApp (bundlePath) == 0 );
281
+ struct stat st;
282
+ if (lstat ([bundlePath stringByAppendingString: @" /.jbroot" ].fileSystemRepresentation , &st)==0 )
283
+ ASSERT ([fm removeItemAtPath: [bundlePath stringByAppendingString: @" /.jbroot" ] error: nil ]);
284
+ if (lstat ([bundlePath stringByAppendingString: @" /.prelib" ].fileSystemRepresentation , &st)==0 )
285
+ ASSERT ([fm removeItemAtPath: [bundlePath stringByAppendingString: @" /.prelib" ] error: nil ]);
286
+ if (lstat ([bundlePath stringByAppendingString: @" /.preload" ].fileSystemRepresentation , &st)==0 )
287
+ ASSERT ([fm removeItemAtPath: [bundlePath stringByAppendingString: @" /.preload" ] error: nil ]);
288
+ if (lstat ([bundlePath stringByAppendingString: @" /.rebuild" ].fileSystemRepresentation , &st)==0 )
289
+ ASSERT ([fm removeItemAtPath: [bundlePath stringByAppendingString: @" /.rebuild" ] error: nil ]);
254
290
255
- ASSERT ([fm removeItemAtPath: [ bundlePath stringByAppendingString: @" /.jbroot " ] error: nil ] );
291
+ ASSERT (restoreApp ( bundlePath) == 0 );
256
292
257
293
// unregister or respring to keep app's icon on home screen
258
294
ASSERT (spawnBootstrap ((char *[]){" /usr/bin/uicache" ," -u" , rootfsPrefix (bundlePath).UTF8String , NULL }, nil , nil ) == 0 );
0 commit comments