Skip to content

Commit 306d065

Browse files
author
Hiroshi Hashiguchi
committed
temporary
1 parent 8272d60 commit 306d065

18 files changed

Lines changed: 117 additions & 12 deletions

FBFileCache.xcodeproj/project.pbxproj

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
4CE0E70F13267765002068A5 /* FBFileCacheManagerTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C2D7F6A131DEA1F000A76E3 /* FBFileCacheManagerTestCase.m */; };
5252
4CEB760113557B5B00329EF5 /* FBLockManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CEB760013557B5B00329EF5 /* FBLockManager.m */; };
5353
4CEB760213557B5B00329EF5 /* FBLockManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CEB760013557B5B00329EF5 /* FBLockManager.m */; };
54+
4CEB7632135BAC7300329EF5 /* TODO.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 4CEB7631135BAC7300329EF5 /* TODO.rtf */; };
5455
/* End PBXBuildFile section */
5556

5657
/* Begin PBXContainerItemProxy section */
@@ -92,6 +93,18 @@
9293
4C094BE9131DB5480019ACAF /* FBFileCacheTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "FBFileCacheTests-Info.plist"; sourceTree = "<group>"; };
9394
4C094BEB131DB5480019ACAF /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
9495
4C094BED131DB5480019ACAF /* FBFileCacheTests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "FBFileCacheTests-Prefix.pch"; sourceTree = "<group>"; };
96+
4C1B1B88142B12B9005E0EE1 /* IMG_0384.JPG */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = IMG_0384.JPG; sourceTree = "<group>"; };
97+
4C1B1B89142B12B9005E0EE1 /* IMG_0488.JPG */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = IMG_0488.JPG; sourceTree = "<group>"; };
98+
4C1B1B8A142B12B9005E0EE1 /* IMG_0766.JPG */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = IMG_0766.JPG; sourceTree = "<group>"; };
99+
4C1B1B8B142B12B9005E0EE1 /* IMG_0854.JPG */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = IMG_0854.JPG; sourceTree = "<group>"; };
100+
4C1B1B8C142B12B9005E0EE1 /* IMG_0873.JPG */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = IMG_0873.JPG; sourceTree = "<group>"; };
101+
4C1B1B8D142B12B9005E0EE1 /* IMG_0944.JPG */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = IMG_0944.JPG; sourceTree = "<group>"; };
102+
4C1B1B8E142B12B9005E0EE1 /* IMG_1017.JPG */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = IMG_1017.JPG; sourceTree = "<group>"; };
103+
4C1B1B8F142B12B9005E0EE1 /* IMG_1114.JPG */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = IMG_1114.JPG; sourceTree = "<group>"; };
104+
4C1B1B90142B12B9005E0EE1 /* IMG_1167.JPG */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = IMG_1167.JPG; sourceTree = "<group>"; };
105+
4C1B1B91142B12B9005E0EE1 /* IMG_1197.JPG */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = IMG_1197.JPG; sourceTree = "<group>"; };
106+
4C1B1B92142B12B9005E0EE1 /* IMG_1201.JPG */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = IMG_1201.JPG; sourceTree = "<group>"; };
107+
4C1B1B93142B12B9005E0EE1 /* list.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = list.txt; sourceTree = "<group>"; };
95108
4C2D7F56131DC243000A76E3 /* FBCachedFile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FBCachedFile.h; sourceTree = "<group>"; };
96109
4C2D7F57131DC243000A76E3 /* FBCachedFile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FBCachedFile.m; sourceTree = "<group>"; };
97110
4C2D7F59131DD758000A76E3 /* FBCachedFileTestCase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FBCachedFileTestCase.h; sourceTree = "<group>"; };
@@ -114,6 +127,7 @@
114127
4C799BE3131E146B00AB4CA7 /* image-00.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "image-00.png"; sourceTree = "<group>"; };
115128
4CEB75FF13557B5B00329EF5 /* FBLockManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FBLockManager.h; sourceTree = "<group>"; };
116129
4CEB760013557B5B00329EF5 /* FBLockManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FBLockManager.m; sourceTree = "<group>"; };
130+
4CEB7631135BAC7300329EF5 /* TODO.rtf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.rtf; path = TODO.rtf; sourceTree = "<group>"; };
117131
/* End PBXFileReference section */
118132

119133
/* Begin PBXFrameworksBuildPhase section */
@@ -145,6 +159,8 @@
145159
4C094BB2131DB5480019ACAF = {
146160
isa = PBXGroup;
147161
children = (
162+
4CEB7631135BAC7300329EF5 /* TODO.rtf */,
163+
4C1B1B87142B12B9005E0EE1 /* Sample Images */,
148164
4C2D7F53131DC19F000A76E3 /* FBFileCache */,
149165
4C094BC7131DB5480019ACAF /* Sample Application */,
150166
4C094BE7131DB5480019ACAF /* FBFileCacheTests */,
@@ -241,6 +257,26 @@
241257
name = "Supporting Files";
242258
sourceTree = "<group>";
243259
};
260+
4C1B1B87142B12B9005E0EE1 /* Sample Images */ = {
261+
isa = PBXGroup;
262+
children = (
263+
4C1B1B88142B12B9005E0EE1 /* IMG_0384.JPG */,
264+
4C1B1B89142B12B9005E0EE1 /* IMG_0488.JPG */,
265+
4C1B1B8A142B12B9005E0EE1 /* IMG_0766.JPG */,
266+
4C1B1B8B142B12B9005E0EE1 /* IMG_0854.JPG */,
267+
4C1B1B8C142B12B9005E0EE1 /* IMG_0873.JPG */,
268+
4C1B1B8D142B12B9005E0EE1 /* IMG_0944.JPG */,
269+
4C1B1B8E142B12B9005E0EE1 /* IMG_1017.JPG */,
270+
4C1B1B8F142B12B9005E0EE1 /* IMG_1114.JPG */,
271+
4C1B1B90142B12B9005E0EE1 /* IMG_1167.JPG */,
272+
4C1B1B91142B12B9005E0EE1 /* IMG_1197.JPG */,
273+
4C1B1B92142B12B9005E0EE1 /* IMG_1201.JPG */,
274+
4C1B1B93142B12B9005E0EE1 /* list.txt */,
275+
);
276+
name = "Sample Images";
277+
path = "Sample Application/Images";
278+
sourceTree = "<group>";
279+
};
244280
4C2D7F53131DC19F000A76E3 /* FBFileCache */ = {
245281
isa = PBXGroup;
246282
children = (
@@ -327,6 +363,7 @@
327363
4C094BCC131DB5480019ACAF /* InfoPlist.strings in Resources */,
328364
4C094BD5131DB5480019ACAF /* MainWindow.xib in Resources */,
329365
4C094BDB131DB5480019ACAF /* RootViewController.xib in Resources */,
366+
4CEB7632135BAC7300329EF5 /* TODO.rtf in Resources */,
330367
);
331368
runOnlyForDeploymentPostprocessing = 0;
332369
};

FBFileCache/FBCachedFile.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99
#import <Foundation/Foundation.h>
1010

1111

12-
@interface FBCachedFile : NSObject {
13-
14-
NSURL* url_;
15-
}
12+
@interface FBCachedFile : NSObject
1613

1714
@property (readonly) NSString* path;
1815
@property (nonatomic, retain, readonly) NSURL* URL;

FBFileCache/FBFileCacheManager.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#import <Foundation/Foundation.h>
1010

11-
#define FBFileCachManager_VERSION @"0.90"
11+
#define FBFileCachManager_VERSION @"1.00"
1212

1313
@class FBCachedFile;
1414
@class FBLockManager;
@@ -26,6 +26,8 @@
2626
NSUInteger count_;
2727

2828
FBLockManager* lockManager_;
29+
30+
BOOL fileProtectionEnabled_;
2931
}
3032

3133
#pragma mark -
@@ -37,7 +39,7 @@
3739
@property (assign, readonly) NSUInteger count;
3840
@property (assign, readonly) NSUInteger size;
3941
@property (assign) BOOL includingParameters;
40-
42+
@property (assign) BOOL fileProtectionEnabled;
4143

4244
// Initializing a New Object
4345
- (id)initWithSize:(NSUInteger)size;

FBFileCache/FBFileCacheManager.m

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ @implementation FBFileCacheManager
4343

4444
@synthesize lockManager = lockManager_;
4545

46+
@synthesize fileProtectionEnabled = fileProtectionEnabled_;
47+
4648
#pragma mark -
4749
#pragma mark Private
4850
- (NSString*)_hashStringFromURL:(NSURL*)url
@@ -196,6 +198,7 @@ - (id)initWithPath:(NSString*)path size:(NSUInteger)size
196198
self.path = path;
197199
[self resizeTo:size];
198200
self.includingParameters = YES;
201+
self.fileProtectionEnabled = NO;
199202
[self reload];
200203
}
201204
return self;
@@ -260,14 +263,24 @@ - (FBCachedFile*)putFile:(NSString*)contentFilePath forURL:(NSURL*)sourceURL
260263
block:^BOOL(NSString* cachedFilePath) {
261264
NSFileManager* fileManager = [NSFileManager defaultManager];
262265
NSError* error = nil;
263-
if ([fileManager copyItemAtPath:contentFilePath
266+
if (![fileManager copyItemAtPath:contentFilePath
264267
toPath:cachedFilePath
265268
error:&error]) {
266-
return YES;
267-
} else {
268269
NSLog(@"%s|[ERROR] %@", __PRETTY_FUNCTION__, error);
269270
return NO;
270-
}
271+
}
272+
if (self.fileProtectionEnabled) {
273+
NSDictionary* attributes =
274+
[NSDictionary dictionaryWithObject:NSFileProtectionComplete
275+
forKey:NSFileProtectionKey];
276+
if (![fileManager setAttributes:attributes
277+
ofItemAtPath:cachedFilePath
278+
error:&error]) {
279+
NSLog(@"%s|[ERROR] %@", __PRETTY_FUNCTION__, error);
280+
return NO;
281+
}
282+
}
283+
return YES;
271284
}];
272285

273286
//
@@ -291,7 +304,7 @@ - (FBCachedFile*)putData:(NSData*)contentData forURL:(NSURL*)sourceURL
291304
// [3] copy the file to cahced file
292305
NSError* error = nil;
293306
if ([contentData writeToFile:cachedFilePath
294-
options:NSDataWritingAtomic
307+
options:NSDataWritingAtomic | (self.fileProtectionEnabled?NSDataWritingFileProtectionComplete:NSDataWritingFileProtectionNone)
295308
error:&error]) {
296309
return YES;
297310
} else {

FBFileCacheTests/FBFileCacheManagerTestCase.m

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ - (void)testInitWhenResume
239239
STAssertEquals(manager2.usingSize, [self usingSize], nil);
240240
}
241241

242-
243242
//
244243
// put
245244
//
@@ -661,8 +660,44 @@ - (void)testCacheHitRate
661660
STAssertEquals(self.fileCacheManager.cacheHitRate, 0.0f, nil);
662661
}
663662

663+
- (void)testFileProtectionEnabled
664+
{
665+
// setup files
666+
[self setupTemporary];
667+
[self putAllTestFilesWithManager:self.fileCacheManager];
668+
669+
for (int i=0; i < TEST_IMAGE_NUM; i++) {
670+
NSString* filename = [NSString stringWithFormat:@"image-%02d.png", i];
671+
NSURL* url = [NSURL URLWithString:filename relativeToURL:self.baseURL];
672+
FBCachedFile* cachedFile = [self.fileCacheManager cachedFileForURL:url];
673+
NSError* error = nil;
674+
NSDictionary* attributes = [[NSFileManager defaultManager]
675+
attributesOfItemAtPath:cachedFile.path
676+
error:&error];
677+
NSLog(@"%@", attributes);
678+
STAssertEquals([attributes objectForKey:NSFileProtectionKey], NSFileProtectionNone, nil);
679+
}
680+
681+
self.fileCacheManager.fileProtectionEnabled = YES;
682+
[self putAllTestFilesWithManager:self.fileCacheManager];
683+
684+
for (int i=0; i < TEST_IMAGE_NUM; i++) {
685+
NSString* filename = [NSString stringWithFormat:@"image-%02d.png", i];
686+
NSURL* url = [NSURL URLWithString:filename relativeToURL:self.baseURL];
687+
FBCachedFile* cachedFile = [self.fileCacheManager cachedFileForURL:url];
688+
NSError* error = nil;
689+
NSDictionary* attributes = [[NSFileManager defaultManager]
690+
attributesOfItemAtPath:cachedFile.path
691+
error:&error];
692+
STAssertEquals([attributes objectForKey:NSFileProtectionKey], NSFileProtectionComplete, nil);
693+
}
694+
}
695+
696+
664697

698+
//
665699
// test reload
700+
//
666701
- (void)testReload
667702
{
668703
[self setupTemporary];
1.17 MB
Loading
1.25 MB
Loading
1.16 MB
Loading
1.18 MB
Loading
1.12 MB
Loading

0 commit comments

Comments
 (0)