Changeset 1258
- Timestamp:
- 01/31/10 18:42:24 (7 months ago)
- Files:
-
- 1 modified
-
trunk/CPFPerianPrefPaneController.m (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/CPFPerianPrefPaneController.m
r1257 r1258 21 21 #import "CPFPerianPrefPaneController.h" 22 22 #import "UpdateCheckerAppDelegate.h" 23 #include <sys/stat.h>24 23 25 24 #define AC3DynamicRangeKey CFSTR("dynamicRange") … … 455 454 #pragma mark Install/Uninstall 456 455 457 /* Shamelessly ripped from Sparkle */456 /* Shamelessly ripped from Sparkle (and now different) */ 458 457 - (BOOL)_extractArchivePath:archivePath toDestination:(NSString *)destination finalPath:(NSString *)finalPath 459 458 { 460 BOOL ret = NO, oldExist = NO; 461 struct stat sb; 462 463 if(stat([finalPath fileSystemRepresentation], &sb) == 0) 464 oldExist = YES; 465 466 char *buf = NULL; 459 BOOL ret = NO, oldExist; 460 NSFileManager *defaultFileManager = [NSFileManager defaultManager]; 461 char *cmd; 462 463 oldExist = [defaultFileManager fileExistsAtPath:finalPath]; 464 467 465 if(oldExist) 468 asprintf(&buf, 469 "mv -f \"$DST_COMPONENT\" \"$TMP_PATH\" && " 470 "ditto -x -k --rsrc \"$SRC_ARCHIVE\" \"$DST_PATH\" && " 471 "rm -rf \"$TMP_PATH\""); 472 else 473 asprintf(&buf, 474 "mkdir -p \"$DST_PATH\" && " 475 "ditto -x -k --rsrc \"$SRC_ARCHIVE\" \"$DST_PATH\""); 476 if(!buf) 477 { 478 [errorString appendFormat:NSLocalizedString(@"Could not allocate memory for extraction command\n", @"")]; 479 return FALSE; 480 } 466 cmd = "mv -f \"$DST_COMPONENT\" \"$TMP_PATH\" && " 467 "ditto -x -k --rsrc \"$SRC_ARCHIVE\" \"$DST_PATH\" && " 468 "rm -rf \"$TMP_PATH\""; 469 else 470 cmd = "mkdir -p \"$DST_PATH\" && " 471 "ditto -x -k --rsrc \"$SRC_ARCHIVE\" \"$DST_PATH\""; 481 472 482 473 setenv("SRC_ARCHIVE", [archivePath fileSystemRepresentation], 1); … … 484 475 setenv("DST_COMPONENT", [finalPath fileSystemRepresentation], 1); 485 476 setenv("TMP_PATH", [[finalPath stringByAppendingPathExtension:@"old"] fileSystemRepresentation], 1); 486 487 int status = system( buf);477 478 int status = system(cmd); 488 479 if(WIFEXITED(status) && WEXITSTATUS(status) == 0) 489 480 ret = YES; 490 481 else 491 482 [errorString appendFormat:NSLocalizedString(@"Extraction for %@ failed\n", @""), archivePath]; 492 493 free(buf); 483 494 484 unsetenv("SRC_ARCHIVE"); 495 unsetenv(" $DST_COMPONENT");485 unsetenv("DST_COMPONENT"); 496 486 unsetenv("TMP_PATH"); 497 487 unsetenv("DST_PATH"); … … 501 491 - (BOOL)_authenticatedExtractArchivePath:(NSString *)archivePath toDestination:(NSString *)destination finalPath:(NSString *)finalPath 502 492 { 503 BOOL ret = NO, oldExist = NO;504 struct stat sb;505 if(stat([finalPath fileSystemRepresentation], &sb) == 0)506 oldExist = YES;507 508 char *buf = NULL;493 BOOL ret = NO, oldExist; 494 NSFileManager *defaultFileManager = [NSFileManager defaultManager]; 495 char *cmd; 496 497 oldExist = [defaultFileManager fileExistsAtPath:finalPath]; 498 509 499 if(oldExist) 510 asprintf(&buf, 511 "mv -f \"$DST_COMPONENT\" \"$TMP_PATH\" && " 512 "ditto -x -k --rsrc \"$SRC_ARCHIVE\" \"$DST_PATH\" && " 513 "rm -rf \"$TMP_PATH\" && " 514 "chown -R root:admin \"$DST_COMPONENT\""); 515 else 516 asprintf(&buf, 517 "mkdir -p \"$DST_PATH\" && " 518 "ditto -x -k --rsrc \"$SRC_ARCHIVE\" \"$DST_PATH\" && " 519 "chown -R root:admin \"$DST_COMPONENT\""); 520 if(!buf) 521 { 522 [errorString appendFormat:NSLocalizedString(@"Could not allocate memory for extraction command\n", @"")]; 523 return FALSE; 524 } 500 cmd = "mv -f \"$DST_COMPONENT\" \"$TMP_PATH\" && " 501 "ditto -x -k --rsrc \"$SRC_ARCHIVE\" \"$DST_PATH\" && " 502 "rm -rf \"$TMP_PATH\" && " 503 "chown -R root:admin \"$DST_COMPONENT\""; 504 else 505 cmd = "mkdir -p \"$DST_PATH\" && " 506 "ditto -x -k --rsrc \"$SRC_ARCHIVE\" \"$DST_PATH\" && " 507 "chown -R root:admin \"$DST_COMPONENT\""; 525 508 526 509 setenv("SRC_ARCHIVE", [archivePath fileSystemRepresentation], 1); … … 529 512 setenv("DST_PATH", [destination fileSystemRepresentation], 1); 530 513 531 char* arguments[] = { "-c", buf, NULL };514 char* const arguments[] = { "-c", cmd, NULL }; 532 515 if(AuthorizationExecuteWithPrivileges(auth, "/bin/sh", kAuthorizationFlagDefaults, arguments, NULL) == errAuthorizationSuccess) 533 516 { … … 542 525 [errorString appendFormat:NSLocalizedString(@"Authentication failed for extraction for %@\n", @""), archivePath]; 543 526 544 free(buf);545 527 unsetenv("SRC_ARCHIVE"); 546 unsetenv(" $DST_COMPONENT");528 unsetenv("DST_COMPONENT"); 547 529 unsetenv("TMP_PATH"); 548 530 unsetenv("DST_PATH"); … … 553 535 { 554 536 BOOL ret = NO; 555 struct stat sb; 556 if(stat([componentPath fileSystemRepresentation], &sb) != 0) 557 /* No error, just forget it */ 537 NSFileManager *defaultFileManager = [NSFileManager defaultManager]; 538 539 if(![defaultFileManager fileExistsAtPath:componentPath]) 540 /* No error, just forget it */ 558 541 return FALSE; 559 542 560 char *buf = NULL; 561 asprintf(&buf, 562 "rm -rf \"$COMP_PATH\""); 563 if(!buf) 564 { 565 [errorString appendFormat:NSLocalizedString(@"Could not allocate memory for removal command\n", @"")]; 566 return FALSE; 567 } 543 char *cmd = "rm -rf \"$COMP_PATH\""; 568 544 569 545 setenv("COMP_PATH", [componentPath fileSystemRepresentation], 1); 570 546 571 char* arguments[] = { "-c", buf, NULL };547 char* const arguments[] = { "-c", cmd, NULL }; 572 548 if(AuthorizationExecuteWithPrivileges(auth, "/bin/sh", kAuthorizationFlagDefaults, arguments, NULL) == errAuthorizationSuccess) 573 549 { … … 581 557 else 582 558 [errorString appendFormat:NSLocalizedString(@"Authentication failed for removal for %@\n", @""), componentPath]; 583 free(buf);559 584 560 unsetenv("COMP_PATH"); 585 561 return ret; 586 562 } 587 588 563 589 564 - (BOOL)installArchive:(NSString *)archivePath forPiece:(NSString *)component type:(ComponentType)type withMyVersion:(NSString *)myVersion
