diff options
Diffstat (limited to 'WebKit/mac/Misc/WebNSFileManagerExtras.m')
| -rw-r--r-- | WebKit/mac/Misc/WebNSFileManagerExtras.m | 118 |
1 files changed, 32 insertions, 86 deletions
diff --git a/WebKit/mac/Misc/WebNSFileManagerExtras.m b/WebKit/mac/Misc/WebNSFileManagerExtras.m index fb1286f..ad48fb8 100644 --- a/WebKit/mac/Misc/WebNSFileManagerExtras.m +++ b/WebKit/mac/Misc/WebNSFileManagerExtras.m @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -30,74 +30,12 @@ #import "WebKitNSStringExtras.h" #import "WebNSURLExtras.h" -#import <WebCore/FoundationExtras.h> -#import <WebKitSystemInterface.h> -#import <pthread.h> -#import <sys/mount.h> #import <JavaScriptCore/Assertions.h> +#import <WebKitSystemInterface.h> +#import <sys/stat.h> @implementation NSFileManager (WebNSFileManagerExtras) -- (BOOL)_webkit_removeFileOnlyAtPath:(NSString *)path -{ - struct statfs buf; - BOOL result = unlink([path fileSystemRepresentation]) == 0; - - // For mysterious reasons, MNT_DOVOLFS is the flag for "supports resource fork" - if ((statfs([path fileSystemRepresentation], &buf) == 0) && !(buf.f_flags & MNT_DOVOLFS)) { - NSString *lastPathComponent = [path lastPathComponent]; - if ([lastPathComponent length] != 0 && ![lastPathComponent isEqualToString:@"/"]) { - NSString *resourcePath = [[path stringByDeletingLastPathComponent] stringByAppendingString:[@"._" stringByAppendingString:lastPathComponent]]; - if (unlink([resourcePath fileSystemRepresentation]) != 0) { - result = NO; - } - } - } - - return result; -} - -- (void)_webkit_backgroundRemoveFileAtPath:(NSString *)path -{ - NSFileManager *manager; - NSString *moveToSubpath; - NSString *moveToPath; - int i; - - manager = [NSFileManager defaultManager]; - - i = 0; - moveToSubpath = [path stringByDeletingLastPathComponent]; - do { - moveToPath = [NSString stringWithFormat:@"%@/.tmp%d", moveToSubpath, i]; - i++; - } while ([manager fileExistsAtPath:moveToPath]); - - if ([manager moveItemAtPath:path toPath:moveToPath error:NULL]) - [NSThread detachNewThreadSelector:@selector(_performRemoveFileAtPath:) toTarget:self withObject:moveToPath]; -} - -- (void)_webkit_backgroundRemoveLeftoverFiles:(NSString *)path -{ - NSFileManager *manager; - NSString *leftoverSubpath; - NSString *leftoverPath; - int i; - - manager = [NSFileManager defaultManager]; - leftoverSubpath = [path stringByDeletingLastPathComponent]; - - i = 0; - while (1) { - leftoverPath = [NSString stringWithFormat:@"%@/.tmp%d", leftoverSubpath, i]; - if (![manager fileExistsAtPath:leftoverPath]) { - break; - } - [NSThread detachNewThreadSelector:@selector(_performRemoveFileAtPath:) toTarget:self withObject:leftoverPath]; - i++; - } -} - - (NSString *)_webkit_carbonPathForPath:(NSString *)posixPath { OSStatus error; @@ -148,19 +86,22 @@ typedef struct MetaDataInfo { - NSString *URLString; - NSString *referrer; - NSString *path; + CFStringRef URLString; + CFStringRef referrer; + CFStringRef path; } MetaDataInfo; static void *setMetaData(void* context) { MetaDataInfo *info = (MetaDataInfo *)context; - WKSetMetadataURL(info->URLString, info->referrer, info->path); - - HardRelease(info->URLString); - HardRelease(info->referrer); - HardRelease(info->path); + WKSetMetadataURL((NSString *)info->URLString, (NSString *)info->referrer, (NSString *)info->path); + + if (info->URLString) + CFRelease(info->URLString); + if (info->referrer) + CFRelease(info->referrer); + if (info->path) + CFRelease(info->path); free(info); return 0; @@ -185,9 +126,9 @@ static void *setMetaData(void* context) MetaDataInfo *info = malloc(sizeof(MetaDataInfo)); - info->URLString = HardRetainWithNSRelease([URLString copy]); - info->referrer = HardRetainWithNSRelease([referrer copy]); - info->path = HardRetainWithNSRelease([path copy]); + info->URLString = URLString ? CFStringCreateCopy(0, (CFStringRef)URLString) : 0; + info->referrer = referrer ? CFStringCreateCopy(0, (CFStringRef)referrer) : 0; + info->path = path ? CFStringCreateCopy(0, (CFStringRef)path) : 0; pthread_create(&tid, &attr, setMetaData, info); pthread_attr_destroy(&attr); @@ -199,14 +140,22 @@ static void *setMetaData(void* context) return [path substringToIndex:[path length]-1]; } +// -[NSFileManager fileExistsAtPath:] returns NO if there is a broken symlink at the path. +// So we use this function instead, which returns YES if there is anything there, including +// a broken symlink. +static BOOL fileExists(NSString *path) +{ + struct stat statBuffer; + return !lstat([path fileSystemRepresentation], &statBuffer); +} + - (NSString *)_webkit_pathWithUniqueFilenameForPath:(NSString *)path { // "Fix" the filename of the path. NSString *filename = [[path lastPathComponent] _webkit_filenameByFixingIllegalCharacters]; path = [[path stringByDeletingLastPathComponent] stringByAppendingPathComponent:filename]; - NSFileManager *fileManager = [NSFileManager defaultManager]; - if ([fileManager fileExistsAtPath:path]) { + if (fileExists(path)) { // Don't overwrite existing file by appending "-n", "-n.ext" or "-n.ext.ext" to the filename. NSString *extensions = nil; NSString *pathWithoutExtensions; @@ -221,15 +170,11 @@ static void *setMetaData(void* context) pathWithoutExtensions = [[path stringByDeletingLastPathComponent] stringByAppendingPathComponent:lastPathComponent]; } - NSString *pathWithAppendedNumber; - unsigned i; - - for (i = 1; 1; i++) { - pathWithAppendedNumber = [NSString stringWithFormat:@"%@-%d", pathWithoutExtensions, i]; + for (unsigned i = 1; ; i++) { + NSString *pathWithAppendedNumber = [NSString stringWithFormat:@"%@-%d", pathWithoutExtensions, i]; path = [extensions length] ? [pathWithAppendedNumber stringByAppendingPathExtension:extensions] : pathWithAppendedNumber; - if (![fileManager fileExistsAtPath:path]) { + if (!fileExists(path)) break; - } } } @@ -238,8 +183,8 @@ static void *setMetaData(void* context) @end - #ifdef BUILDING_ON_TIGER + @implementation NSFileManager (WebNSFileManagerTigerForwardCompatibility) - (NSArray *)contentsOfDirectoryAtPath:(NSString *)path error:(NSError **)error @@ -293,4 +238,5 @@ static void *setMetaData(void* context) } @end + #endif |
