Skip to content

Commit

Permalink
fixed arc compile errors, archiveInterval now configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
artifacts committed Nov 12, 2013
1 parent e367713 commit 924510c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 40 deletions.
1 change: 1 addition & 0 deletions src/shared/AFCache.h
Expand Up @@ -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;


/*
Expand Down
16 changes: 10 additions & 6 deletions src/shared/AFCache.m
Expand Up @@ -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;

Expand Down Expand Up @@ -211,6 +212,7 @@ - (void)reinitialize {
}
[self cancelAllClientItems];

_archiveInterval = kAFCacheArchiveDelay;
cacheEnabled = YES;
failOnStatusCodeAbove400 = YES;
self.cacheWithHashname = YES;
Expand Down Expand Up @@ -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;
}

Expand Down
57 changes: 23 additions & 34 deletions src/shared/AFCachePackageCreator.m
Expand Up @@ -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) {
Expand All @@ -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;
}

Expand All @@ -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);
}
}
}
}
}

/* ================================================================================================
Expand Down Expand Up @@ -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"];
Expand Down Expand Up @@ -176,7 +173,6 @@ - (BOOL)createPackageWithOptions:(NSDictionary*)options error:(NSError**)inError
if (metaDescription) {
[metaDescriptions addObject:metaDescription];
}
[item release];
}
}

Expand All @@ -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
Expand All @@ -214,7 +208,6 @@ - (BOOL)createPackageWithOptions:(NSDictionary*)options error:(NSError**)inError
}
i--;
}
[metaDescriptions release];

if (json) {
[result appendString: @"]\n}"];
Expand All @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 924510c

Please sign in to comment.