Permalink
Browse files

Use new shared temporary folder method. Also, make use of threadSafe …

…file manager while I"m at it.
  • Loading branch information...
danwood committed Sep 17, 2010
1 parent 2b41862 commit 6d6de572450a9235cc3a4f40e0f1eaab8ac17f68
View
@@ -99,7 +99,7 @@ + (NSArray*) parserInstancesForMediaType:(NSString*)inMediaType
NSMutableArray* parserInstances = [NSMutableArray array]; NSMutableArray* parserInstances = [NSMutableArray array];
NSString *bookmarkPath = [self firefoxBookmarkPath]; NSString *bookmarkPath = [self firefoxBookmarkPath];
NSFileManager *fm = [NSFileManager defaultManager]; // File manager, not flying meat! NSFileManager *fm = [NSFileManager threadSafeManager]; // File manager, not flying meat!
if ([self isInstalled] && bookmarkPath && [fm fileExistsAtPath:bookmarkPath] && [fm isReadableFileAtPath:bookmarkPath]) if ([self isInstalled] && bookmarkPath && [fm fileExistsAtPath:bookmarkPath] && [fm isReadableFileAtPath:bookmarkPath])
{ {
IMBFireFoxParser* parser = [[[self class] alloc] initWithMediaType:inMediaType]; IMBFireFoxParser* parser = [[[self class] alloc] initWithMediaType:inMediaType];
@@ -119,7 +119,7 @@ + (NSString *)firefoxBookmarkPath;
NSArray *libraryPaths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES); NSArray *libraryPaths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
NSString *path = [libraryPaths objectAtIndex:0]; NSString *path = [libraryPaths objectAtIndex:0];
NSFileManager *fm = [NSFileManager defaultManager]; NSFileManager *fm = [NSFileManager threadSafeManager];
NSString *firefoxPath = [path stringByAppendingPathComponent:@"Firefox"]; NSString *firefoxPath = [path stringByAppendingPathComponent:@"Firefox"];
NSString *profilesPath = [firefoxPath stringByAppendingPathComponent:@"Profiles"]; NSString *profilesPath = [firefoxPath stringByAppendingPathComponent:@"Profiles"];
@@ -148,14 +148,14 @@ + (NSString *)firefoxBookmarkPath;
- (void) copyDatabase; // try to copy the database and store in copy. - (void) copyDatabase; // try to copy the database and store in copy.
{ {
NSFileManager *fm = [NSFileManager defaultManager]; NSFileManager *fm = [NSFileManager threadSafeManager];
NSString *newPath = nil; // copy destination if we have to copy the file NSString *newPath = nil; // copy destination if we have to copy the file
// null result set means we couldn't open it ... it's probably busy. // null result set means we couldn't open it ... it's probably busy.
// The stupid workaround is to make a copy of the sqlite file, and check there! // The stupid workaround is to make a copy of the sqlite file, and check there!
// However just in case the source file has not changed, we'll check modification dates. // However just in case the source file has not changed, we'll check modification dates.
// //
newPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"places.sqlite"]; newPath = [[[NSFileManager threadSafeManager] sharedTemporaryFolder:@"firefox"] stringByAppendingPathComponent:@"places.sqlite"];
if (![newPath isEqualToString:self.databasePathCurrent]) // if we are trying to open the copy, don't allow that. if (![newPath isEqualToString:self.databasePathCurrent]) // if we are trying to open the copy, don't allow that.
{ {
BOOL needToCopyFile = YES; // probably we will need to copy but let's check BOOL needToCopyFile = YES; // probably we will need to copy but let's check
View
@@ -83,8 +83,7 @@ - (NSURL*) previewItemURL
{ {
// The is our temp download folder... // The is our temp download folder...
NSString* folder = [NSTemporaryDirectory() stringByAppendingPathComponent:@"iMedia-QuickLook"]; NSString* folder = [[NSFileManager threadSafeManager] sharedTemporaryFolder:@"quicklook"];
[[NSFileManager defaultManager] createDirectoryAtPath:folder withIntermediateDirectories:YES attributes:nil error:nil];
// Build a path for the download file... // Build a path for the download file...
@@ -93,7 +92,7 @@ - (NSURL*) previewItemURL
// If the file is already there, then use it... // If the file is already there, then use it...
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) if ([[NSFileManager threadSafeManager] fileExistsAtPath:path])
{ {
previewItemURL = [NSURL fileURLWithPath:path]; previewItemURL = [NSURL fileURLWithPath:path];
} }
View
@@ -112,7 +112,7 @@ - (IMBNode*) nodeWithOldNode:(const IMBNode*)inOldNode options:(IMBOptions)inOpt
// Check if the folder exists. If not then do not return a node... // Check if the folder exists. If not then do not return a node...
BOOL exists,directory; BOOL exists,directory;
exists = [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&directory]; exists = [[NSFileManager threadSafeManager] fileExistsAtPath:path isDirectory:&directory];
if (!exists || !directory) if (!exists || !directory)
{ {
View
@@ -257,7 +257,7 @@ - (IMBNode*) _unpopulatedRootNodes
NSString* demoSongsPath = [IMBGarageBandParser demoSongsPath]; NSString* demoSongsPath = [IMBGarageBandParser demoSongsPath];
if ([[NSFileManager defaultManager] fileExistsAtPath:demoSongsPath]) if ([[NSFileManager threadSafeManager] fileExistsAtPath:demoSongsPath])
{ {
IMBNode* demo = [[[IMBNode alloc] init] autorelease]; IMBNode* demo = [[[IMBNode alloc] init] autorelease];
demo.parentNode = root; demo.parentNode = root;
@@ -278,7 +278,7 @@ - (IMBNode*) _unpopulatedRootNodes
NSString* userSongsPath = [IMBGarageBandParser userSongsPath]; NSString* userSongsPath = [IMBGarageBandParser userSongsPath];
if ([[NSFileManager defaultManager] fileExistsAtPath:userSongsPath]) if ([[NSFileManager threadSafeManager] fileExistsAtPath:userSongsPath])
{ {
IMBNode* user = [[[IMBNode alloc] init] autorelease]; IMBNode* user = [[[IMBNode alloc] init] autorelease];
user.parentNode = root; user.parentNode = root;
View
@@ -513,7 +513,7 @@ + (NSString*)cloneDatabase:(NSString*)databasePath
NSString *pathExtension = [databasePath pathExtension]; NSString *pathExtension = [databasePath pathExtension];
NSString *readOnlyDatabasePath = [[NSString stringWithFormat:@"%@-readOnly", basePath] stringByAppendingPathExtension:pathExtension]; NSString *readOnlyDatabasePath = [[NSString stringWithFormat:@"%@-readOnly", basePath] stringByAppendingPathExtension:pathExtension];
NSFileManager *fileManager = [NSFileManager defaultManager]; NSFileManager *fileManager = [NSFileManager threadSafeManager];
BOOL needToCopyFile = YES; // probably we will need to copy but let's check BOOL needToCopyFile = YES; // probably we will need to copy but let's check
NSError* error; NSError* error;
View
@@ -253,7 +253,7 @@ + (void) parseRecentLibrariesList:(NSString*)inRecentLibrariesList into:(NSMutab
path = [path substringWithRange:NSMakeRange(1, [path length] - 3)]; path = [path substringWithRange:NSMakeRange(1, [path length] - 3)];
BOOL exists,changed; BOOL exists,changed;
exists = [[NSFileManager defaultManager] fileExistsAtPath:&path wasChanged:&changed]; exists = [[NSFileManager threadSafeManager] fileExistsAtPath:&path wasChanged:&changed];
if (exists) [inLibraryPaths addObject:path]; if (exists) [inLibraryPaths addObject:path];
path = @""; path = @"";
View
@@ -152,7 +152,7 @@ - (NSDictionary*) metadataForFileAtPath:(NSString*)inPath
} }
else else
{ {
// NSLog(@"Nil from MDItemCreate for %@ exists?%d", inPath, [[NSFileManager defaultManager] fileExistsAtPath:inPath]); // NSLog(@"Nil from MDItemCreate for %@ exists?%d", inPath, [[NSFileManager threadSafeManager] fileExistsAtPath:inPath]);
} }
return metadata; return metadata;
View
@@ -695,7 +695,7 @@ - (NSDragOperation) outlineView:(NSOutlineView*)inOutlineView validateDrop:(id<N
for (NSString* path in paths) for (NSString* path in paths)
{ {
exists = [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&directory]; exists = [[NSFileManager threadSafeManager] fileExistsAtPath:path isDirectory:&directory];
if (exists && directory) if (exists && directory)
{ {
@@ -717,7 +717,7 @@ - (BOOL) outlineView:(NSOutlineView*)inOutlineView acceptDrop:(id<NSDraggingInfo
for (NSString* path in paths) for (NSString* path in paths)
{ {
exists = [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&directory]; exists = [[NSFileManager threadSafeManager] fileExistsAtPath:path isDirectory:&directory];
if (exists && directory) if (exists && directory)
{ {
View
@@ -366,7 +366,7 @@ - (void) _loadObject:(IMBObject*)inObject
// Now, copy this to the download folder path ... ? // Now, copy this to the download folder path ... ?
NSString *fullPath = [self.downloadFolderPath stringByAppendingPathComponent:[[localURL path] lastPathComponent]]; NSString *fullPath = [self.downloadFolderPath stringByAppendingPathComponent:[[localURL path] lastPathComponent]];
NSError *err = nil; NSError *err = nil;
[[NSFileManager defaultManager] copyItemAtPath:[localURL path] toPath:fullPath error:&err]; [[NSFileManager threadSafeManager] copyItemAtPath:[localURL path] toPath:fullPath error:&err];
if (err) if (err)
{ {
NSLog(@"%@", err); NSLog(@"%@", err);
@@ -545,7 +545,11 @@ - (void) loadObjects:(NSArray*)inObjects
op.delegateReference = object; op.delegateReference = object;
NSString *downloadFolderPath = self.downloadFolderPath; NSString *downloadFolderPath = self.downloadFolderPath;
if (!downloadFolderPath) downloadFolderPath = NSTemporaryDirectory(); // force downloading into temporary directory if (!downloadFolderPath)
{
downloadFolderPath = [[NSFileManager threadSafeManager] sharedTemporaryFolder:@"downloads"];
// force downloading into temporary directory
}
op.downloadFolderPath = downloadFolderPath; op.downloadFolderPath = downloadFolderPath;
[self.downloadOperations addObject:op]; [self.downloadOperations addObject:op];
View
@@ -60,6 +60,8 @@
- (NSString*)uniqueTemporaryFile:(NSString*)name withinDirectory:(NSString*)directoryPath; - (NSString*)uniqueTemporaryFile:(NSString*)name withinDirectory:(NSString*)directoryPath;
- (NSString*)uniqueTemporaryPathWithinDirectory:(NSString*)directoryPath; - (NSString*)uniqueTemporaryPathWithinDirectory:(NSString*)directoryPath;
- (NSString*)sharedTemporaryFolder:(NSString*)dirName;
- (NSString*) volumeNameAtPath:(NSString*)inPath; - (NSString*) volumeNameAtPath:(NSString*)inPath;
- (NSString*) relativePathToVolumeAtPath:(NSString*)inPath; - (NSString*) relativePathToVolumeAtPath:(NSString*)inPath;
- (BOOL) fileExistsAtPath:(NSString**)ioPath wasChanged:(BOOL*)outWasChanged; - (BOOL) fileExistsAtPath:(NSString**)ioPath wasChanged:(BOOL*)outWasChanged;
View
@@ -106,7 +106,7 @@ - (BOOL)createDirectoryPath:(NSString *)path attributes:(NSDictionary *)attribut
[NSException raise:@"iMediaException" format:@"createDirectoryPath:attributes: path not absolute:%@", path]; [NSException raise:@"iMediaException" format:@"createDirectoryPath:attributes: path not absolute:%@", path];
} }
return [[NSFileManager defaultManager] fileExistsAtPath:path]; return [self fileExistsAtPath:path];
} }
- (BOOL)isPathHidden:(NSString *)path - (BOOL)isPathHidden:(NSString *)path
@@ -154,6 +154,20 @@ - (NSString *)pathResolved:(NSString *)path
return resolvedPath; return resolvedPath;
} }
// Return (creating if necessary) a path to the shared iMedia temporary directory.
// If you pass in a subfolder name, that will be created and appended.
- (NSString*)sharedTemporaryFolder:(NSString*)dirName;
{
NSString *directoryPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"iMedia"];
if (dirName && ![dirName isEqualToString:@""])
{
directoryPath = [directoryPath stringByAppendingPathComponent:dirName];
}
[self createDirectoryAtPath:directoryPath withIntermediateDirectories:YES attributes:nil error:NULL];
return directoryPath;
}
- (NSString*)uniqueTemporaryFile:(NSString*)name - (NSString*)uniqueTemporaryFile:(NSString*)name
{ {
NSString *processName = [[NSProcessInfo processInfo] processName]; NSString *processName = [[NSProcessInfo processInfo] processName];

0 comments on commit 6d6de57

Please sign in to comment.