#import "PithosLocalObjectState.h"
#import "PithosUtilities.h"
-#import "FileMD5Hash.h"
#import "HashMapHash.h"
@implementation PithosLocalObjectState
-@synthesize md5, hashMapHash, filePath, isDirectory, exists, hash, tmpFilePath;
+@synthesize filePath, isDirectory, exists, hash, tmpFilePath;
#pragma mark -
#pragma mark Object Lifecycle
if ((self = [self init])) {
self.filePath = aFilePath;
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath isDirectory:&isDirectory] && !isDirectory) {
- self.md5 = (NSString *)FileMD5HashCreateWithPath((CFStringRef)aFilePath,
- FileHashDefaultChunkSizeForReadingData);
- self.hashMapHash = [HashMapHash calculateHashMapHash:[HashMapHash calculateObjectHashMap:aFilePath
- withBlockHash:blockHash
- andBlockSize:blockSize]];
+ self.hash = [HashMapHash calculateHashMapHash:[HashMapHash calculateObjectHashMap:aFilePath
+ withBlockHash:blockHash
+ andBlockSize:blockSize]];
}
}
return self;
if ((self = [self init])) {
if (anIsDirectory)
isDirectory = YES;
- else if ([aHash length] == 32)
- self.md5 = aHash;
else if ([aHash length] == 64)
- self.hashMapHash = aHash;
+ self.hash = aHash;
}
return self;
}
- (void)dealloc {
self.tmpFilePath = nil;
[filePath release];
- [hashMapHash release];
- [md5 release];
+ [hash release];
[super dealloc];
}
- (NSString *)description {
- return [NSString stringWithFormat:@"md5: %@, hashMapHash: %@, filePath: %@, isDirectory: %d",
- md5, hashMapHash, filePath, isDirectory];
+ return [NSString stringWithFormat:@"hash: %@, filePath: %@, isDirectory: %d",
+ hash, filePath, isDirectory];
}
- (BOOL)isEqualToState:(PithosLocalObjectState *)aState {
// Object exists, while the other doesn't
return NO;
else
- // Both objects exist, check that they have at least one hash in common
- return ([self.md5 isEqualToString:aState.md5] || [self.hashMapHash isEqualToString:aState.hashMapHash]);
+ // Both objects exist, check that they have the same hash
+ return [self.hash isEqualToString:aState.hash];
}
#pragma mark -
- (void)setIsDirectory:(BOOL)anIsDirectory {
isDirectory = anIsDirectory;
if (isDirectory) {
- self.md5 = nil;
- self.hashMapHash = nil;
+ self.hash = nil;
self.tmpFilePath = nil;
}
}
}
- (BOOL)exists {
- return (isDirectory || md5 || hashMapHash);
-}
-
-- (NSString *)hash {
- if (hashMapHash)
- return hashMapHash;
- else
- return md5;
+ return (isDirectory || hash);
}
- (void)setHash:(NSString *)aHash {
- self.md5 = nil;
- self.hashMapHash = nil;
- if ([aHash length] == 32) {
- self.md5 = aHash;
- } else if ([aHash length] == 64) {
- self.hashMapHash = aHash;
- }
+ [hash release];
+ if ([aHash length] == 64)
+ hash = [aHash retain];
+ else
+ hash = nil;
}
#pragma mark -
- (id)initWithCoder:(NSCoder *)decoder {
if ((self = [super init])) {
- self.md5 = [decoder decodeObjectForKey:@"md5"];
- self.hashMapHash = [decoder decodeObjectForKey:@"hashMapHash"];
+ self.hash = [decoder decodeObjectForKey:@"hash"];
self.filePath = [decoder decodeObjectForKey:@"filePath"];
self.isDirectory = [decoder decodeBoolForKey:@"isDirectory"];
self.tmpFilePath = [decoder decodeObjectForKey:@"tmpFilePath"];
}
- (void)encodeWithCoder:(NSCoder *)encoder {
- [encoder encodeObject:md5 forKey:@"md5"];
- [encoder encodeObject:hashMapHash forKey:@"hashMapHash"];
+ [encoder encodeObject:hash forKey:@"hash"];
[encoder encodeObject:filePath forKey:@"filePath"];
[encoder encodeBool:isDirectory forKey:@"isDirectory"];
[encoder encodeObject:tmpFilePath forKey:@"tmpFilePath"];