Skip to content

Commit

Permalink
Fix to make working directory checks function on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
rfm committed Oct 11, 2023
1 parent f0f841c commit 921c131
Showing 1 changed file with 47 additions and 39 deletions.
86 changes: 47 additions & 39 deletions Source/NSTask.m
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,45 @@ + (NSTask *) launchedTaskWithExecutableURL: (NSURL *)url

- (BOOL) launchAndReturnError: (NSError **)error
{
NSFileManager *mgr = [NSFileManager defaultManager];
NSString *cwd;
BOOL ok;

ASSIGN(_launchingThread, [NSThread currentThread]);

cwd = [self currentDirectoryPath];
if (NO == [mgr fileExistsAtPath: cwd isDirectory: &ok])
{
if (error)
{
NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:
@"does not exist", NSLocalizedDescriptionKey,
cwd, NSFilePathErrorKey,
nil];
*error = [NSError errorWithDomain: NSCocoaErrorDomain
code: NSFileNoSuchFileError
userInfo: info];
}
return NO;
}
if (NO == ok)
{
if (error)
{
*error = [NSError _systemError: ENOTDIR];
[*error _setObject: cwd forKey: NSFilePathErrorKey];
}
return NO;
}
if (NO == [mgr isExecutableFileAtPath: cwd])
{
if (error)
{
*error = [NSError _systemError: EACCES];
[*error _setObject: cwd forKey: NSFilePathErrorKey];
}
return NO;
}
return YES;
}

Expand Down Expand Up @@ -1217,7 +1255,10 @@ - (BOOL) launchAndReturnError: (NSError **)error
return NO;
}

[super launchAndReturnError: error];
if (NO == [super launchAndReturnError: error])
{
return NO;
}

lpath = [self _fullLaunchPath];
wexecutable = (const unichar*)[lpath fileSystemRepresentation];
Expand Down Expand Up @@ -1528,12 +1569,9 @@ @implementation NSConcreteUnixTask
// 10.13 method...
- (BOOL) launchAndReturnError: (NSError **)error
{
NSFileManager *mgr = [NSFileManager defaultManager];
NSDictionary *info;
NSMutableArray *toClose;
NSString *lpath;
NSString *cwd;
BOOL ok;
int pid;
const char *executable;
const char *path;
Expand Down Expand Up @@ -1563,7 +1601,10 @@ - (BOOL) launchAndReturnError: (NSError **)error
return NO;
}

[super launchAndReturnError: error];
if (NO == [super launchAndReturnError: error])
{
return NO;
}

lpath = [self _fullLaunchPath];
executable = [lpath fileSystemRepresentation];
Expand Down Expand Up @@ -1593,40 +1634,7 @@ - (BOOL) launchAndReturnError: (NSError **)error
}
envl[ec] = 0;

cwd = [self currentDirectoryPath];
if (NO == [mgr fileExistsAtPath: cwd isDirectory: &ok])
{
if (error)
{
info = [NSDictionary dictionaryWithObjectsAndKeys:
@"does not exist", NSLocalizedDescriptionKey,
cwd, NSFilePathErrorKey,
nil];
*error = [NSError errorWithDomain: NSCocoaErrorDomain
code: NSFileNoSuchFileError
userInfo: info];
}
return NO;
}
if (NO == ok)
{
if (error)
{
*error = [NSError _systemError: ENOTDIR];
[*error _setObject: cwd forKey: NSFilePathErrorKey];
}
return NO;
}
if (NO == [mgr isExecutableFileAtPath: cwd])
{
if (error)
{
*error = [NSError _systemError: EACCES];
[*error _setObject: cwd forKey: NSFilePathErrorKey];
}
return NO;
}
path = [cwd fileSystemRepresentation];
path = [[self currentDirectoryPath] fileSystemRepresentation];

toClose = [NSMutableArray arrayWithCapacity: 3];
hdl = [self standardInput];
Expand Down

0 comments on commit 921c131

Please sign in to comment.