Permalink
Browse files

fixed arc compile errors, archiveInterval now configurable

  • Loading branch information...
1 parent e367713 commit 924510cc676512db623d1a0ce797bf0b8ffbf0d1 @artifacts committed Nov 12, 2013
Showing with 34 additions and 40 deletions.
  1. +1 −0 src/shared/AFCache.h
  2. +10 −6 src/shared/AFCache.m
  3. +23 −34 src/shared/AFCachePackageCreator.m
View
@@ -127,6 +127,7 @@ typedef struct NetworkTimeoutIntervals {
@property (nonatomic, assign) double maxItemFileSize;
@property (nonatomic, assign) double diskCacheDisplacementTresholdSize;
@property (nonatomic, assign) NetworkTimeoutIntervals networkTimeoutIntervals;
+@property (nonatomic, assign) NSTimeInterval archiveInterval;
/*
View
@@ -54,7 +54,8 @@
const char* kAFCacheContentLengthFileAttribute = "de.artifacts.contentLength";
const char* kAFCacheDownloadingFileAttribute = "de.artifacts.downloading";
const double kAFCacheInfiniteFileSize = 0.0;
-const double kAFCacheArchiveDelay = 5.0;
+const double kAFCacheArchiveDelay = 30.0; // archive every 30s
+
extern NSString* const UIApplicationWillResignActiveNotification;
@@ -211,6 +212,7 @@ - (void)reinitialize {
}
[self cancelAllClientItems];
+ _archiveInterval = kAFCacheArchiveDelay;
cacheEnabled = YES;
failOnStatusCodeAbove400 = YES;
self.cacheWithHashname = YES;
@@ -864,11 +866,13 @@ - (void)startArchiveThread:(NSTimer*)timer {
- (void)archive {
[archiveTimer invalidate];
- archiveTimer = [NSTimer scheduledTimerWithTimeInterval:kAFCacheArchiveDelay
- target:self
- selector:@selector(startArchiveThread:)
- userInfo:nil
- repeats:NO];
+ if ([self archiveInterval] > 0) {
+ archiveTimer = [NSTimer scheduledTimerWithTimeInterval:[self archiveInterval]
+ target:self
+ selector:@selector(startArchiveThread:)
+ userInfo:nil
+ repeats:NO];
+ }
wantsToArchive_ = YES;
}
@@ -21,9 +21,9 @@ - (AFCacheableItem*)newCacheableItemForFileAtPath:(NSString*)filepath lastModifi
NSURL *url;
NSString* escapedUrlString = [AFCacheableItem urlEncodeValue:filepath];
if (baseURL) {
- url = [[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@", baseURL, escapedUrlString]] retain];
+ url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@", baseURL, escapedUrlString]];
} else {
- url = [[NSURL URLWithString:[NSString stringWithFormat:@"afcpkg://localhost/%@", escapedUrlString]] retain];
+ url = [NSURL URLWithString:[NSString stringWithFormat:@"afcpkg://localhost/%@", escapedUrlString]];
}
NSDate *expireDate = nil;
if (maxAge) {
@@ -34,7 +34,6 @@ - (AFCacheableItem*)newCacheableItemForFileAtPath:(NSString*)filepath lastModifi
AFCacheableItem *item = [[AFCacheableItem alloc] initWithURL:url lastModified:lastModified expireDate:expireDate];
NSData *data = [NSData dataWithContentsOfMappedFile:completePathToFile];
[item setDataAndFile:data];
- [url release];
return item;
}
@@ -43,25 +42,25 @@ - (void)enumerateFilesInFolder:(NSString*)aFolder processHiddenFiles:(BOOL)proce
{
NSFileManager *localFileManager=[[NSFileManager alloc] init];
// A directory enumarator for iterating through a folder's files
- NSDirectoryEnumerator *dirEnum = [[localFileManager enumeratorAtPath:aFolder] retain];
+ NSDirectoryEnumerator *dirEnum = [localFileManager enumeratorAtPath:aFolder];
// write meta descriptions
for (NSString *file in dirEnum) {
// Create an inner autorelease pool, because we will create many objects in a loop
- NSAutoreleasePool *innerPool = [[NSAutoreleasePool alloc] init];
- NSDictionary *attributes = [dirEnum fileAttributes];
- NSString *fileType = [attributes objectForKey:NSFileType];
- BOOL hidden = [[file lastPathComponent] hasPrefix:@"."] || ([file rangeOfString:@"/."].location!=NSNotFound);
-
- if ([fileType isEqualToString:NSFileTypeRegular]) {
- if (!hidden || processHiddenFiles) {
- block(file, attributes);
- }
- }
- [innerPool drain];
- }
- [dirEnum release];
- [localFileManager release];
+ @autoreleasepool {
+
+
+ NSDictionary *attributes = [dirEnum fileAttributes];
+ NSString *fileType = [attributes objectForKey:NSFileType];
+ BOOL hidden = [[file lastPathComponent] hasPrefix:@"."] || ([file rangeOfString:@"/."].location!=NSNotFound);
+
+ if ([fileType isEqualToString:NSFileTypeRegular]) {
+ if (!hidden || processHiddenFiles) {
+ block(file, attributes);
+ }
+ }
+ }
+ }
}
/* ================================================================================================
@@ -134,17 +133,15 @@ - (BOOL)createPackageWithOptions:(NSDictionary*)options error:(NSError**)inError
BOOL ret = [zip CreateZipFile2:(outfile)?outfile:@"afcache-archive.zip"];
if (!ret) {
NSLog(@"Failed creating zip file.\n");
- success = NO;
- goto bailout;
+ return NO;
}
// Exit if given folder containing data doesn't exist
NSFileManager *localFileManager=[[NSFileManager alloc] init];
BOOL folderExists = [localFileManager fileExistsAtPath:folder];
if (!folderExists) {
NSLog(@"Folder '%s' does not exist. Aborting.\n", [folder cStringUsingEncoding:NSUTF8StringEncoding]);
- success = NO;
- goto bailout;
+ return NO;
}
if (json) {
[result appendFormat:@"{\n\"resources\":[\n"];
@@ -176,7 +173,6 @@ - (BOOL)createPackageWithOptions:(NSDictionary*)options error:(NSError**)inError
if (metaDescription) {
[metaDescriptions addObject:metaDescription];
}
- [item release];
}
}
@@ -195,11 +191,9 @@ - (BOOL)createPackageWithOptions:(NSDictionary*)options error:(NSError**)inError
if ([metaDescriptions count] == 0 && [userDataFolder length] == 0) {
printf("No input files. Aborting.\n");
- success = NO;
- goto bailout;
+ return NO;
}
- [localFileManager release];
[result appendFormat:@"baseURL = %@\n", baseURL];
// write meta descriptions into result string
@@ -214,7 +208,6 @@ - (BOOL)createPackageWithOptions:(NSDictionary*)options error:(NSError**)inError
}
i--;
}
- [metaDescriptions release];
if (json) {
[result appendString: @"]\n}"];
@@ -225,11 +218,10 @@ - (BOOL)createPackageWithOptions:(NSDictionary*)options error:(NSError**)inError
@catch (NSException * e) {
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:[e description] forKey:NSLocalizedDescriptionKey];
error = [NSError errorWithDomain:@"AFCache" code:99 userInfo:userInfo];
- success = NO;
- goto bailout;
+ return NO;
}
- // create manifest tmp file
+ // create manifest tmp file
const char *template = (char*)[[NSTemporaryDirectory() stringByAppendingPathComponent:@"AFCache.XXXXXX"] UTF8String];
char *buffer = strdup(template);
mktemp(buffer);
@@ -244,15 +236,12 @@ - (BOOL)createPackageWithOptions:(NSDictionary*)options error:(NSError**)inError
[error localizedFailureReason]]
forKey:NSLocalizedDescriptionKey];
error = [NSError errorWithDomain:@"AFCache" code:0 userInfo:userInfo];
- success = NO;
- goto bailout;
+ return NO;
}
[zip addFileToZip:manifestPath newname:@"manifest.afcache"];
// cleanup
- [zip release];
- [result release];
[[NSFileManager defaultManager] removeItemAtPath:manifestPath error:&error];
bailout:
return success;

0 comments on commit 924510c

Please sign in to comment.