mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +00:00
Expand '~' abbreviations in localFromOpenStepPath: and change lines modified
by last windows patch to conform to coding standards. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@20646 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
e1b944688b
commit
e22f1c0d4f
2 changed files with 927 additions and 829 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
2005-02-02 09:40 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* Source/NSFileManager.m: Restructure last patch to conform to
|
||||||
|
gnustep coding standards.
|
||||||
|
(localFromOpenStepPath:) for unix paths, expand '~' abbreviations.
|
||||||
|
|
||||||
2005-01-31 Adam Fedor <fedor@gnu.org>
|
2005-01-31 Adam Fedor <fedor@gnu.org>
|
||||||
|
|
||||||
* Documentation/coding-standards.texi: Add section of documentation.
|
* Documentation/coding-standards.texi: Add section of documentation.
|
||||||
|
|
|
@ -310,9 +310,9 @@ static NSFileManager* defaultManager = nil;
|
||||||
- (BOOL) changeFileAttributes: (NSDictionary*)attributes atPath: (NSString*)path
|
- (BOOL) changeFileAttributes: (NSDictionary*)attributes atPath: (NSString*)path
|
||||||
{
|
{
|
||||||
#ifdef __MINGW__
|
#ifdef __MINGW__
|
||||||
const unichar *wpath = NULL;
|
const unichar *wpath = 0;
|
||||||
#else
|
#else
|
||||||
const char *cpath = NULL;
|
const char *cpath = 0;
|
||||||
#endif
|
#endif
|
||||||
unsigned long num;
|
unsigned long num;
|
||||||
NSString *str;
|
NSString *str;
|
||||||
|
@ -596,7 +596,7 @@ static NSFileManager* defaultManager = nil;
|
||||||
NSDictionary *needChown = nil;
|
NSDictionary *needChown = nil;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* This is consitent with MacOSX - just return NO for an invalid path. */
|
/* This is consistent with MacOSX - just return NO for an invalid path. */
|
||||||
if ([path length] == 0)
|
if ([path length] == 0)
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
|
@ -619,8 +619,9 @@ static NSFileManager* defaultManager = nil;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const unichar *wpath;
|
const unichar *wpath;
|
||||||
|
|
||||||
wpath = [[self localFromOpenStepPath: completePath] unicharString];
|
wpath = [[self localFromOpenStepPath: completePath] unicharString];
|
||||||
if (CreateDirectory(wpath, NULL) == FALSE)
|
if (CreateDirectory(wpath, 0) == FALSE)
|
||||||
{
|
{
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
@ -766,7 +767,7 @@ static NSFileManager* defaultManager = nil;
|
||||||
{
|
{
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
{
|
{
|
||||||
WriteFile(fh, [contents bytes], len, &written, NULL);
|
WriteFile(fh, [contents bytes], len, &written, 0);
|
||||||
}
|
}
|
||||||
CloseHandle(fh);
|
CloseHandle(fh);
|
||||||
if (attributes != nil
|
if (attributes != nil
|
||||||
|
@ -832,24 +833,28 @@ static NSFileManager* defaultManager = nil;
|
||||||
NSString *currentDir = nil;
|
NSString *currentDir = nil;
|
||||||
|
|
||||||
#if defined(__MINGW__)
|
#if defined(__MINGW__)
|
||||||
int len = GetCurrentDirectory(0, NULL);
|
int len = GetCurrentDirectory(0, 0);
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
{
|
{
|
||||||
unichar *wpath = (unichar*)calloc(len+10,sizeof(unichar));
|
unichar *wpath = (unichar*)calloc(len+10,sizeof(unichar));
|
||||||
if (wpath != NULL)
|
|
||||||
|
if (wpath != 0)
|
||||||
{
|
{
|
||||||
if (GetCurrentDirectory(len, wpath)>0)
|
if (GetCurrentDirectory(len, wpath)>0)
|
||||||
currentDir = [self openStepPathFromLocal:[NSString stringWithCharacters: wpath length: len]];
|
{
|
||||||
|
currentDilr = [self openStepPathFromLocal:
|
||||||
|
[NSString stringWithCharacters: wpath length: len]];
|
||||||
|
}
|
||||||
free(wpath);
|
free(wpath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
#ifdef HAVE_GETCWD
|
#ifdef HAVE_GETCWD
|
||||||
if (getcwd(path, PATH_MAX-1) == NULL)
|
if (getcwd(path, PATH_MAX-1) == 0)
|
||||||
return nil;
|
return nil;
|
||||||
#else
|
#else
|
||||||
if (getwd(path) == NULL)
|
if (getwd(path) == 0)
|
||||||
return nil;
|
return nil;
|
||||||
#endif /* HAVE_GETCWD */
|
#endif /* HAVE_GETCWD */
|
||||||
currentDir = [self stringWithFileSystemRepresentation: path length: strlen(path)];
|
currentDir = [self stringWithFileSystemRepresentation: path length: strlen(path)];
|
||||||
|
@ -955,16 +960,24 @@ static NSFileManager* defaultManager = nil;
|
||||||
toPath: (NSString*)destination
|
toPath: (NSString*)destination
|
||||||
handler: (id)handler
|
handler: (id)handler
|
||||||
{
|
{
|
||||||
BOOL sourceIsDir, fileExists;
|
BOOL sourceIsDir;
|
||||||
#if defined(__MINGW__)
|
BOOL fileExists;
|
||||||
const unichar* sourcePath = [[self localFromOpenStepPath: source] unicharString];
|
|
||||||
const unichar* destPath = [[self localFromOpenStepPath: destination] unicharString];
|
|
||||||
#else
|
|
||||||
const char* sourcePath = [self fileSystemRepresentationWithPath: source];
|
|
||||||
const char* destPath = [self fileSystemRepresentationWithPath: destination];
|
|
||||||
#endif
|
|
||||||
NSString *destinationParent;
|
NSString *destinationParent;
|
||||||
unsigned int sourceDevice, destinationDevice;
|
unsigned int sourceDevice;
|
||||||
|
unsigned int destinationDevice;
|
||||||
|
#if defined(__MINGW__)
|
||||||
|
const unichar *sourcePath;
|
||||||
|
const unichar *destPath;
|
||||||
|
|
||||||
|
sourcePath = [[self localFromOpenStepPath: source] unicharString];
|
||||||
|
destPath = [[self localFromOpenStepPath: destination] unicharString];
|
||||||
|
#else
|
||||||
|
const char *sourcePath;
|
||||||
|
const char *destPath;
|
||||||
|
|
||||||
|
sourcePath = [self fileSystemRepresentationWithPath: source];
|
||||||
|
destPath = [self fileSystemRepresentationWithPath: destination];
|
||||||
|
#endif
|
||||||
|
|
||||||
if ([self fileExistsAtPath: destination] == YES)
|
if ([self fileExistsAtPath: destination] == YES)
|
||||||
{
|
{
|
||||||
|
@ -991,7 +1004,9 @@ static NSFileManager* defaultManager = nil;
|
||||||
isn't possible. */
|
isn't possible. */
|
||||||
if (sourceIsDir && [[destination stringByAppendingString: @"/"]
|
if (sourceIsDir && [[destination stringByAppendingString: @"/"]
|
||||||
hasPrefix: [source stringByAppendingString: @"/"]])
|
hasPrefix: [source stringByAppendingString: @"/"]])
|
||||||
|
{
|
||||||
return NO;
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
if ([self copyPath: source toPath: destination handler: handler])
|
if ([self copyPath: source toPath: destination handler: handler])
|
||||||
{
|
{
|
||||||
|
@ -1003,8 +1018,10 @@ static NSFileManager* defaultManager = nil;
|
||||||
return [self removeFileAtPath: source handler: handler];
|
return [self removeFileAtPath: source handler: handler];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* source and destination are on the same device so we can simply
|
/* source and destination are on the same device so we can simply
|
||||||
|
@ -1260,7 +1277,7 @@ static NSFileManager* defaultManager = nil;
|
||||||
*/
|
*/
|
||||||
- (BOOL) fileExistsAtPath: (NSString*)path
|
- (BOOL) fileExistsAtPath: (NSString*)path
|
||||||
{
|
{
|
||||||
return [self fileExistsAtPath: path isDirectory: NULL];
|
return [self fileExistsAtPath: path isDirectory: 0];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1280,21 +1297,29 @@ static NSFileManager* defaultManager = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wpath == 0 || *wpath == L'\0')
|
if (wpath == 0 || *wpath == L'\0')
|
||||||
|
{
|
||||||
return NO;
|
return NO;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DWORD res;
|
DWORD res;
|
||||||
|
|
||||||
res = GetFileAttributes(wpath);
|
res = GetFileAttributes(wpath);
|
||||||
if (res == WIN32ERR)
|
if (res == WIN32ERR)
|
||||||
|
{
|
||||||
return NO;
|
return NO;
|
||||||
|
}
|
||||||
if (isDirectory != 0)
|
if (isDirectory != 0)
|
||||||
{
|
{
|
||||||
if (res & FILE_ATTRIBUTE_DIRECTORY)
|
if (res & FILE_ATTRIBUTE_DIRECTORY)
|
||||||
|
{
|
||||||
*isDirectory = YES;
|
*isDirectory = YES;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
*isDirectory = NO;
|
*isDirectory = NO;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -1314,7 +1339,9 @@ static NSFileManager* defaultManager = nil;
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
|
|
||||||
if (stat(cpath, &statbuf) != 0)
|
if (stat(cpath, &statbuf) != 0)
|
||||||
|
{
|
||||||
return NO;
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
if (isDirectory)
|
if (isDirectory)
|
||||||
{
|
{
|
||||||
|
@ -1336,14 +1363,17 @@ static NSFileManager* defaultManager = nil;
|
||||||
const unichar* wpath = [[self localFromOpenStepPath: path] unicharString];
|
const unichar* wpath = [[self localFromOpenStepPath: path] unicharString];
|
||||||
|
|
||||||
if (wpath == 0 || *wpath == L'\0')
|
if (wpath == 0 || *wpath == L'\0')
|
||||||
|
{
|
||||||
return NO;
|
return NO;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DWORD res= GetFileAttributes(wpath);
|
DWORD res= GetFileAttributes(wpath);
|
||||||
|
|
||||||
if (res == WIN32ERR)
|
if (res == WIN32ERR)
|
||||||
|
{
|
||||||
return NO;
|
return NO;
|
||||||
|
}
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -1370,14 +1400,17 @@ static NSFileManager* defaultManager = nil;
|
||||||
const unichar* wpath = [[self localFromOpenStepPath: path] unicharString];
|
const unichar* wpath = [[self localFromOpenStepPath: path] unicharString];
|
||||||
|
|
||||||
if (wpath == 0 || *wpath == L'\0')
|
if (wpath == 0 || *wpath == L'\0')
|
||||||
|
{
|
||||||
return NO;
|
return NO;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DWORD res= GetFileAttributes(wpath);
|
DWORD res= GetFileAttributes(wpath);
|
||||||
|
|
||||||
if (res == WIN32ERR)
|
if (res == WIN32ERR)
|
||||||
|
{
|
||||||
return NO;
|
return NO;
|
||||||
|
}
|
||||||
return (res & FILE_ATTRIBUTE_READONLY) ? NO : YES;
|
return (res & FILE_ATTRIBUTE_READONLY) ? NO : YES;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -1405,27 +1438,36 @@ static NSFileManager* defaultManager = nil;
|
||||||
const unichar* wpath = [[self localFromOpenStepPath: path] unicharString];
|
const unichar* wpath = [[self localFromOpenStepPath: path] unicharString];
|
||||||
|
|
||||||
if (wpath == 0 || *wpath == L'\0')
|
if (wpath == 0 || *wpath == L'\0')
|
||||||
|
{
|
||||||
return NO;
|
return NO;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DWORD res= GetFileAttributes(wpath);
|
DWORD res= GetFileAttributes(wpath);
|
||||||
|
|
||||||
if (res == WIN32ERR)
|
if (res == WIN32ERR)
|
||||||
|
{
|
||||||
return NO;
|
return NO;
|
||||||
|
}
|
||||||
if ([[[path pathExtension] lowercaseString] isEqualToString: @"exe"])
|
if ([[[path pathExtension] lowercaseString] isEqualToString: @"exe"])
|
||||||
|
{
|
||||||
return YES;
|
return YES;
|
||||||
|
}
|
||||||
/* FIXME: On unix, directory accessable == executable, so we simulate that
|
/* FIXME: On unix, directory accessable == executable, so we simulate that
|
||||||
here for Windows. Is there a better check for directory access? */
|
here for Windows. Is there a better check for directory access? */
|
||||||
if (res & FILE_ATTRIBUTE_DIRECTORY)
|
if (res & FILE_ATTRIBUTE_DIRECTORY)
|
||||||
|
{
|
||||||
return YES;
|
return YES;
|
||||||
|
}
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
const char* cpath = [self fileSystemRepresentationWithPath: path];
|
const char* cpath = [self fileSystemRepresentationWithPath: path];
|
||||||
|
|
||||||
if (cpath == 0 || *cpath == '\0')
|
if (cpath == 0 || *cpath == '\0')
|
||||||
|
{
|
||||||
return NO;
|
return NO;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return (access(cpath, X_OK) == 0);
|
return (access(cpath, X_OK) == 0);
|
||||||
|
@ -1443,15 +1485,18 @@ static NSFileManager* defaultManager = nil;
|
||||||
const unichar* wpath = [[self localFromOpenStepPath: path] unicharString];
|
const unichar* wpath = [[self localFromOpenStepPath: path] unicharString];
|
||||||
|
|
||||||
if (wpath == 0 || *wpath == L'\0')
|
if (wpath == 0 || *wpath == L'\0')
|
||||||
|
{
|
||||||
return NO;
|
return NO;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// TODO - handle directories
|
// TODO - handle directories
|
||||||
DWORD res= GetFileAttributes(wpath);
|
DWORD res= GetFileAttributes(wpath);
|
||||||
|
|
||||||
if (res == WIN32ERR)
|
if (res == WIN32ERR)
|
||||||
|
{
|
||||||
return NO;
|
return NO;
|
||||||
|
}
|
||||||
return (res & FILE_ATTRIBUTE_READONLY) ? NO : YES;
|
return (res & FILE_ATTRIBUTE_READONLY) ? NO : YES;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -1599,7 +1644,9 @@ static NSFileManager* defaultManager = nil;
|
||||||
|
|
||||||
if (!GetDiskFreeSpace(wpath, &SectorsPerCluster,
|
if (!GetDiskFreeSpace(wpath, &SectorsPerCluster,
|
||||||
&BytesPerSector, &NumberFreeClusters, &TotalNumberClusters))
|
&BytesPerSector, &NumberFreeClusters, &TotalNumberClusters))
|
||||||
|
{
|
||||||
return nil;
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
totalsize = (unsigned long long)TotalNumberClusters
|
totalsize = (unsigned long long)TotalNumberClusters
|
||||||
* (unsigned long long)SectorsPerCluster
|
* (unsigned long long)SectorsPerCluster
|
||||||
|
@ -1638,14 +1685,19 @@ static NSFileManager* defaultManager = nil;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (stat(cpath, &statbuf) != 0)
|
if (stat(cpath, &statbuf) != 0)
|
||||||
|
{
|
||||||
return nil;
|
return nil;
|
||||||
|
}
|
||||||
#ifdef HAVE_STATVFS
|
#ifdef HAVE_STATVFS
|
||||||
if (statvfs(cpath, &statfsbuf) != 0)
|
if (statvfs(cpath, &statfsbuf) != 0)
|
||||||
|
{
|
||||||
return nil;
|
return nil;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
if (statfs(cpath, &statfsbuf) != 0)
|
if (statfs(cpath, &statfsbuf) != 0)
|
||||||
|
{
|
||||||
return nil;
|
return nil;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
totalsize = (unsigned long long) statfsbuf.f_bsize
|
totalsize = (unsigned long long) statfsbuf.f_bsize
|
||||||
|
@ -1830,12 +1882,15 @@ static NSFileManager* defaultManager = nil;
|
||||||
*/
|
*/
|
||||||
- (const char*) fileSystemRepresentationWithPath: (NSString*)path
|
- (const char*) fileSystemRepresentationWithPath: (NSString*)path
|
||||||
{
|
{
|
||||||
NSString *localPath = [self localFromOpenStepPath:path];
|
NSString *localPath;
|
||||||
const char *local_c_path = NULL;
|
const char *local_c_path = 0;
|
||||||
|
|
||||||
if (localPath && [localPath canBeConvertedToEncoding: [NSString defaultCStringEncoding]])
|
localPath = [self localFromOpenStepPath: path];
|
||||||
|
if (localPath
|
||||||
|
&& [localPath canBeConvertedToEncoding: [NSString defaultCStringEncoding]])
|
||||||
|
{
|
||||||
local_c_path = [localPath cString];
|
local_c_path = [localPath cString];
|
||||||
|
}
|
||||||
return (local_c_path);
|
return (local_c_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1858,7 +1913,7 @@ static NSFileManager* defaultManager = nil;
|
||||||
* can handle it
|
* can handle it
|
||||||
*/
|
*/
|
||||||
int wcount; // count unichars
|
int wcount; // count unichars
|
||||||
unichar *wc_path = NULL;
|
unichar *wc_path = 0;
|
||||||
int l;
|
int l;
|
||||||
|
|
||||||
path = [path stringByStandardizingPath];
|
path = [path stringByStandardizingPath];
|
||||||
|
@ -1883,14 +1938,16 @@ static NSFileManager* defaultManager = nil;
|
||||||
wc_path[1] = L':';
|
wc_path[1] = L':';
|
||||||
newpath = [NSString stringWithCharacters: wc_path length: wcount];
|
newpath = [NSString stringWithCharacters: wc_path length: wcount];
|
||||||
}
|
}
|
||||||
else if (l >= 3 && wc_path[0] == L'/' && wc_path[1] == L'/' && iswalpha(wc_path[2]))
|
else if (l >= 3 && wc_path[0] == L'/' && wc_path[1] == L'/'
|
||||||
|
&& iswalpha(wc_path[2]))
|
||||||
{
|
{
|
||||||
if (l == 3 || wc_path[3] == L'/')
|
if (l == 3 || wc_path[3] == L'/')
|
||||||
{
|
{
|
||||||
/* Cygwin "//c/" type absolute path */
|
/* Cygwin "//c/" type absolute path */
|
||||||
wc_path[1] = wc_path[2];
|
wc_path[1] = wc_path[2];
|
||||||
wc_path[2] = L':';
|
wc_path[2] = L':';
|
||||||
newpath = [NSString stringWithCharacters:&wc_path[1] length:wcount-1];
|
newpath = [NSString stringWithCharacters: &wc_path[1]
|
||||||
|
length: wcount-1];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1906,11 +1963,13 @@ static NSFileManager* defaultManager = nil;
|
||||||
else if (wc_path[0] == L'/')
|
else if (wc_path[0] == L'/')
|
||||||
{
|
{
|
||||||
#ifdef __CYGWIN__
|
#ifdef __CYGWIN__
|
||||||
if (l > 11 && wcsncmp(wc_path, L"/cygdrive/", 10) == 0 && wc_path[11] == L'/')
|
if (l > 11 && wcsncmp(wc_path, L"/cygdrive/", 10) == 0
|
||||||
|
&& wc_path[11] == L'/')
|
||||||
{
|
{
|
||||||
wc_path[9] = wc_path[10];
|
wc_path[9] = wc_path[10];
|
||||||
wc_path[10] = L':';
|
wc_path[10] = L':';
|
||||||
newpath = [NSString stringWithCharacters:&wc_path[9] length:wcount-9];
|
newpath = [NSString stringWithCharacters: &wc_path[9]
|
||||||
|
length: wcount-9];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1936,7 +1995,8 @@ static NSFileManager* defaultManager = nil;
|
||||||
{
|
{
|
||||||
/* Mingw /drive/... format */
|
/* Mingw /drive/... format */
|
||||||
wc_path[2] = L':';
|
wc_path[2] = L':';
|
||||||
newpath = [NSString stringWithCharacters:&wc_path[1] length:wcount-1];
|
newpath = [NSString stringWithCharacters: &wc_path[1]
|
||||||
|
length: wcount-1];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1950,17 +2010,23 @@ static NSFileManager* defaultManager = nil;
|
||||||
}
|
}
|
||||||
newpath = [newpath stringByReplacingString: @"/" withString: @"\\"];
|
newpath = [newpath stringByReplacingString: @"/" withString: @"\\"];
|
||||||
if (wc_path)
|
if (wc_path)
|
||||||
|
{
|
||||||
free (wc_path);
|
free (wc_path);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
newpath = path;
|
newpath = path;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
/*
|
/*
|
||||||
* NB ... Don't standardize path, since that would automatically
|
* NB ... Don't standardize path, since that would automatically
|
||||||
* follow symbolic links ... and mess up any code wishing to
|
* follow symbolic links ... and mess up any code wishing to
|
||||||
* examine the link itsself.
|
* examine the link itsself.
|
||||||
|
* We just need the path in a form where it can be interpreted by
|
||||||
|
* operating system calls (no '~' abbreviations for user directories).
|
||||||
*/
|
*/
|
||||||
newpath = path;
|
newpath = [path stringByExpandingTildeInPath];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return (newpath);
|
return (newpath);
|
||||||
|
@ -1979,8 +2045,10 @@ return (newpath);
|
||||||
{
|
{
|
||||||
NSString *localPath = nil;
|
NSString *localPath = nil;
|
||||||
|
|
||||||
if (string != NULL)
|
if (string != 0)
|
||||||
|
{
|
||||||
localPath = [NSString stringWithCString: string length: len];
|
localPath = [NSString stringWithCString: string length: len];
|
||||||
|
}
|
||||||
|
|
||||||
return([self openStepPathFromLocal: localPath]);
|
return([self openStepPathFromLocal: localPath]);
|
||||||
}
|
}
|
||||||
|
@ -1998,7 +2066,7 @@ return (newpath);
|
||||||
#ifdef __MINGW__
|
#ifdef __MINGW__
|
||||||
|
|
||||||
int len; // count unichars
|
int len; // count unichars
|
||||||
unichar *wc_path = NULL;
|
unichar *wc_path = 0;
|
||||||
|
|
||||||
len = [localPath length];
|
len = [localPath length];
|
||||||
if (len != 0)
|
if (len != 0)
|
||||||
|
@ -2022,7 +2090,8 @@ return (newpath);
|
||||||
free(wc_path);
|
free(wc_path);
|
||||||
return @"";
|
return @"";
|
||||||
}
|
}
|
||||||
if (len >= 2 && ((ptr[1] == L'/' && ptr[0] == L'/') || (ptr[1] == L'\\' && ptr[0] == L'\\')))
|
if (len >= 2 && ((ptr[1] == L'/' && ptr[0] == L'/')
|
||||||
|
|| (ptr[1] == L'\\' && ptr[0] == L'\\')))
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Convert '//<servername>/' to '~@<servername>/' sequences.
|
* Convert '//<servername>/' to '~@<servername>/' sequences.
|
||||||
|
@ -2099,7 +2168,9 @@ return (newpath);
|
||||||
return [NSString stringWithCharacters: buf length: j];
|
return [NSString stringWithCharacters: buf length: j];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
return(@"");
|
return(@"");
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return localPath;
|
return localPath;
|
||||||
|
@ -2130,7 +2201,7 @@ typedef struct _GSEnumeratedDirectory {
|
||||||
|
|
||||||
inline void gsedRelease(GSEnumeratedDirectory X)
|
inline void gsedRelease(GSEnumeratedDirectory X)
|
||||||
{
|
{
|
||||||
[X.path release];
|
DESTROY(X.path);
|
||||||
#ifdef __MINGW__
|
#ifdef __MINGW__
|
||||||
_wclosedir(X.pointer);
|
_wclosedir(X.pointer);
|
||||||
#else
|
#else
|
||||||
|
@ -2208,18 +2279,21 @@ static SEL ospfl = 0;
|
||||||
_flags.isRecursive = recurse;
|
_flags.isRecursive = recurse;
|
||||||
_flags.isFollowing = follow;
|
_flags.isFollowing = follow;
|
||||||
_flags.justContents = justContents;
|
_flags.justContents = justContents;
|
||||||
_topPath = [[NSString stringWithString:path] retain];
|
|
||||||
|
_topPath = [[NSString alloc] initWithString: path];
|
||||||
|
|
||||||
#ifdef __MINGW__
|
#ifdef __MINGW__
|
||||||
dir_pointer = _wopendir([[defaultManager localFromOpenStepPath: path] unicharString]);
|
dir_pointer
|
||||||
|
= _wopendir([[defaultManager localFromOpenStepPath: path] unicharString]);
|
||||||
#else
|
#else
|
||||||
dir_pointer = opendir([defaultManager fileSystemRepresentationWithPath:path]);
|
dir_pointer
|
||||||
|
= opendir([defaultManager fileSystemRepresentationWithPath: path]);
|
||||||
#endif
|
#endif
|
||||||
if (dir_pointer)
|
if (dir_pointer)
|
||||||
{
|
{
|
||||||
GSIArrayItem item;
|
GSIArrayItem item;
|
||||||
|
|
||||||
item.ext.path = [[NSString stringWithString:@""] retain];
|
item.ext.path = @"";
|
||||||
item.ext.pointer = dir_pointer;
|
item.ext.pointer = dir_pointer;
|
||||||
|
|
||||||
GSIArrayAddItem(_stack, item);
|
GSIArrayAddItem(_stack, item);
|
||||||
|
@ -2236,8 +2310,8 @@ static SEL ospfl = 0;
|
||||||
{
|
{
|
||||||
GSIArrayEmpty(_stack);
|
GSIArrayEmpty(_stack);
|
||||||
NSZoneFree([self zone], _stack);
|
NSZoneFree([self zone], _stack);
|
||||||
[_topPath release];
|
DESTROY(_topPath);
|
||||||
[_currentFilePath release];
|
DESTROY(_currentFilePath);
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2275,35 +2349,31 @@ static SEL ospfl = 0;
|
||||||
if (GSIArrayCount(_stack) > 0)
|
if (GSIArrayCount(_stack) > 0)
|
||||||
{
|
{
|
||||||
GSIArrayRemoveLastItem(_stack);
|
GSIArrayRemoveLastItem(_stack);
|
||||||
if (_currentFilePath != NULL)
|
if (_currentFilePath != 0)
|
||||||
{
|
{
|
||||||
[_currentFilePath release];
|
DESTROY(_currentFilePath);
|
||||||
_currentFilePath = NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enumerate next
|
/*
|
||||||
|
* finds the next file according to the top enumerator
|
||||||
|
* - if there is a next file it is put in currentFile
|
||||||
|
* - if the current file is a directory and if isRecursive calls
|
||||||
|
* recurseIntoDirectory: currentFile
|
||||||
|
* - if the current file is a symlink to a directory and if isRecursive
|
||||||
|
* and isFollowing calls recurseIntoDirectory: currentFile
|
||||||
|
* - if at end of current directory pops stack and attempts to
|
||||||
|
* find the next entry in the parent
|
||||||
|
* - sets currentFile to nil if there are no more files to enumerate
|
||||||
|
*/
|
||||||
- (id) nextObject
|
- (id) nextObject
|
||||||
{
|
{
|
||||||
/*
|
NSString *returnFileName = 0;
|
||||||
finds the next file according to the top enumerator
|
|
||||||
- if there is a next file it is put in currentFile
|
|
||||||
- if the current file is a directory and if isRecursive calls
|
|
||||||
recurseIntoDirectory: currentFile
|
|
||||||
- if the current file is a symlink to a directory and if isRecursive
|
|
||||||
and isFollowing calls recurseIntoDirectory: currentFile
|
|
||||||
- if at end of current directory pops stack and attempts to
|
|
||||||
find the next entry in the parent
|
|
||||||
- sets currentFile to nil if there are no more files to enumerate
|
|
||||||
*/
|
|
||||||
NSString *returnFileName = NULL;
|
|
||||||
|
|
||||||
if (_currentFilePath != NULL)
|
if (_currentFilePath != 0)
|
||||||
{
|
{
|
||||||
[_currentFilePath release];
|
DESTROY(_currentFilePath);
|
||||||
_currentFilePath = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (GSIArrayCount(_stack) > 0)
|
while (GSIArrayCount(_stack) > 0)
|
||||||
|
@ -2328,7 +2398,9 @@ static SEL ospfl = 0;
|
||||||
/* Skip "." and ".." directory entries */
|
/* Skip "." and ".." directory entries */
|
||||||
if (wcscmp(dirbuf->d_name, L".") == 0
|
if (wcscmp(dirbuf->d_name, L".") == 0
|
||||||
|| wcscmp(dirbuf->d_name, L"..") == 0)
|
|| wcscmp(dirbuf->d_name, L"..") == 0)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
/* Name of file to return */
|
/* Name of file to return */
|
||||||
returnFileName = _openStepPathFromLocalImp(defaultManager, ospfl,
|
returnFileName = _openStepPathFromLocalImp(defaultManager, ospfl,
|
||||||
[NSString stringWithCharacters: dirbuf->d_name
|
[NSString stringWithCharacters: dirbuf->d_name
|
||||||
|
@ -2337,16 +2409,21 @@ static SEL ospfl = 0;
|
||||||
/* Skip "." and ".." directory entries */
|
/* Skip "." and ".." directory entries */
|
||||||
if (strcmp(dirbuf->d_name, ".") == 0
|
if (strcmp(dirbuf->d_name, ".") == 0
|
||||||
|| strcmp(dirbuf->d_name, "..") == 0)
|
|| strcmp(dirbuf->d_name, "..") == 0)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
/* Name of file to return */
|
/* Name of file to return */
|
||||||
returnFileName = _openStepPathFromLocalImp(defaultManager, ospfl,
|
returnFileName = _openStepPathFromLocalImp(defaultManager, ospfl,
|
||||||
[NSString stringWithCString: dirbuf->d_name]);
|
[NSString stringWithCString: dirbuf->d_name]);
|
||||||
#endif
|
#endif
|
||||||
returnFileName = [[dir.path stringByAppendingPathComponent:returnFileName] retain];
|
returnFileName = [dir.path stringByAppendingPathComponent:
|
||||||
|
returnFileName];
|
||||||
|
RETAIN(returnFileName);
|
||||||
|
|
||||||
/* TODO - can this one can be removed ? */
|
/* TODO - can this one can be removed ? */
|
||||||
if (!_flags.justContents)
|
if (!_flags.justContents)
|
||||||
_currentFilePath = [[_topPath stringByAppendingPathComponent:returnFileName] retain];
|
_currentFilePath = RETAIN([_topPath stringByAppendingPathComponent:
|
||||||
|
returnFileName]);
|
||||||
|
|
||||||
if (_flags.isRecursive == YES)
|
if (_flags.isRecursive == YES)
|
||||||
{
|
{
|
||||||
|
@ -2357,23 +2434,32 @@ static SEL ospfl = 0;
|
||||||
#else
|
#else
|
||||||
if (!_flags.isFollowing)
|
if (!_flags.isFollowing)
|
||||||
{
|
{
|
||||||
if (lstat([_currentFilePath fileSystemRepresentation], &statbuf) != 0)
|
if (lstat([_currentFilePath fileSystemRepresentation],
|
||||||
|
&statbuf) != 0)
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
// If link then return it as link
|
// If link then return it as link
|
||||||
if (S_IFLNK == (S_IFMT & statbuf.st_mode))
|
if (S_IFLNK == (S_IFMT & statbuf.st_mode))
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#ifdef __MINGW__
|
#ifdef __MINGW__
|
||||||
if (_wstat([[_currentFilePath localFromOpenStepPath] unicharString], &statbuf) != 0)
|
if (_wstat([[_currentFilePath localFromOpenStepPath]
|
||||||
|
unicharString], &statbuf) != 0)
|
||||||
#else
|
#else
|
||||||
if (stat([_currentFilePath fileSystemRepresentation], &statbuf) != 0)
|
if (stat([_currentFilePath fileSystemRepresentation],
|
||||||
|
&statbuf) != 0)
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (S_IFDIR == (S_IFMT & statbuf.st_mode))
|
if (S_IFDIR == (S_IFMT & statbuf.st_mode))
|
||||||
{
|
{
|
||||||
#ifdef __MINGW__
|
#ifdef __MINGW__
|
||||||
|
@ -2390,15 +2476,15 @@ static SEL ospfl = 0;
|
||||||
{
|
{
|
||||||
GSIArrayItem item;
|
GSIArrayItem item;
|
||||||
|
|
||||||
item.ext.path = [returnFileName retain];
|
item.ext.path = RETAIN(returnFileName);
|
||||||
item.ext.pointer = dir_pointer;
|
item.ext.pointer = dir_pointer;
|
||||||
|
|
||||||
GSIArrayAddItem(_stack, item);
|
GSIArrayAddItem(_stack, item);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NSLog(@"Failed to recurse into directory '%@' - %s",_currentFilePath,
|
NSLog(@"Failed to recurse into directory '%@' - %s",
|
||||||
GSLastErrorStr(errno));
|
_currentFilePath, GSLastErrorStr(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2407,10 +2493,9 @@ static SEL ospfl = 0;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GSIArrayRemoveLastItem(_stack);
|
GSIArrayRemoveLastItem(_stack);
|
||||||
if (_currentFilePath != NULL)
|
if (_currentFilePath != 0)
|
||||||
{
|
{
|
||||||
[_currentFilePath release];
|
DESTROY(_currentFilePath);
|
||||||
_currentFilePath = NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2965,18 +3050,21 @@ static NSSet *fileKeys = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __MINGW__
|
#ifdef __MINGW__
|
||||||
+ (NSDictionary*) wattributesAt: (const unichar*)wpath traverseLink: (BOOL)traverse
|
+ (NSDictionary*) wattributesAt: (const unichar*)wpath
|
||||||
|
traverseLink: (BOOL)traverse
|
||||||
{
|
{
|
||||||
GSAttrDictionary *d;
|
GSAttrDictionary *d;
|
||||||
|
|
||||||
if (wpath == 0 || *wpath == L'\0')
|
if (wpath == 0 || *wpath == L'\0')
|
||||||
|
{
|
||||||
return nil;
|
return nil;
|
||||||
|
}
|
||||||
d = (GSAttrDictionary*)NSAllocateObject(self, 0, NSDefaultMallocZone());
|
d = (GSAttrDictionary*)NSAllocateObject(self, 0, NSDefaultMallocZone());
|
||||||
d->name = NULL; //seems to be unused
|
d->name = 0; //seems to be unused
|
||||||
if (_wstat(wpath, (struct _stat*)&d->statbuf) != 0)
|
if (_wstat(wpath, (struct _stat*)&d->statbuf) != 0)
|
||||||
|
{
|
||||||
DESTROY(d);
|
DESTROY(d);
|
||||||
|
}
|
||||||
return AUTORELEASE(d);
|
return AUTORELEASE(d);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -3116,13 +3204,14 @@ static NSSet *fileKeys = nil;
|
||||||
"myfile.txt",
|
"myfile.txt",
|
||||||
GENERIC_READ,
|
GENERIC_READ,
|
||||||
FILE_SHARE_READ,
|
FILE_SHARE_READ,
|
||||||
NULL,
|
0,
|
||||||
OPEN_EXISTING,
|
OPEN_EXISTING,
|
||||||
FILE_ATTRIBUTE_NORMAL,
|
FILE_ATTRIBUTE_NORMAL,
|
||||||
NULL);
|
0);
|
||||||
|
|
||||||
// Check GetLastError for CreateFile error code.
|
// Check GetLastError for CreateFile error code.
|
||||||
if (hFile == INVALID_HANDLE_VALUE) {
|
if (hFile == INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
DWORD dwErrorCode = 0;
|
DWORD dwErrorCode = 0;
|
||||||
|
|
||||||
dwErrorCode = GetLastError();
|
dwErrorCode = GetLastError();
|
||||||
|
@ -3146,13 +3235,14 @@ static NSSet *fileKeys = nil;
|
||||||
SE_FILE_OBJECT,
|
SE_FILE_OBJECT,
|
||||||
OWNER_SECURITY_INFORMATION,
|
OWNER_SECURITY_INFORMATION,
|
||||||
&pSidOwner,
|
&pSidOwner,
|
||||||
NULL,
|
0,
|
||||||
NULL,
|
0,
|
||||||
NULL,
|
0,
|
||||||
&pSD);
|
&pSD);
|
||||||
|
|
||||||
// Check GetLastError for GetSecurityInfo error condition.
|
// Check GetLastError for GetSecurityInfo error condition.
|
||||||
if (dwRtnCode != ERROR_SUCCESS) {
|
if (dwRtnCode != ERROR_SUCCESS)
|
||||||
|
{
|
||||||
DWORD dwErrorCode = 0;
|
DWORD dwErrorCode = 0;
|
||||||
|
|
||||||
dwErrorCode = GetLastError();
|
dwErrorCode = GetLastError();
|
||||||
|
@ -3162,7 +3252,7 @@ static NSSet *fileKeys = nil;
|
||||||
|
|
||||||
// First call to LookupAccountSid to get the buffer sizes.
|
// First call to LookupAccountSid to get the buffer sizes.
|
||||||
bRtnBool = LookupAccountSid(
|
bRtnBool = LookupAccountSid(
|
||||||
NULL, // local computer
|
0, // local computer
|
||||||
pSidOwner,
|
pSidOwner,
|
||||||
AcctName,
|
AcctName,
|
||||||
(LPDWORD)&dwAcctName,
|
(LPDWORD)&dwAcctName,
|
||||||
|
@ -3176,7 +3266,8 @@ static NSSet *fileKeys = nil;
|
||||||
dwAcctName);
|
dwAcctName);
|
||||||
|
|
||||||
// Check GetLastError for GlobalAlloc error condition.
|
// Check GetLastError for GlobalAlloc error condition.
|
||||||
if (AcctName == NULL) {
|
if (AcctName == 0)
|
||||||
|
{
|
||||||
DWORD dwErrorCode = 0;
|
DWORD dwErrorCode = 0;
|
||||||
|
|
||||||
dwErrorCode = GetLastError();
|
dwErrorCode = GetLastError();
|
||||||
|
@ -3189,18 +3280,18 @@ static NSSet *fileKeys = nil;
|
||||||
dwDomainName);
|
dwDomainName);
|
||||||
|
|
||||||
// Check GetLastError for GlobalAlloc error condition.
|
// Check GetLastError for GlobalAlloc error condition.
|
||||||
if (DomainName == NULL) {
|
if (DomainName == 0)
|
||||||
|
{
|
||||||
DWORD dwErrorCode = 0;
|
DWORD dwErrorCode = 0;
|
||||||
|
|
||||||
dwErrorCode = GetLastError();
|
dwErrorCode = GetLastError();
|
||||||
_tprintf(TEXT("GlobalAlloc error = %d\n"), dwErrorCode);
|
_tprintf(TEXT("GlobalAlloc error = %d\n"), dwErrorCode);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Second call to LookupAccountSid to get the account name.
|
// Second call to LookupAccountSid to get the account name.
|
||||||
bRtnBool = LookupAccountSid(
|
bRtnBool = LookupAccountSid(
|
||||||
NULL, // name of local or remote computer
|
0, // name of local or remote computer
|
||||||
pSidOwner, // security identifier
|
pSidOwner, // security identifier
|
||||||
AcctName, // account name buffer
|
AcctName, // account name buffer
|
||||||
(LPDWORD)&dwAcctName, // size of account name buffer
|
(LPDWORD)&dwAcctName, // size of account name buffer
|
||||||
|
@ -3209,7 +3300,8 @@ static NSSet *fileKeys = nil;
|
||||||
&eUse); // SID type
|
&eUse); // SID type
|
||||||
|
|
||||||
// Check GetLastError for LookupAccountSid error condition.
|
// Check GetLastError for LookupAccountSid error condition.
|
||||||
if (bRtnBool == FALSE) {
|
if (bRtnBool == FALSE)
|
||||||
|
{
|
||||||
DWORD dwErrorCode = 0;
|
DWORD dwErrorCode = 0;
|
||||||
|
|
||||||
dwErrorCode = GetLastError();
|
dwErrorCode = GetLastError();
|
||||||
|
@ -3219,12 +3311,12 @@ static NSSet *fileKeys = nil;
|
||||||
else
|
else
|
||||||
_tprintf(TEXT("Error in LookupAccountSid.\n"));
|
_tprintf(TEXT("Error in LookupAccountSid.\n"));
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
} else if (bRtnBool == TRUE)
|
else if (bRtnBool == TRUE)
|
||||||
|
{
|
||||||
// Print the account name.
|
// Print the account name.
|
||||||
_tprintf(TEXT("Account owner = %s\n"), AcctName);
|
_tprintf(TEXT("Account owner = %s\n"), AcctName);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue