Revision df003f06 pithos-macos/PithosLocalObjectState.m
b/pithos-macos/PithosLocalObjectState.m | ||
---|---|---|
41 | 41 |
#import "HashMapHash.h" |
42 | 42 |
|
43 | 43 |
@implementation PithosLocalObjectState |
44 |
@synthesize md5, hashMapHash, tmpDownloadFile, isDirectory, exists, hash;
|
|
44 |
@synthesize md5, hashMapHash, filePath, isDirectory, exists, hash;
|
|
45 | 45 |
|
46 | 46 |
#pragma mark - |
47 | 47 |
#pragma mark Object Lifecycle |
48 | 48 |
|
49 |
- (id)initWithFile:(NSString *)filePath blockHash:(NSString *)blockHash blockSize:(NSUInteger)blockSize {
|
|
49 |
- (id)initWithFile:(NSString *)aFilePath blockHash:(NSString *)blockHash blockSize:(NSUInteger)blockSize {
|
|
50 | 50 |
if ((self = [self init])) { |
51 |
self.filePath = aFilePath; |
|
51 | 52 |
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath isDirectory:&isDirectory] && !isDirectory) { |
52 |
self.md5 = (NSString *)FileMD5HashCreateWithPath((CFStringRef)filePath,
|
|
53 |
self.md5 = (NSString *)FileMD5HashCreateWithPath((CFStringRef)aFilePath,
|
|
53 | 54 |
FileHashDefaultChunkSizeForReadingData); |
54 | 55 |
self.hashMapHash = [HashMapHash calculateHashMapHash:[HashMapHash calculateObjectHashMap:filePath |
55 | 56 |
withBlockHash:blockHash |
... | ... | |
75 | 76 |
return [[[self alloc] init] autorelease]; |
76 | 77 |
} |
77 | 78 |
|
78 |
+ (id)localObjectStateWithFile:(NSString *)filePath blockHash:(NSString *)blockHash blockSize:(NSUInteger)blockSize {
|
|
79 |
return [[[self alloc] initWithFile:filePath blockHash:blockHash blockSize:blockSize] autorelease];
|
|
79 |
+ (id)localObjectStateWithFile:(NSString *)aFilePath blockHash:(NSString *)blockHash blockSize:(NSUInteger)blockSize {
|
|
80 |
return [[[self alloc] initWithFile:aFilePath blockHash:blockHash blockSize:blockSize] autorelease];
|
|
80 | 81 |
} |
81 | 82 |
|
82 | 83 |
+ (id)localObjectStateWithHash:(NSString *)aHash directory:(BOOL)anIsDirectory { |
... | ... | |
84 | 85 |
} |
85 | 86 |
|
86 | 87 |
- (void)dealloc { |
87 |
self.tmpDownloadFile = nil;
|
|
88 |
self.filePath = nil;
|
|
88 | 89 |
[hashMapHash release]; |
89 | 90 |
[md5 release]; |
90 | 91 |
[super dealloc]; |
91 | 92 |
} |
92 | 93 |
|
93 | 94 |
- (NSString *)description { |
94 |
return [NSString stringWithFormat:@"md5: %@, hashMapHash: %@, tmpDownloadFile: %@, isDirectory: %d",
|
|
95 |
md5, hashMapHash, tmpDownloadFile, isDirectory];
|
|
95 |
return [NSString stringWithFormat:@"md5: %@, hashMapHash: %@, filePath: %@, isDirectory: %d",
|
|
96 |
md5, hashMapHash, filePath, isDirectory];
|
|
96 | 97 |
} |
97 | 98 |
|
98 | 99 |
- (BOOL)isEqualToState:(PithosLocalObjectState *)aState { |
... | ... | |
121 | 122 |
if (isDirectory) { |
122 | 123 |
self.md5 = nil; |
123 | 124 |
self.hashMapHash = nil; |
124 |
self.tmpDownloadFile = nil;
|
|
125 |
self.filePath = nil;
|
|
125 | 126 |
} |
126 | 127 |
} |
127 | 128 |
|
128 |
- (void)setTmpDownloadFile:(NSString *)aTmpDownloadFile {
|
|
129 |
if (![tmpDownloadFile isEqualToString:aTmpDownloadFile]) {
|
|
130 |
if (!aTmpDownloadFile) {
|
|
129 |
- (void)setTmpDownloadFile:(NSString *)aFilePath {
|
|
130 |
if (![filePath isEqualToString:aFilePath]) {
|
|
131 |
if (!aFilePath) {
|
|
131 | 132 |
NSFileManager *fileManager = [NSFileManager defaultManager]; |
132 |
if ([fileManager fileExistsAtPath:tmpDownloadFile]) {
|
|
133 |
if ([fileManager fileExistsAtPath:filePath]) {
|
|
133 | 134 |
NSError *error = nil; |
134 |
if (![fileManager removeItemAtPath:tmpDownloadFile error:&error] || error)
|
|
135 |
if (![fileManager removeItemAtPath:filePath error:&error] || error)
|
|
135 | 136 |
[PithosUtilities fileActionFailedAlertWithTitle:@"Remove File Error" |
136 |
message:[NSString stringWithFormat:@"Cannot remove file at '%@'", tmpDownloadFile]
|
|
137 |
message:[NSString stringWithFormat:@"Cannot remove file at '%@'", filePath]
|
|
137 | 138 |
error:error]; |
138 | 139 |
} |
139 | 140 |
} |
140 |
[tmpDownloadFile release];
|
|
141 |
tmpDownloadFile = [aTmpDownloadFile retain];
|
|
141 |
[filePath release];
|
|
142 |
filePath = [aFilePath retain];
|
|
142 | 143 |
} |
143 | 144 |
} |
144 | 145 |
|
... | ... | |
170 | 171 |
if ((self = [super init])) { |
171 | 172 |
self.md5 = [decoder decodeObjectForKey:@"md5"]; |
172 | 173 |
self.hashMapHash = [decoder decodeObjectForKey:@"hashMapHash"]; |
173 |
self.tmpDownloadFile = [decoder decodeObjectForKey:@"tmpDownloadFile"];
|
|
174 |
self.filePath = [decoder decodeObjectForKey:@"filePath"];
|
|
174 | 175 |
self.isDirectory = [decoder decodeBoolForKey:@"isDirectory"]; |
175 | 176 |
} |
176 | 177 |
return self; |
... | ... | |
179 | 180 |
- (void)encodeWithCoder:(NSCoder *)encoder { |
180 | 181 |
[encoder encodeObject:md5 forKey:@"md5"]; |
181 | 182 |
[encoder encodeObject:hashMapHash forKey:@"hashMapHash"]; |
182 |
[encoder encodeObject:tmpDownloadFile forKey:@"tmpDownloadFile"];
|
|
183 |
[encoder encodeObject:filePath forKey:@"filePath"];
|
|
183 | 184 |
[encoder encodeBool:isDirectory forKey:@"isDirectory"]; |
184 | 185 |
} |
185 | 186 |
|
Also available in: Unified diff