Skip to content

Commit

Permalink
Clear matplotlib's font cache file at launch to prevent sandboxing vi…
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Liyanage committed Oct 30, 2013
1 parent 8e1930e commit ec7744c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions IPython Notebook/Notebook Controller/NotebookWindowController.m
Expand Up @@ -218,6 +218,8 @@ - (IBAction)openNotebooksFolder:(id)sender

- (BOOL)launchNotebookServerTask
{
[self clearApplicationBundleLocationDependentCacheFiles];

NSURL *virtualEnvPythonURL = [[NSBundle mainBundle] URLForResource:@"python" withExtension:nil subdirectory:@"virtualenv/bin"];
NSURL *launchScriptURL = [[NSBundle mainBundle] URLForResource:@"launch-ipython" withExtension:@"py" subdirectory:@"virtualenv/bin"];
NSAssert(launchScriptURL, NSLocalizedString(@"Unable to determine url to launch-ipython.py script in resources", nil));
Expand Down Expand Up @@ -256,6 +258,22 @@ - (BOOL)launchNotebookServerTask
}


- (void)clearApplicationBundleLocationDependentCacheFiles
{
NSURL *homeDirectoryUrl = [NSURL fileURLWithPath:NSHomeDirectory()];
NSURL *matplotlibFontListCacheUrl = [homeDirectoryUrl URLByAppendingPathComponent:@".matplotlib/fontList.cache"];

NSFileManager *fm = [NSFileManager defaultManager];
if ([fm fileExistsAtPath:[matplotlibFontListCacheUrl path]]) {
NSLog(@"Removing cache file %@", [matplotlibFontListCacheUrl path]);
NSError *error = nil;
if (![fm removeItemAtURL:matplotlibFontListCacheUrl error:&error]) {
NSLog(@"Unable to remove cache file: %@", error);
}
}
}


- (NSString *)customPythonPath
{
if (![self.pythonPathURLs count]) {
Expand Down

0 comments on commit ec7744c

Please sign in to comment.