Revision: 5662
http://skim-app.svn.sourceforge.net/skim-app/?rev=5662&view=rev
Author: hofman
Date: 2009-09-04 10:46:55 +0000 (Fri, 04 Sep 2009)
Log Message:
-----------
replace thread safe files methods by using a local copy of NSFileManager
Modified Paths:
--------------
trunk/Files_SKExtensions.h
trunk/Files_SKExtensions.m
trunk/SKConversionProgressController.m
trunk/SKPDFSynchronizerServer.h
trunk/SKPDFSynchronizerServer.m
Modified: trunk/Files_SKExtensions.h
===================================================================
--- trunk/Files_SKExtensions.h 2009-09-04 10:35:39 UTC (rev 5661)
+++ trunk/Files_SKExtensions.h 2009-09-04 10:46:55 UTC (rev 5662)
@@ -45,16 +45,10 @@
// These functions are thread safe
extern BOOL SKFileIsInTrash(NSURL *fileURL);
-extern BOOL SKFileExistsAtPath(NSString *path);
-extern NSDate *SKFileModificationDateAtPath(NSString *path);
extern NSURL *SKResolvedURLFromPath(NSString *path);
extern NSString *SKUniqueDirectoryCreating(NSString *basePath, BOOL create);
extern NSString *SKChewableItemsDirectory();
extern NSString *SKUniqueTemporaryDirectory();
extern NSString *SKUniqueChewableItemsDirectory();
-
-extern OSErr FSDeleteContainerContents(const FSRef *container);
-extern OSErr FSDeleteContainer(const FSRef *container);
-extern OSErr FSPathDeleteContainer(const UInt8 *containerPath);
\ No newline at end of file
Modified: trunk/Files_SKExtensions.m
===================================================================
--- trunk/Files_SKExtensions.m 2009-09-04 10:35:39 UTC (rev 5661)
+++ trunk/Files_SKExtensions.m 2009-09-04 10:46:55 UTC (rev 5662)
@@ -69,28 +69,6 @@
return result;
}
-BOOL SKFileExistsAtPath(NSString *path) {
- FSRef fileRef;
-
- if (path && noErr == FSPathMakeRefWithOptions((UInt8 *)[path
fileSystemRepresentation], kFSPathMakeRefDoNotFollowLeafSymlink, &fileRef,
NULL))
- return YES;
- else
- return NO;
-}
-
-NSDate *SKFileModificationDateAtPath(NSString *path) {
- FSRef fileRef;
- FSCatalogInfo info;
- CFAbsoluteTime absoluteTime;
-
- if (CFURLGetFSRef((CFURLRef)[NSURL fileURLWithPath:path], &fileRef) &&
- noErr == FSGetCatalogInfo(&fileRef, kFSCatInfoContentMod, &info, NULL,
NULL, NULL) &&
- noErr == UCConvertUTCDateTimeToCFAbsoluteTime(&info.contentModDate,
&absoluteTime))
- return [NSDate
dateWithTimeIntervalSinceReferenceDate:(NSTimeInterval)absoluteTime];
- else
- return nil;
-}
-
extern NSURL *SKResolvedURLFromPath(NSString *path) {
NSURL *url = nil;
FSRef fileRef;
@@ -171,148 +149,3 @@
NSString *SKUniqueChewableItemsDirectory() {
return SKUniqueDirectoryCreating(SKChewableItemsDirectory(), YES);
}
-
-// These are taken from MoreFilesX
-
-struct FSDeleteContainerGlobals
-{
- OSErr result;
/* result */
- ItemCount actualObjects;
/* number of objects returned */
- FSCatalogInfo catalogInfo; /*
FSCatalogInfo */
-};
-typedef struct FSDeleteContainerGlobals FSDeleteContainerGlobals;
-
-static
-void
-FSDeleteContainerLevel(
- const FSRef *container,
- FSDeleteContainerGlobals *theGlobals)
-{
- /* level locals */
- FSIterator iterator;
- FSRef itemToDelete;
- UInt16 nodeFlags;
-
- /* Open FSIterator for flat access and give delete optimization hint */
- theGlobals->result = FSOpenIterator(container, kFSIterateFlat +
kFSIterateDelete, &iterator);
- require_noerr(theGlobals->result, FSOpenIterator);
-
- /* delete the contents of the directory */
- do
- {
- /* get 1 item to delete */
- theGlobals->result = FSGetCatalogInfoBulk(iterator, 1,
&theGlobals->actualObjects,
- NULL,
kFSCatInfoNodeFlags, &theGlobals->catalogInfo,
- &itemToDelete,
NULL, NULL);
- if ( (noErr == theGlobals->result) && (1 ==
theGlobals->actualObjects) )
- {
- /* save node flags in local in case we have to recurse
*/
- nodeFlags = theGlobals->catalogInfo.nodeFlags;
-
- /* is it a file or directory? */
- if ( 0 != (nodeFlags & kFSNodeIsDirectoryMask) )
- {
- /* it's a directory -- delete its contents
before attempting to delete it */
- FSDeleteContainerLevel(&itemToDelete,
theGlobals);
- }
- /* are we still OK to delete? */
- if ( noErr == theGlobals->result )
- {
- /* is item locked? */
- if ( 0 != (nodeFlags & kFSNodeLockedMask) )
- {
- /* then attempt to unlock it (ignore
result since FSDeleteObject will set it correctly) */
- theGlobals->catalogInfo.nodeFlags =
nodeFlags & ~kFSNodeLockedMask;
- (void) FSSetCatalogInfo(&itemToDelete,
kFSCatInfoNodeFlags, &theGlobals->catalogInfo);
- }
- /* delete the item */
- theGlobals->result =
FSDeleteObject(&itemToDelete);
- }
- }
- } while ( noErr == theGlobals->result );
-
- /* we found the end of the items normally, so return noErr */
- if ( errFSNoMoreItems == theGlobals->result )
- {
- theGlobals->result = noErr;
- }
-
- /* close the FSIterator (closing an open iterator should never fail) */
- verify_noerr(FSCloseIterator(iterator));
-
-FSOpenIterator:
-
- return;
-}
-
-OSErr
-FSDeleteContainerContents(
- const FSRef *container)
-{
- FSDeleteContainerGlobals theGlobals;
-
- /* delete container's contents */
- FSDeleteContainerLevel(container, &theGlobals);
-
- return ( theGlobals.result );
-}
-
-OSErr
-FSDeleteContainer(
- const FSRef *container)
-{
- OSErr result;
- FSCatalogInfo catalogInfo;
-
- /* get nodeFlags for container */
- result = FSGetCatalogInfo(container, kFSCatInfoNodeFlags, &catalogInfo,
NULL, NULL,NULL);
- require_noerr(result, FSGetCatalogInfo);
-
- /* make sure container is a directory */
- require_action(0 != (catalogInfo.nodeFlags & kFSNodeIsDirectoryMask),
ContainerNotDirectory, result = dirNFErr);
-
- /* delete container's contents */
- result = FSDeleteContainerContents(container);
- require_noerr(result, FSDeleteContainerContents);
-
- /* is container locked? */
- if ( 0 != (catalogInfo.nodeFlags & kFSNodeLockedMask) )
- {
- /* then attempt to unlock container (ignore result since
FSDeleteObject will set it correctly) */
- catalogInfo.nodeFlags &= ~kFSNodeLockedMask;
- (void) FSSetCatalogInfo(container, kFSCatInfoNodeFlags,
&catalogInfo);
- }
-
- /* delete the container */
- result = FSDeleteObject(container);
-
-FSDeleteContainerContents:
-ContainerNotDirectory:
-FSGetCatalogInfo:
-
- return ( result );
-}
-
-OSErr
-FSPathDeleteContainer(
- const UInt8 *containerPath)
-{
- OSErr result;
- FSRef container;
- Boolean isDirectory;
-
- /* get FSRef for container */
- result = FSPathMakeRef(containerPath, &container, &isDirectory);
- require_noerr(result, FSPathMakeRef);
-
- /* make sure container is a directory */
- require_action(isDirectory == true, ContainerNotDirectory, result =
dirNFErr);
-
- /* delete the container recursively */
- result = FSDeleteContainer(&container);
-
-ContainerNotDirectory:
-FSPathMakeRef:
-
- return ( result );
-}
Modified: trunk/SKConversionProgressController.m
===================================================================
--- trunk/SKConversionProgressController.m 2009-09-04 10:35:39 UTC (rev
5661)
+++ trunk/SKConversionProgressController.m 2009-09-04 10:46:55 UTC (rev
5662)
@@ -343,8 +343,9 @@
BOOL success = NO;
NSInvocation *invocation;
+ NSFileManager *fm = [[[NSFileManager alloc] init] autorelease];
- if ([self shouldKeepRunning] && [[[[NSFileManager alloc] init]
autorelease] fileExistsAtPath:dviFile]) {
+ if ([self shouldKeepRunning] && [fm fileExistsAtPath:dviFile]) {
NSTask *task = [NSTask launchedTaskWithLaunchPath:commandPath
arguments:arguments currentDirectoryPath:[dviFile
stringByDeletingLastPathComponent]];
if (task) {
invocation = [NSInvocation invocationWithTarget:self
selector:@selector(conversionStarted)];
@@ -390,7 +391,7 @@
[self stopModalOnMainThread:success];
}
- FSPathDeleteContainer((UInt8 *)[tmpDir fileSystemRepresentation]);
+ [fm removeItemAtPath:tmpDir error:NULL];
[pool release];
}
Modified: trunk/SKPDFSynchronizerServer.h
===================================================================
--- trunk/SKPDFSynchronizerServer.h 2009-09-04 10:35:39 UTC (rev 5661)
+++ trunk/SKPDFSynchronizerServer.h 2009-09-04 10:46:55 UTC (rev 5662)
@@ -60,6 +60,8 @@
NSDate *lastModDate;
BOOL isPdfsync;
+ NSFileManager *fileManager;
+
NSMutableArray *pages;
NSMutableDictionary *lines;
Modified: trunk/SKPDFSynchronizerServer.m
===================================================================
--- trunk/SKPDFSynchronizerServer.m 2009-09-04 10:35:39 UTC (rev 5661)
+++ trunk/SKPDFSynchronizerServer.m 2009-09-04 10:46:55 UTC (rev 5662)
@@ -141,6 +141,8 @@
// handshake, this sets the proxy at the other side
[clientProxy setServerProxy:self];
+ fileManager = [[NSFileManager alloc] init];
+
OSAtomicCompareAndSwap32Barrier(0, 1, (int32_t
*)&serverFlags->serverReady);
NSRunLoop *rl = [NSRunLoop currentRunLoop];
@@ -159,6 +161,9 @@
OSAtomicCompareAndSwap32Barrier(0, 1, (int32_t
*)&serverFlags->serverReady);
}
@finally {
+ [fileManager release];
+ fileManager = nil;
+
// clean up the connection in the server thread
[connection setRootObject:nil];
@@ -235,6 +240,7 @@
return file;
}
+// this should only be used from the server thread
- (void)setSyncFileName:(NSString *)newSyncFileName {
@synchronized(self) {
if (syncFileName != newSyncFileName) {
@@ -242,7 +248,7 @@
syncFileName = [newSyncFileName retain];
}
[lastModDate release];
- lastModDate = [(syncFileName ?
SKFileModificationDateAtPath(syncFileName) : nil) retain];
+ lastModDate = [(syncFileName ? [[fileManager
attributesOfItemAtPath:syncFileName error:NULL] fileModificationDate] : nil)
retain];
}
}
@@ -261,12 +267,12 @@
file = [file substringWithRange:NSMakeRange(1, [file length] - 2)];
if ([file isAbsolutePath] == NO)
file = [[[self fileName] stringByDeletingLastPathComponent]
stringByAppendingPathComponent:file];
- if (isTeX && SKFileExistsAtPath(file) == NO &&
[SKPDFSynchronizerTexExtensions containsObject:[[file pathExtension]
lowercaseString]] == NO) {
+ if (isTeX && [fileManager fileExistsAtPath:file] == NO &&
[SKPDFSynchronizerTexExtensions containsObject:[[file pathExtension]
lowercaseString]] == NO) {
NSEnumerator *texExtensions = [SKPDFSynchronizerTexExtensions
objectEnumerator];
NSString *extension;
while (extension = [texExtensions nextObject]) {
NSString *tryFile = [file
stringByAppendingPathExtension:extension];
- if (SKFileExistsAtPath(tryFile)) {
+ if ([fileManager fileExistsAtPath:tryFile]) {
file = tryFile;
break;
}
@@ -584,8 +590,8 @@
if (theFileName) {
NSString *theSyncFileName = [self syncFileName];
- if (theSyncFileName && SKFileExistsAtPath(theSyncFileName)) {
- NSDate *modDate = SKFileModificationDateAtPath(theFileName);
+ if (theSyncFileName && [fileManager fileExistsAtPath:theSyncFileName])
{
+ NSDate *modDate = [[fileManager attributesOfItemAtPath:theFileName
error:NULL] fileModificationDate];
NSDate *currentModDate = [self lastModDate];
if (currentModDate && [modDate compare:currentModDate] !=
NSOrderedDescending)
@@ -598,7 +604,7 @@
rv = [self loadSynctexFileForFile:theFileName];
if (rv == NO) {
theSyncFileName = [theFileName
stringByReplacingPathExtension:SKPDFSynchronizerPdfsyncExtension];
- if (SKFileExistsAtPath(theSyncFileName))
+ if ([fileManager fileExistsAtPath:theSyncFileName])
rv = [self loadPdfsyncFile:theSyncFileName];
}
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit