[55488] branches/gsoc09-gui

juanger at macports.org juanger at macports.org
Tue Aug 11 21:40:28 PDT 2009


Revision: 55488
          http://trac.macports.org/changeset/55488
Author:   juanger at macports.org
Date:     2009-08-11 21:40:26 -0700 (Tue, 11 Aug 2009)
Log Message:
-----------
New handling of authorization mode via NSFileManager.

Modified Paths:
--------------
    branches/gsoc09-gui/MPGUI/MPActionLauncher.m
    branches/gsoc09-gui/MPGUI/MPActionsController.m
    branches/gsoc09-gui/MacPorts_Framework/BetterAuthorizationSampleLib.c
    branches/gsoc09-gui/MacPorts_Framework/MPInterpreter.m
    branches/gsoc09-gui/MacPorts_Framework/MPMacPorts.h
    branches/gsoc09-gui/MacPorts_Framework/MPMacPorts.m

Modified: branches/gsoc09-gui/MPGUI/MPActionLauncher.m
===================================================================
--- branches/gsoc09-gui/MPGUI/MPActionLauncher.m	2009-08-12 03:53:35 UTC (rev 55487)
+++ branches/gsoc09-gui/MPGUI/MPActionLauncher.m	2009-08-12 04:40:26 UTC (rev 55488)
@@ -76,10 +76,7 @@
 - (void)cancelPortProcess {
     //  TODO: display confirmation dialog
     //        send a "Shutting down" notification
-    NSTask *task = [MPInterpreter task];
-    if(task != nil && [task isRunning]) {
-        [task terminate];
-    }
+    [[MPMacPorts sharedInstance] cancelCurrentCommand];
 }
 
 @end

Modified: branches/gsoc09-gui/MPGUI/MPActionsController.m
===================================================================
--- branches/gsoc09-gui/MPGUI/MPActionsController.m	2009-08-12 03:53:35 UTC (rev 55487)
+++ branches/gsoc09-gui/MPGUI/MPActionsController.m	2009-08-12 04:40:26 UTC (rev 55488)
@@ -51,7 +51,7 @@
 
 - (IBAction)cancel:(id)sender {
     [activityController setBusy:NO]; // TODO: Should I set this with a notification?
-    [[MPActionLauncher sharedInstance] cancelPortProcess];
+    [[MPMacPorts sharedInstance] cancelCurrentCommand];
 }
 
 -(BOOL)validateToolbarItem:(NSToolbarItem *)toolbarItem {
@@ -59,7 +59,7 @@
     if ([[toolbarItem itemIdentifier] isEqual:[cancel itemIdentifier]]) {
         enable = !enable;
     } 
-    return enable;
+    return YES;
 }
 
 #pragma mark App Delegate

Modified: branches/gsoc09-gui/MacPorts_Framework/BetterAuthorizationSampleLib.c
===================================================================
--- branches/gsoc09-gui/MacPorts_Framework/BetterAuthorizationSampleLib.c	2009-08-12 03:53:35 UTC (rev 55487)
+++ branches/gsoc09-gui/MacPorts_Framework/BetterAuthorizationSampleLib.c	2009-08-12 04:40:26 UTC (rev 55488)
@@ -77,7 +77,7 @@
 
 enum {
     kIdleTimeoutInSeconds     = 120,        // if we get no requests in 2 minutes, we quit
-    kWatchdogTimeoutInSeconds = 65          // any given request must be completely in 65 seconds
+    kWatchdogTimeoutInSeconds = 500000      // any given request must be completed in ~5 days (is this ok?)
 };
 
 // IMPORTANT:

Modified: branches/gsoc09-gui/MacPorts_Framework/MPInterpreter.m
===================================================================
--- branches/gsoc09-gui/MacPorts_Framework/MPInterpreter.m	2009-08-12 03:53:35 UTC (rev 55487)
+++ branches/gsoc09-gui/MacPorts_Framework/MPInterpreter.m	2009-08-12 04:40:26 UTC (rev 55488)
@@ -34,6 +34,7 @@
  */
 
 #import "MPInterpreter.h"
+#import "MPMacPorts.h"
 #include "BetterAuthorizationSampleLib.h"
 #include "MPHelperCommon.h"
 #include "MPHelperNotificationsProtocol.h"
@@ -455,25 +456,18 @@
 - (NSString *)evaluateStringWithPossiblePrivileges:(NSString *)statement error:(NSError **)mportError {
 	//N.B. I am going to insist that funciton users not pass in nil for the
 	//mportError parameter
-	NSString * firstResult;
-	NSString * secondResult;
+	NSString * result;
 	
-	*mportError = nil;
-   	firstResult = [self evaluateStringWithMPPortProcess:statement error:mportError];
-    
-	//Because of string results of methods like mportsync (which returns the empty string)
-	//the only way to truly check for an error is to check the mportError parameter.
-	//If it is nil then there was no error, if not we re-evaluate with privileges using
-	//the helper tool
+    // Is this the best way to know if the running user can use macports without privileges?
+    if ([[NSFileManager defaultManager] isWritableFileAtPath:PKGPath]) {
+        [[MPMacPorts sharedInstance] setAuthorizationMode:NO];
+        result = [self evaluateStringWithMPPortProcess:statement error:mportError];
+    } else {
+        [[MPMacPorts sharedInstance] setAuthorizationMode:YES];
+        result = [self evaluateStringWithMPHelperTool:statement error:mportError];
+    }
 	
-	if ( *mportError != nil) {
-		*mportError = nil; 
-		secondResult = [self evaluateStringWithMPHelperTool:statement error:mportError];
-		
-		return secondResult;
-	}
-	
-	return firstResult;
+	return result;
 }
 
 //NOTE: We expect the Framework client to initialize the AuthorizationRef
@@ -595,38 +589,10 @@
 		//Making the following assumption in error handling. If we return
 		//a noErr then response dictionary cannot be nil since everything went ok. 
 		//Hence I'm only checking for errors WITHIN the following blocks ...
-		if (err == noErr) {
-			err = BASExecuteRequestInHelperTool(internalMacPortsAuthRef, 
-												kMPHelperCommandSet, 
-												(CFStringRef) bundleID, 
-												(CFDictionaryRef) request, 
-												&response);
-			if (err == noErr){// retrieve result here if available
-				if( response != NULL)
-					result = (NSString *) (CFStringRef) CFDictionaryGetValue(response, CFSTR(kTclStringEvaluationResult));
-			}
-			else { //If we executed unsuccessfully
-				if (mportError != NULL) {
-					NSError * undError = [[[NSError alloc] initWithDomain:NSOSStatusErrorDomain 
-																	 code:err 
-																 userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
-																		   NSLocalizedString(@"Check error code for OSStatus returned",@""), 
-																		   NSLocalizedDescriptionKey,
-																		   nil]] autorelease];
-					
-					*mportError = [[[NSError alloc] initWithDomain:MPFrameworkErrorDomain 
-															  code:MPHELPINSTFAILED 
-														  userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
-																	NSLocalizedString(@"Unable to execute MPHelperTool successfuly", @""), 
-																	NSLocalizedDescriptionKey,
-																	undError, NSUnderlyingErrorKey,
-																	NSLocalizedString(@"BASExecuteRequestInHelperTool execution failed", @""),
-																	NSLocalizedFailureReasonErrorKey,
-																	nil]] autorelease];
-				}
-			}
-		}
-		else {//This means FixFaliure failed ... Report that in returned error
+        //
+        // NOTE: We don't automatically retry as the user wants to have a consistent cancel 
+        //      action (i.e. terminate the process when he wants to)
+		if (err != noErr) {//This means FixFaliure failed ... Report that in returned error
 			if (mportError != NULL) {
 				//I'm not sure of exactly how to report this error ... 
 				//Do we need some error codes for our domain? I'll define one
@@ -677,6 +643,14 @@
     [theProxy evaluateString:statement];
     [aTask waitUntilExit];
     
+    int status = [aTask terminationStatus];
+    
+    if (status == TCL_OK) {
+        NSLog(@"Task succeeded.");
+    } else {
+        NSLog(@"Task failed.%i", status);
+    }
+    
     return nil;
 }
 

Modified: branches/gsoc09-gui/MacPorts_Framework/MPMacPorts.h
===================================================================
--- branches/gsoc09-gui/MacPorts_Framework/MPMacPorts.h	2009-08-12 03:53:35 UTC (rev 55487)
+++ branches/gsoc09-gui/MacPorts_Framework/MPMacPorts.h	2009-08-12 04:40:26 UTC (rev 55488)
@@ -221,6 +221,7 @@
  */
 -(BOOL) authorizationMode;
 
+- (void) cancelCurrentCommand;
 
 //Notifications stuff for private use and testing purposes
 -(void)registerForLocalNotifications;

Modified: branches/gsoc09-gui/MacPorts_Framework/MPMacPorts.m
===================================================================
--- branches/gsoc09-gui/MacPorts_Framework/MPMacPorts.m	2009-08-12 03:53:35 UTC (rev 55487)
+++ branches/gsoc09-gui/MacPorts_Framework/MPMacPorts.m	2009-08-12 04:40:26 UTC (rev 55488)
@@ -60,8 +60,14 @@
 }
 
 - (void) cancelCurrentCommand {
-    //[[MPNotifications sharedListener] cancel];
-    [MPInterpreter terminateMPHelperTool];
+    if (authorizationMode) {
+        [MPInterpreter terminateMPHelperTool];
+    } else {
+        NSTask *task = [MPInterpreter task];
+        if(task != nil && [task isRunning]) {
+            [task terminate];
+        }
+    }
 }
 
 + (MPMacPorts *)sharedInstance {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20090811/0e214976/attachment.html>


More information about the macports-changes mailing list