/BEE.framework/BEE/BEEFileSystemObject.m
http://eeframework.googlecode.com/ · Objective C · 119 lines · 83 code · 25 blank · 11 comment · 7 complexity · 70b27eef96d6c89ea6b134e4ad59bbeb MD5 · raw file
- // -*- objc -*-
- #import "BEE/BEE.h"
- @implementation BEEFileSystemObject
- - (id)init
- {
- self = [super init];
-
- isArchived = YES;
- return self;
- }
- - (void)dealloc
- {
- RELEASE(_path);
- [super dealloc];
- }
- /* BEE specific */
- - (NSString *)path
- {
- return _path;
- }
- - (BOOL)isArchived
- {
- return isArchived;
- }
- - (void)setPath:(NSString *)path
- {
- NSFileManager *fm = [NSFileManager defaultManager];
- if(![path isAbsolutePath])
- {
- path = [[fm currentDirectoryPath] stringByAppendingFormat:@"/%@", [path stringByStandardizingPath]];
- }
- [self setShortName:[path lastPathComponent]];
- ASSIGN(_path, path);
- }
- - (void)backup
- {
- NSString *path = [NSString stringWithString:@"/"];
- NSString *pathPart;
- NSFileManager *fm = [NSFileManager defaultManager];
- BOOL isDir = NO;
- NSString *backupPath = [[self backupRoot] stringByAppendingString:_path];
- // NSString *incrPath = [[self incrementalRoot] stringByAppendingString:_path];
- NSEnumerator *en = [[backupPath pathComponents] objectEnumerator];
- while((pathPart = [en nextObject]))
- {
- if([pathPart isEqualToString:@"/"])
- {
- continue;
- }
- if([pathPart isEqualToString:[backupPath lastPathComponent]])
- {
- continue;
- }
-
- path = [path stringByAppendingFormat:@"%@/",pathPart];
- if(![fm fileExistsAtPath:path isDirectory:&isDir])
- {
- [fm createDirectoryAtPath:path attributes:nil];
- }
- else if(!isDir)
- {
- [NSException raise:NSGenericException
- format:@"The backup tree has been broken by an existing file suddenly"];
- }
- }
- if(isArchived)
- {
- [fm copyPath:_path toPath:backupPath handler:self];
- }
- }
- - (void)setArchived:(BOOL)flag
- {
- isArchived = YES;
- }
- @end /* BEEFileSystemObject */
- @implementation BEEFileSystemObject ( NSFileManagerDelegate )
- - (void)fileManager:(NSFileManager *)manager willProcessPath:(NSString *)path
- {
- /*
- if(!([_path isEqualToString:path]))
- {
- NSLog(@"my path %@", _path);
- NSLog(@"%@", path);
- [NSException raise:NSInvalidArgumentException format:@"That's not my path"];
- }
- */
- }
- - (BOOL)fileManager:(NSFileManager *)manager
- shouldProceedAfterError:(NSDictionary *)errorInfo
- {
- NSLog(@"Something wrong with paths. Please check:");
- NSLog(@"%@",[self path]);
- NSLog(@"%@",[[self backupRoot] stringByAppendingString:[self path]]);
- return NO;
- }
- @end /* BEEFileSystemObject ( NSFileManagerDelegate ) */