mirror of
https://github.com/gnustep/libs-base.git
synced 2025-06-04 10:30:47 +00:00
fix for bug #35672
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@35392 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
447db36958
commit
dc55974ec8
2 changed files with 82 additions and 50 deletions
|
@ -1,3 +1,12 @@
|
||||||
|
2012-08-10 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* Source/NSFileManager.m: ([-createDirectoryAtPath:attributes:])
|
||||||
|
OSX compatibility change to no longer create intermediate directories
|
||||||
|
(fixing bug #35672).
|
||||||
|
NB. Code depending on the original incorrect behavior should be
|
||||||
|
updated to use the new method:
|
||||||
|
-createDirectoryAtPath:withIntermediateDirectories:attributes:error:
|
||||||
|
|
||||||
2012-08-10 Richard Frith-Macdonald <rfm@gnu.org>
|
2012-08-10 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/NSSpellServer.m:
|
* Source/NSSpellServer.m:
|
||||||
|
|
|
@ -783,8 +783,8 @@ static NSStringEncoding defaultEncoding;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new directory, and sets its attributes as specified.<br />
|
* Creates a new directory, and sets its attributes as specified.<br />
|
||||||
* Creates other directories in the path as necessary.<br />
|
* Fails if directories in the path are missing.<br />
|
||||||
* Returns YES on success, NO on failure.
|
* Returns YES if the directory was created (or already exists), NO otherwise.
|
||||||
*/
|
*/
|
||||||
- (BOOL) createDirectoryAtPath: (NSString*)path
|
- (BOOL) createDirectoryAtPath: (NSString*)path
|
||||||
attributes: (NSDictionary*)attributes
|
attributes: (NSDictionary*)attributes
|
||||||
|
@ -821,22 +821,38 @@ static NSStringEncoding defaultEncoding;
|
||||||
if ([self fileExistsAtPath: completePath isDirectory: &isDir])
|
if ([self fileExistsAtPath: completePath isDirectory: &isDir])
|
||||||
{
|
{
|
||||||
if (!isDir)
|
if (!isDir)
|
||||||
NSLog(@"WARNING: during creation of directory %@:"
|
{
|
||||||
@" sub path %@ exists, but is not a directory !",
|
NSString *e;
|
||||||
path, completePath);
|
|
||||||
|
e = [NSString stringWithFormat:
|
||||||
|
@"path %@ exists, but is not a directory", completePath];
|
||||||
|
ASSIGN(_lastError, e);
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const _CHAR *lpath;
|
if (nil == [paths nextObject])
|
||||||
|
{
|
||||||
|
const _CHAR *lpath;
|
||||||
|
|
||||||
|
lpath = [self fileSystemRepresentationWithPath: completePath];
|
||||||
|
if (CreateDirectoryW(lpath, 0) == FALSE)
|
||||||
|
{
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NSString *e;
|
||||||
|
|
||||||
lpath = [self fileSystemRepresentationWithPath: completePath];
|
e = [NSString stringWithFormat:
|
||||||
if (CreateDirectoryW(lpath, 0) == FALSE)
|
@"path %@ is not accessible", completePath];
|
||||||
{
|
ASSIGN(_lastError, e);
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -885,46 +901,53 @@ static NSStringEncoding defaultEncoding;
|
||||||
}
|
}
|
||||||
// check if path from 0 to cur is valid
|
// check if path from 0 to cur is valid
|
||||||
dirpath[cur] = '\0';
|
dirpath[cur] = '\0';
|
||||||
if (_STAT(dirpath, &statbuf) == 0)
|
if (_STAT(dirpath, &statbuf) != 0)
|
||||||
{
|
{
|
||||||
if (cur == len)
|
NSString *p;
|
||||||
{
|
|
||||||
ASSIGN(_lastError,
|
|
||||||
@"Could not create directory - already exists");
|
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// make new directory
|
|
||||||
if (mkdir(dirpath, 0777) != 0)
|
|
||||||
{
|
|
||||||
NSString *s;
|
|
||||||
|
|
||||||
s = [NSString stringWithFormat: @"Could not create '%s' - '%@'",
|
p = [self stringWithFileSystemRepresentation: dirpath length: cur];
|
||||||
dirpath, [NSError _last]];
|
|
||||||
ASSIGN(_lastError, s);
|
if (cur != len)
|
||||||
return NO;
|
{
|
||||||
}
|
NSString *e;
|
||||||
// if last directory and attributes then change
|
|
||||||
if (cur == len && attributes != nil)
|
e = [NSString stringWithFormat: @"path %@ is not accessible", p];
|
||||||
{
|
ASSIGN(_lastError, e);
|
||||||
if ([self changeFileAttributes: attributes
|
return NO;
|
||||||
atPath: [self stringWithFileSystemRepresentation: dirpath
|
}
|
||||||
length: cur]] == NO)
|
else
|
||||||
return NO;
|
{
|
||||||
if (needChown != nil)
|
// make new directory
|
||||||
{
|
if (mkdir(dirpath, 0777) != 0)
|
||||||
if ([self changeFileAttributes: needChown
|
{
|
||||||
atPath: [self stringWithFileSystemRepresentation: dirpath
|
NSString *e;
|
||||||
length: cur]] == NO)
|
|
||||||
{
|
e = [NSString stringWithFormat:
|
||||||
NSLog(@"Failed to change ownership of '%s' to '%@'",
|
@"Could not create '%@' - '%@'",
|
||||||
dirpath, NSUserName());
|
p, [NSError _last]];
|
||||||
}
|
ASSIGN(_lastError, e);
|
||||||
}
|
return NO;
|
||||||
return YES;
|
}
|
||||||
}
|
// if last directory and attributes then change
|
||||||
|
if (attributes != nil)
|
||||||
|
{
|
||||||
|
if ([self changeFileAttributes: attributes
|
||||||
|
atPath: p] == NO)
|
||||||
|
{
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
if (needChown != nil)
|
||||||
|
{
|
||||||
|
if ([self changeFileAttributes: needChown
|
||||||
|
atPath: p] == NO)
|
||||||
|
{
|
||||||
|
NSLog(@"Failed to change ownership of '%p' to '%@'",
|
||||||
|
p, NSUserName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dirpath[cur] = '/';
|
dirpath[cur] = '/';
|
||||||
cur++;
|
cur++;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue