Skip to content

Commit

Permalink
More cosmetics
Browse files Browse the repository at this point in the history
  • Loading branch information
hschmidt committed Jan 8, 2017
1 parent fa9a204 commit 210d351
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions EnvAgent/EnvAgent.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ int main( int argc, const char **argv )

NSError *error = nil;
NSFileManager *fileManager = [NSFileManager defaultManager];

/*
* Read current agent configuration.
*/
Expand All @@ -41,25 +40,21 @@ int main( int argc, const char **argv )
NSLog( @"Can't find current user's library directory: %@", error );
return 1;
};

NSURL *agentConfsUrl = [libraryUrl URLByAppendingPathComponent: @"LaunchAgents"
isDirectory: YES];

NSString *agentConfName = [agentLabel stringByAppendingString: @".plist"];

NSURL *agentConfUrl = [agentConfsUrl URLByAppendingPathComponent: agentConfName];

NSDictionary *curAgentConf = [NSDictionary dictionaryWithContentsOfURL: agentConfUrl];

/*
* As per convention, the path to the preference pane is the first entry in
* WatchPaths. Normally, the preference pane bundle still exists and we
* simply export the environment. Otherwise, we uninstall the agent by
* removing the files created outside the bundle during installation.
* As per convention, the path to the preference pane is the first entry in WatchPaths.
* Normally, the preference pane bundle still exists and we simply export the environment.
* Otherwise, we uninstall the agent by removing the files created outside the bundle during
* installation.
*/
NSString *envPanePath = curAgentConf[ @"WatchPaths" ][ 0 ];
BOOL isDir;
if( [fileManager fileExistsAtPath: envPanePath isDirectory: &isDir] && isDir ) {
if( [fileManager fileExistsAtPath: envPanePath
isDirectory: &isDir] && isDir ) {
NSLog( @"Setting environment" );
Environment *environment = [Environment loadPlist];
[environment export];
Expand All @@ -82,14 +77,14 @@ int main( int argc, const char **argv )
* ... and its parent directory.
*/
NSString *envAgentAppSupport = [agentExecutablePath stringByDeletingLastPathComponent];
if( ![fileManager removeItemAtPath: envAgentAppSupport error: &error] ) {
if( ![fileManager removeItemAtPath: envAgentAppSupport
error: &error] ) {
NSLog( @"Failed to remove agent configuration (%@): %@", agentConfUrl, error );
}
/*
* Remove the job from launchd. This seems to have the same effect as
* 'unload' except it doesn't cause the running instance of the agent to
* be terminated and it works without the presence of agent executable
* or plist.
* Remove the job from launchd. This seems to have the same effect as 'unload' except it
* doesn't cause the running instance of the agent to be terminated and it works without
* the presence of agent executable or plist.
*/
NSTask *task = [NSTask launchedTaskWithLaunchPath: launchctlPath
arguments: @[ @"remove", agentLabel ]];
Expand All @@ -105,3 +100,4 @@ int main( int argc, const char **argv )
NSLog( @"Exiting agent %s (PID %u)", argv[ 0 ], getpid() );
return 0;
}

0 comments on commit 210d351

Please sign in to comment.