mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
Delete temporary files when they are deallocated
This will remove a lot of the stray files in the temporary dir. However, they won't be deleted on exit of the program. What to do about this?
This commit is contained in:
+320
-320
File diff suppressed because it is too large
Load Diff
@@ -29,6 +29,7 @@
|
||||
F58A8F280E043698007E3FC0 /* commits.css in Resources */ = {isa = PBXBuildFile; fileRef = F58A8F270E043698007E3FC0 /* commits.css */; };
|
||||
F5945E170E02B0C200706420 /* PBGitRepository.m in Sources */ = {isa = PBXBuildFile; fileRef = F5945E160E02B0C200706420 /* PBGitRepository.m */; };
|
||||
F5B721C40E05CF7E00AF29DC /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = F5B721C20E05CF7E00AF29DC /* MainMenu.xib */; };
|
||||
F5DFFA6C0E075D8800617813 /* PBEasyFS.m in Sources */ = {isa = PBXBuildFile; fileRef = F5DFFA6B0E075D8800617813 /* PBEasyFS.m */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
@@ -70,6 +71,8 @@
|
||||
F5945E150E02B0C200706420 /* PBGitRepository.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitRepository.h; sourceTree = "<group>"; };
|
||||
F5945E160E02B0C200706420 /* PBGitRepository.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitRepository.m; sourceTree = "<group>"; };
|
||||
F5B721C30E05CF7E00AF29DC /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MainMenu.xib; sourceTree = "<group>"; };
|
||||
F5DFFA6A0E075D8800617813 /* PBEasyFS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBEasyFS.h; sourceTree = "<group>"; };
|
||||
F5DFFA6B0E075D8800617813 /* PBEasyFS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBEasyFS.m; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@@ -206,6 +209,8 @@
|
||||
F56524BA0E02D22D00F03B52 /* NSFileHandleExt.h */,
|
||||
F57CC38F0E05DDF2000472E2 /* PBEasyPipe.h */,
|
||||
F57CC3900E05DDF2000472E2 /* PBEasyPipe.m */,
|
||||
F5DFFA6A0E075D8800617813 /* PBEasyFS.h */,
|
||||
F5DFFA6B0E075D8800617813 /* PBEasyFS.m */,
|
||||
F53EE3590E06BBA00022B925 /* CWQuickLook.h */,
|
||||
F51308590E0740F2000C8BCD /* PBQLOutlineView.h */,
|
||||
F513085A0E0740F2000C8BCD /* PBQLOutlineView.m */,
|
||||
@@ -299,6 +304,7 @@
|
||||
F57CC3910E05DDF2000472E2 /* PBEasyPipe.m in Sources */,
|
||||
F57CC4410E05E496000472E2 /* PBDetailController.m in Sources */,
|
||||
F513085B0E0740F2000C8BCD /* PBQLOutlineView.m in Sources */,
|
||||
F5DFFA6C0E075D8800617813 /* PBEasyFS.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -361,6 +367,7 @@
|
||||
26FC0A890875C7B200E6366F /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
GCC_ENABLE_OBJC_GC = required;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
PREBINDING = NO;
|
||||
@@ -375,6 +382,7 @@
|
||||
ppc,
|
||||
i386,
|
||||
);
|
||||
GCC_ENABLE_OBJC_GC = required;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
PREBINDING = NO;
|
||||
|
||||
@@ -29,6 +29,12 @@
|
||||
- (void) updateKeys
|
||||
{
|
||||
NSArray* selection = [commitController selectedObjects];
|
||||
|
||||
// Remove any references in the QLPanel
|
||||
[[QLPreviewPanel sharedPreviewPanel] setURLs:[NSArray array] currentIndex:0 preservingDisplayState:YES];
|
||||
// We have to do this manually, as NSTreeController leaks memory?
|
||||
[treeController setSelectionIndexPaths:[NSArray array]];
|
||||
|
||||
if ([selection count] > 0)
|
||||
realCommit = [selection objectAtIndex:0];
|
||||
else
|
||||
@@ -38,6 +44,7 @@
|
||||
self.rawCommit = nil;
|
||||
self.gitTree = nil;
|
||||
|
||||
|
||||
int num = [self.selectedTab intValue];
|
||||
|
||||
if (num == 0) // Detailed view
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// PBEasyFS.h
|
||||
// GitX
|
||||
//
|
||||
// Created by Pieter de Bie on 6/17/08.
|
||||
// Copyright 2008 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
|
||||
@interface PBEasyFS : NSObject {
|
||||
|
||||
}
|
||||
+ (NSString*) tmpNameWithSuffix: (NSString*) path;
|
||||
+ (NSString*) tmpDirWithPrefix: (NSString*) path;
|
||||
|
||||
@end
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// PBEasyFS.m
|
||||
// GitX
|
||||
//
|
||||
// Created by Pieter de Bie on 6/17/08.
|
||||
// Copyright 2008 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import "PBEasyFS.h"
|
||||
|
||||
|
||||
@implementation PBEasyFS
|
||||
|
||||
+ (NSString*) tmpNameWithSuffix: (NSString*) path
|
||||
{
|
||||
NSString* newName = [NSString stringWithFormat: @"%@/XXXXXX%@", NSTemporaryDirectory(), path];
|
||||
char *template = (char*) [newName fileSystemRepresentation];
|
||||
int fd = mkstemps(template, [path length]);
|
||||
close(fd);
|
||||
return [NSString stringWithUTF8String:template];
|
||||
}
|
||||
|
||||
+ (NSString*) tmpDirWithPrefix: (NSString*) path
|
||||
{
|
||||
NSString* newName = [NSString stringWithFormat: @"%@%@.XXXXXX", NSTemporaryDirectory(), path];
|
||||
char *template = (char*) [newName fileSystemRepresentation];
|
||||
template = mkdtemp(template);
|
||||
return [NSString stringWithUTF8String:template];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -18,6 +18,4 @@
|
||||
|
||||
+ (NSString*) outputForCommand: (NSString*) cmd withArgs: (NSArray*) args;
|
||||
+ (NSString*) outputForCommand: (NSString*) cmd withArgs: (NSArray*) args inDir: (NSString*) dir;
|
||||
|
||||
+ (NSString*) writeData:(NSData*) data toTempFileWithName: (NSString *) fileName;
|
||||
@end
|
||||
|
||||
@@ -51,15 +51,4 @@
|
||||
return [self outputForCommand:cmd withArgs:args inDir:nil];
|
||||
}
|
||||
|
||||
+ (NSString*) writeData:(NSData*) data toTempFileWithName: (NSString *) fileName
|
||||
{
|
||||
NSString* newName = [NSString stringWithFormat: @"%@/XXXXXX%@", NSTemporaryDirectory(), fileName];
|
||||
char *template = (char*) [newName fileSystemRepresentation];
|
||||
int fd = mkstemps(template, [fileName length]);
|
||||
NSFileHandle* handle = [[NSFileHandle alloc] initWithFileDescriptor:fd];
|
||||
[handle writeData: data];
|
||||
[handle closeFile];
|
||||
return [NSString stringWithUTF8String:template];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
+2
-2
@@ -73,7 +73,7 @@ static NSString* gitPath = @"/usr/bin/env";
|
||||
|
||||
- (void) initializeCommits
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
//NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
NSMutableArray * newArray = [NSMutableArray array];
|
||||
NSDate* start = [NSDate date];
|
||||
@@ -96,7 +96,7 @@ static NSString* gitPath = @"/usr/bin/env";
|
||||
NSTimeInterval duration = [[NSDate date] timeIntervalSinceDate:start];
|
||||
NSLog(@"Loaded %i commits in %f seconds", num, duration);
|
||||
|
||||
[pool release];
|
||||
//[pool release];
|
||||
[NSThread exit];
|
||||
}
|
||||
|
||||
|
||||
+5
-2
@@ -13,9 +13,12 @@
|
||||
NSString* sha;
|
||||
NSString* path;
|
||||
PBGitRepository* repository;
|
||||
PBGitTree* parent;
|
||||
__weak PBGitTree* parent;
|
||||
NSArray* children;
|
||||
BOOL leaf;
|
||||
|
||||
NSString* localFileName;
|
||||
NSDate* localMtime;
|
||||
}
|
||||
|
||||
+ (PBGitTree*) rootForCommit: (id) commit;
|
||||
@@ -27,7 +30,7 @@
|
||||
@property(copy) NSString* path;
|
||||
@property(assign) BOOL leaf;
|
||||
@property(retain) PBGitRepository* repository;
|
||||
@property(assign) PBGitTree* parent;
|
||||
@property(assign) __weak PBGitTree* parent;
|
||||
|
||||
@property(readonly) NSArray* children;
|
||||
@property(readonly) NSString* fullPath;
|
||||
|
||||
+79
-7
@@ -10,6 +10,7 @@
|
||||
#import "PBGitCommit.h"
|
||||
#import "NSFileHandleExt.h"
|
||||
#import "PBEasyPipe.h"
|
||||
#import "PBEasyFS.h"
|
||||
|
||||
@implementation PBGitTree
|
||||
|
||||
@@ -40,6 +41,7 @@
|
||||
- init
|
||||
{
|
||||
children = nil;
|
||||
localFileName = nil;
|
||||
leaf = YES;
|
||||
return self;
|
||||
}
|
||||
@@ -49,25 +51,89 @@
|
||||
return [NSString stringWithFormat:@"%@:%@", self.sha, self.fullPath];
|
||||
}
|
||||
|
||||
- (BOOL) isLocallyCached
|
||||
{
|
||||
NSFileManager* fs = [NSFileManager defaultManager];
|
||||
if (localFileName && [fs fileExistsAtPath:localFileName])
|
||||
{
|
||||
NSDate* mtime = [[fs attributesOfItemAtPath:localFileName error: nil] objectForKey:NSFileModificationDate];
|
||||
if ([mtime compare:localMtime] == 0)
|
||||
return YES;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (NSString*) contents
|
||||
{
|
||||
if (!leaf)
|
||||
return [NSString stringWithFormat:@"This is a tree with path %@", self];
|
||||
|
||||
NSFileHandle* handle = [repository handleForArguments:[NSArray arrayWithObjects:@"show", [self refSpec], nil]];
|
||||
NSData* data = [handle readDataToEndOfFile];
|
||||
NSString* string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
||||
return string;
|
||||
NSData* data = nil;
|
||||
|
||||
if ([self isLocallyCached])
|
||||
data = [NSData dataWithContentsOfFile: localFileName];
|
||||
else {
|
||||
NSFileHandle* handle = [repository handleForArguments:[NSArray arrayWithObjects:@"show", [self refSpec], nil]];
|
||||
data = [handle readDataToEndOfFile];
|
||||
}
|
||||
|
||||
return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
||||
}
|
||||
|
||||
- (void) saveToFolder: (NSString *) dir
|
||||
{
|
||||
NSString* newName = [dir stringByAppendingPathComponent:path];
|
||||
|
||||
if (leaf) {
|
||||
NSFileHandle* handle = [repository handleForArguments:[NSArray arrayWithObjects:@"show", [self refSpec], nil]];
|
||||
NSData* data = [handle readDataToEndOfFile];
|
||||
[data writeToFile:newName atomically:YES];
|
||||
} else { // Directory
|
||||
[[NSFileManager defaultManager] createDirectoryAtPath:newName attributes:nil];
|
||||
for (PBGitTree* child in children)
|
||||
[child saveToFolder: newName];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString*) tmpDirWithContents
|
||||
{
|
||||
if (leaf)
|
||||
return nil;
|
||||
|
||||
if (!localFileName)
|
||||
localFileName = [PBEasyFS tmpDirWithPrefix: path];
|
||||
|
||||
NSLog(@"Exporting children..");
|
||||
|
||||
for (PBGitTree* child in [self children]) {
|
||||
NSLog(@"Telling %@ to save to %@!", [child fullPath], localFileName);
|
||||
[child saveToFolder: localFileName];
|
||||
}
|
||||
|
||||
return localFileName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
- (NSString*) tmpFileNameForContents
|
||||
{
|
||||
if (!leaf)
|
||||
return nil;
|
||||
NSLog(@"Getting tmp file");
|
||||
return [self tmpDirWithContents];
|
||||
|
||||
if ([self isLocallyCached])
|
||||
return localFileName;
|
||||
|
||||
if (!localFileName)
|
||||
localFileName = [PBEasyFS tmpNameWithSuffix: path];
|
||||
|
||||
NSFileHandle* handle = [repository handleForArguments:[NSArray arrayWithObjects:@"show", [self refSpec], nil]];
|
||||
NSData* data = [handle readDataToEndOfFile];
|
||||
return [PBEasyPipe writeData:data toTempFileWithName:path];
|
||||
[data writeToFile:localFileName atomically:YES];
|
||||
|
||||
NSFileManager* fs = [NSFileManager defaultManager];
|
||||
localMtime = [[fs attributesOfItemAtPath:localFileName error: nil] objectForKey:NSFileModificationDate];
|
||||
|
||||
return localFileName;
|
||||
}
|
||||
|
||||
- (NSArray*) children
|
||||
@@ -111,4 +177,10 @@
|
||||
return [parent.fullPath stringByAppendingPathComponent: self.path];
|
||||
}
|
||||
|
||||
- (void) finalize
|
||||
{
|
||||
if (localFileName)
|
||||
[[NSFileManager defaultManager] removeFileAtPath:localFileName handler:nil];
|
||||
[super finalize];
|
||||
}
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user