Permalink
Browse files

More detailed error handling and logging.

- Take failure of stat into account
- Use correct format for printing uids
- SULog actual failure points.
- Cope with nonexistent destinations
  • Loading branch information...
1 parent 575bdda commit efe903bc73044765a7e33418e04160b41ef1ef5d @uliwitness committed Dec 23, 2009
Showing with 20 additions and 2 deletions.
  1. +20 −2 SUPlainInstallerInternals.m
@@ -163,7 +163,17 @@ + (BOOL)_copyPathWithForcedAuthentication:(NSString *)src toPath:(NSString *)dst
const char* dstPath = [dst fileSystemRepresentation];
struct stat dstSB;
- stat(dstPath, &dstSB);
+ if( stat(dstPath, &dstSB) != 0 ) // Doesn't exist yet, try containing folder.
+ {
+ const char* dstDirPath = [[dst stringByDeletingLastPathComponent] fileSystemRepresentation];
+ if( stat(dstDirPath, &dstSB) != 0 )
+ {
+ NSString *errorMessage = [NSString stringWithFormat:@"Stat on %@ during authenticated file copy failed.", dst];
+ if (error != NULL)
+ *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUFileCopyFailure userInfo:[NSDictionary dictionaryWithObject:errorMessage forKey:NSLocalizedDescriptionKey]];
+ return NO;
+ }
+ }
AuthorizationRef auth = NULL;
OSStatus authStat = errAuthorizationDenied;
@@ -179,7 +189,7 @@ + (BOOL)_copyPathWithForcedAuthentication:(NSString *)src toPath:(NSString *)dst
res = YES;
char uidgid[42];
- snprintf(uidgid, sizeof(uidgid), "%d:%d",
+ snprintf(uidgid, sizeof(uidgid), "%u:%u",
dstSB.st_uid, dstSB.st_gid);
// If the currently-running application is trusted, the new
@@ -204,25 +214,33 @@ + (BOOL)_copyPathWithForcedAuthentication:(NSString *)src toPath:(NSString *)dst
{
const char* coParams[] = { "-R", uidgid, srcPath, NULL };
res = AuthorizationExecuteWithPrivilegesAndWait( auth, "/usr/sbin/chown", kAuthorizationFlagDefaults, coParams );
+ if( !res )
+ SULog( @"chown -R %s %s failed.", uidgid, srcPath );
}
BOOL haveDst = [[NSFileManager defaultManager] fileExistsAtPath: dst];
if( res && haveDst ) // If there's something at our tmp path (previous failed update or whatever) delete that first.
{
const char* rmParams[] = { "-rf", tmpPath, NULL };
res = AuthorizationExecuteWithPrivilegesAndWait( auth, "/bin/rm", kAuthorizationFlagDefaults, rmParams );
+ if( !res )
+ SULog( @"rm failed" );
}
if( res && haveDst ) // Move old exe to tmp path.
{
const char* mvParams[] = { "-f", dstPath, tmpPath, NULL };
res = AuthorizationExecuteWithPrivilegesAndWait( auth, "/bin/mv", kAuthorizationFlagDefaults, mvParams );
+ if( !res )
+ SULog( @"mv 1 failed" );
}
if( res ) // Move new exe to old exe's path.
{
const char* mvParams2[] = { "-f", srcPath, dstPath, NULL };
res = AuthorizationExecuteWithPrivilegesAndWait( auth, "/bin/mv", kAuthorizationFlagDefaults, mvParams2 );
+ if( !res )
+ SULog( @"mv 2 failed" );
}
// if( res && haveDst /*&& !foundTrash*/ ) // If we managed to put the old exe in the trash, leave it there for the user to delete or recover.

0 comments on commit efe903b

Please sign in to comment.