Diff
Modified: trunk/Source/WebKit/ChangeLog (88967 => 88968)
--- trunk/Source/WebKit/ChangeLog 2011-06-15 19:50:30 UTC (rev 88967)
+++ trunk/Source/WebKit/ChangeLog 2011-06-15 19:52:14 UTC (rev 88968)
@@ -1,3 +1,13 @@
+2011-06-15 David Kilzer <[email protected]>
+
+ <http://webkit.org/b/62745> Convert WebNSFileManagerExtras.m to Objective-C++
+
+ Reviewed by Joseph Pecoraro.
+
+ * WebKit.xcodeproj/project.pbxproj:
+ (WebNSFileManagerExtras.m): Rename to WebNSFileManagerExtras.mm
+ and change file type to Objective-C++.
+
2011-06-02 Adam Barth <[email protected]>
Reviewed by Ryosuke Niwa.
Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (88967 => 88968)
--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj 2011-06-15 19:50:30 UTC (rev 88967)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj 2011-06-15 19:52:14 UTC (rev 88968)
@@ -136,7 +136,7 @@
65E0F9E608500F23007E5CB9 /* WebNSUserDefaultsExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = 65E0F9E408500F23007E5CB9 /* WebNSUserDefaultsExtras.h */; settings = {ATTRIBUTES = (Private, ); }; };
65E0F9E708500F23007E5CB9 /* WebNSUserDefaultsExtras.mm in Sources */ = {isa = PBXBuildFile; fileRef = 65E0F9E508500F23007E5CB9 /* WebNSUserDefaultsExtras.mm */; };
65EEDE57084FFC9E0002DB25 /* WebNSFileManagerExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = 65EEDE55084FFC9E0002DB25 /* WebNSFileManagerExtras.h */; settings = {ATTRIBUTES = (Private, ); }; };
- 65EEDE58084FFC9E0002DB25 /* WebNSFileManagerExtras.m in Sources */ = {isa = PBXBuildFile; fileRef = 65EEDE56084FFC9E0002DB25 /* WebNSFileManagerExtras.m */; };
+ 65EEDE58084FFC9E0002DB25 /* WebNSFileManagerExtras.mm in Sources */ = {isa = PBXBuildFile; fileRef = 65EEDE56084FFC9E0002DB25 /* WebNSFileManagerExtras.mm */; };
65FFB7FC0AD0B7D30048CD05 /* WebDocumentLoaderMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 65FFB7FA0AD0B7D30048CD05 /* WebDocumentLoaderMac.h */; };
65FFB7FD0AD0B7D30048CD05 /* WebDocumentLoaderMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 65FFB7FB0AD0B7D30048CD05 /* WebDocumentLoaderMac.mm */; };
7A8FF0D11075024A00A80A08 /* WebInspectorPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A8FF0D01075024A00A80A08 /* WebInspectorPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -574,7 +574,7 @@
65E1150307EFFEBF009B8BF7 /* WebPluginContainerCheck.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebPluginContainerCheck.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
65E1150407EFFEBF009B8BF7 /* WebPluginContainerCheck.mm */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebPluginContainerCheck.mm; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
65EEDE55084FFC9E0002DB25 /* WebNSFileManagerExtras.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebNSFileManagerExtras.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
- 65EEDE56084FFC9E0002DB25 /* WebNSFileManagerExtras.m */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = WebNSFileManagerExtras.m; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
+ 65EEDE56084FFC9E0002DB25 /* WebNSFileManagerExtras.mm */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebNSFileManagerExtras.mm; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
65FFB7FA0AD0B7D30048CD05 /* WebDocumentLoaderMac.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = WebDocumentLoaderMac.h; sourceTree = "<group>"; };
65FFB7FB0AD0B7D30048CD05 /* WebDocumentLoaderMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = WebDocumentLoaderMac.mm; sourceTree = "<group>"; };
7082F56F038EADAA00A80180 /* WebKitNSStringExtras.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebKitNSStringExtras.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
@@ -999,7 +999,7 @@
BE887BFF056D3A6E009BB3E7 /* WebNSEventExtras.h */,
BE887C00056D3A6E009BB3E7 /* WebNSEventExtras.m */,
65EEDE55084FFC9E0002DB25 /* WebNSFileManagerExtras.h */,
- 65EEDE56084FFC9E0002DB25 /* WebNSFileManagerExtras.m */,
+ 65EEDE56084FFC9E0002DB25 /* WebNSFileManagerExtras.mm */,
8398847A03426FB000BC5F5E /* WebNSImageExtras.h */,
8398847B03426FB000BC5F5E /* WebNSImageExtras.m */,
51494D220C7EC1B6004178C5 /* WebNSNotificationCenterExtras.h */,
@@ -1969,7 +1969,7 @@
939811150824BF01008DF038 /* WebNSDataExtras.m in Sources */,
65488DA2084FBCCB00831AD0 /* WebNSDictionaryExtras.m in Sources */,
939811160824BF01008DF038 /* WebNSEventExtras.m in Sources */,
- 65EEDE58084FFC9E0002DB25 /* WebNSFileManagerExtras.m in Sources */,
+ 65EEDE58084FFC9E0002DB25 /* WebNSFileManagerExtras.mm in Sources */,
939810C70824BF01008DF038 /* WebNSImageExtras.m in Sources */,
51494D250C7EC1B7004178C5 /* WebNSNotificationCenterExtras.m in Sources */,
934C4A910F01406C009372C0 /* WebNSObjectExtras.mm in Sources */,
Modified: trunk/Source/WebKit/mac/ChangeLog (88967 => 88968)
--- trunk/Source/WebKit/mac/ChangeLog 2011-06-15 19:50:30 UTC (rev 88967)
+++ trunk/Source/WebKit/mac/ChangeLog 2011-06-15 19:52:14 UTC (rev 88968)
@@ -1,3 +1,13 @@
+2011-06-15 David Kilzer <[email protected]>
+
+ <http://webkit.org/b/62745> Convert WebNSFileManagerExtras.m to Objective-C++
+
+ Reviewed by Joseph Pecoraro.
+
+ * Misc/WebNSFileManagerExtras.mm: Renamed from Source/WebKit/mac/Misc/WebNSFileManagerExtras.m.
+ (-[NSFileManager _webkit_setMetadataURL:referrer:atPath:]):
+ Added static_cast<MetaDataInfo *>.
+
2011-06-14 Stephanie Lewis <[email protected]>
Rubber stamped by Oliver Hunt.
Deleted: trunk/Source/WebKit/mac/Misc/WebNSFileManagerExtras.m (88967 => 88968)
--- trunk/Source/WebKit/mac/Misc/WebNSFileManagerExtras.m 2011-06-15 19:50:30 UTC (rev 88967)
+++ trunk/Source/WebKit/mac/Misc/WebNSFileManagerExtras.m 2011-06-15 19:52:14 UTC (rev 88968)
@@ -1,188 +0,0 @@
-/*
- * 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
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
- * its contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#import <WebKit/WebNSFileManagerExtras.h>
-
-#import "WebKitNSStringExtras.h"
-#import "WebNSURLExtras.h"
-#import <_javascript_Core/Assertions.h>
-#import <WebKitSystemInterface.h>
-#import <sys/stat.h>
-
-@implementation NSFileManager (WebNSFileManagerExtras)
-
-- (NSString *)_webkit_carbonPathForPath:(NSString *)posixPath
-{
- OSStatus error;
- FSRef ref, rootRef, parentRef;
- FSCatalogInfo info;
- NSMutableArray *carbonPathPieces;
- HFSUniStr255 nameString;
-
- // Make an FSRef.
- error = FSPathMakeRef((const UInt8 *)[posixPath fileSystemRepresentation], &ref, NULL);
- if (error != noErr) {
- return nil;
- }
-
- // Get volume refNum.
- error = FSGetCatalogInfo(&ref, kFSCatInfoVolume, &info, NULL, NULL, NULL);
- if (error != noErr) {
- return nil;
- }
-
- // Get root directory FSRef.
- error = FSGetVolumeInfo(info.volume, 0, NULL, kFSVolInfoNone, NULL, NULL, &rootRef);
- if (error != noErr) {
- return nil;
- }
-
- // Get the pieces of the path.
- carbonPathPieces = [NSMutableArray array];
- for (;;) {
- error = FSGetCatalogInfo(&ref, kFSCatInfoNone, NULL, &nameString, NULL, &parentRef);
- if (error != noErr) {
- return nil;
- }
- [carbonPathPieces insertObject:[NSString stringWithCharacters:nameString.unicode length:nameString.length] atIndex:0];
- if (FSCompareFSRefs(&ref, &rootRef) == noErr) {
- break;
- }
- ref = parentRef;
- }
-
- // Volume names need trailing : character.
- if ([carbonPathPieces count] == 1) {
- [carbonPathPieces addObject:@""];
- }
-
- return [carbonPathPieces componentsJoinedByString:@":"];
-}
-
-typedef struct MetaDataInfo
-{
- CFStringRef URLString;
- CFStringRef referrer;
- CFStringRef path;
-} MetaDataInfo;
-
-static void *setMetaData(void* context)
-{
- MetaDataInfo *info = (MetaDataInfo *)context;
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- 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);
- [pool drain];
-
- return 0;
-}
-
-- (void)_webkit_setMetadataURL:(NSString *)URLString referrer:(NSString *)referrer atPath:(NSString *)path
-{
- ASSERT(URLString);
- ASSERT(path);
-
- NSURL *URL = "" _web_URLWithUserTypedString:URLString];
- if (URL)
- URLString = [[URL _web_URLByRemovingUserInfo] _web_userVisibleString];
-
- // Spawn a background thread for WKSetMetadataURL because this function will not return until mds has
- // journaled the data we're're trying to set. Depending on what other I/O is going on, it can take some
- // time.
- pthread_t tid;
- pthread_attr_t attr;
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-
- MetaDataInfo *info = malloc(sizeof(MetaDataInfo));
-
- 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);
-}
-
-- (NSString *)_webkit_startupVolumeName
-{
- NSString *path = [self _webkit_carbonPathForPath:@"/"];
- 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];
-
- 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;
- NSString *lastPathComponent = [path lastPathComponent];
- NSRange periodRange = [lastPathComponent rangeOfString:@"."];
-
- if (periodRange.location == NSNotFound) {
- pathWithoutExtensions = path;
- } else {
- extensions = [lastPathComponent substringFromIndex:periodRange.location + 1];
- lastPathComponent = [lastPathComponent substringToIndex:periodRange.location];
- pathWithoutExtensions = [[path stringByDeletingLastPathComponent] stringByAppendingPathComponent:lastPathComponent];
- }
-
- for (unsigned i = 1; ; i++) {
- NSString *pathWithAppendedNumber = [NSString stringWithFormat:@"%@-%d", pathWithoutExtensions, i];
- path = [extensions length] ? [pathWithAppendedNumber stringByAppendingPathExtension:extensions] : pathWithAppendedNumber;
- if (!fileExists(path))
- break;
- }
- }
-
- return path;
-}
-
-@end
-
Copied: trunk/Source/WebKit/mac/Misc/WebNSFileManagerExtras.mm (from rev 88967, trunk/Source/WebKit/mac/Misc/WebNSFileManagerExtras.m) (0 => 88968)
--- trunk/Source/WebKit/mac/Misc/WebNSFileManagerExtras.mm (rev 0)
+++ trunk/Source/WebKit/mac/Misc/WebNSFileManagerExtras.mm 2011-06-15 19:52:14 UTC (rev 88968)
@@ -0,0 +1,188 @@
+/*
+ * 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
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <WebKit/WebNSFileManagerExtras.h>
+
+#import "WebKitNSStringExtras.h"
+#import "WebNSURLExtras.h"
+#import <_javascript_Core/Assertions.h>
+#import <WebKitSystemInterface.h>
+#import <sys/stat.h>
+
+@implementation NSFileManager (WebNSFileManagerExtras)
+
+- (NSString *)_webkit_carbonPathForPath:(NSString *)posixPath
+{
+ OSStatus error;
+ FSRef ref, rootRef, parentRef;
+ FSCatalogInfo info;
+ NSMutableArray *carbonPathPieces;
+ HFSUniStr255 nameString;
+
+ // Make an FSRef.
+ error = FSPathMakeRef((const UInt8 *)[posixPath fileSystemRepresentation], &ref, NULL);
+ if (error != noErr) {
+ return nil;
+ }
+
+ // Get volume refNum.
+ error = FSGetCatalogInfo(&ref, kFSCatInfoVolume, &info, NULL, NULL, NULL);
+ if (error != noErr) {
+ return nil;
+ }
+
+ // Get root directory FSRef.
+ error = FSGetVolumeInfo(info.volume, 0, NULL, kFSVolInfoNone, NULL, NULL, &rootRef);
+ if (error != noErr) {
+ return nil;
+ }
+
+ // Get the pieces of the path.
+ carbonPathPieces = [NSMutableArray array];
+ for (;;) {
+ error = FSGetCatalogInfo(&ref, kFSCatInfoNone, NULL, &nameString, NULL, &parentRef);
+ if (error != noErr) {
+ return nil;
+ }
+ [carbonPathPieces insertObject:[NSString stringWithCharacters:nameString.unicode length:nameString.length] atIndex:0];
+ if (FSCompareFSRefs(&ref, &rootRef) == noErr) {
+ break;
+ }
+ ref = parentRef;
+ }
+
+ // Volume names need trailing : character.
+ if ([carbonPathPieces count] == 1) {
+ [carbonPathPieces addObject:@""];
+ }
+
+ return [carbonPathPieces componentsJoinedByString:@":"];
+}
+
+typedef struct MetaDataInfo
+{
+ CFStringRef URLString;
+ CFStringRef referrer;
+ CFStringRef path;
+} MetaDataInfo;
+
+static void *setMetaData(void* context)
+{
+ MetaDataInfo *info = (MetaDataInfo *)context;
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ 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);
+ [pool drain];
+
+ return 0;
+}
+
+- (void)_webkit_setMetadataURL:(NSString *)URLString referrer:(NSString *)referrer atPath:(NSString *)path
+{
+ ASSERT(URLString);
+ ASSERT(path);
+
+ NSURL *URL = "" _web_URLWithUserTypedString:URLString];
+ if (URL)
+ URLString = [[URL _web_URLByRemovingUserInfo] _web_userVisibleString];
+
+ // Spawn a background thread for WKSetMetadataURL because this function will not return until mds has
+ // journaled the data we're're trying to set. Depending on what other I/O is going on, it can take some
+ // time.
+ pthread_t tid;
+ pthread_attr_t attr;
+ pthread_attr_init(&attr);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+
+ MetaDataInfo *info = static_cast<MetaDataInfo *>(malloc(sizeof(MetaDataInfo)));
+
+ 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);
+}
+
+- (NSString *)_webkit_startupVolumeName
+{
+ NSString *path = [self _webkit_carbonPathForPath:@"/"];
+ 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];
+
+ 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;
+ NSString *lastPathComponent = [path lastPathComponent];
+ NSRange periodRange = [lastPathComponent rangeOfString:@"."];
+
+ if (periodRange.location == NSNotFound) {
+ pathWithoutExtensions = path;
+ } else {
+ extensions = [lastPathComponent substringFromIndex:periodRange.location + 1];
+ lastPathComponent = [lastPathComponent substringToIndex:periodRange.location];
+ pathWithoutExtensions = [[path stringByDeletingLastPathComponent] stringByAppendingPathComponent:lastPathComponent];
+ }
+
+ for (unsigned i = 1; ; i++) {
+ NSString *pathWithAppendedNumber = [NSString stringWithFormat:@"%@-%d", pathWithoutExtensions, i];
+ path = [extensions length] ? [pathWithAppendedNumber stringByAppendingPathExtension:extensions] : pathWithAppendedNumber;
+ if (!fileExists(path))
+ break;
+ }
+ }
+
+ return path;
+}
+
+@end
+