Skip to content

Commit

Permalink
Add methods for registering repositories with PMPackageManager
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Nowicki <sebnow@gmail.com>
  • Loading branch information
sebnow committed Dec 22, 2008
1 parent 8fdd806 commit b3329ad
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
9 changes: 8 additions & 1 deletion PMPackageManager.h
Expand Up @@ -22,10 +22,13 @@

#import <Foundation/Foundation.h>

@class PMRepository;

@interface PMPackageManager : NSObject {
NSString *_rootDirectory;
NSString *_databasePath;
NSMutableArray *_cacheDirectories;
NSMutableArray *_repositories;
}

+ (PMPackageManager *) sharedManager;
Expand All @@ -38,5 +41,9 @@
- (NSArray *) cacheDirectories;
- (void) addCacheDirectory:(NSString *)thePath;
- (void) removeCacheDirectory:(NSString *)thePath;

- (PMRepository *) repositoryByRegisteringWithName:(NSString *)aName servers:(NSArray *)servers;
- (void) addRepository:(PMRepository *)aRepository;
- (void) removeRepository:(PMRepository *)aRepository;
- (NSArray *) repositories;
- (void) refreshRepositories;
@end
37 changes: 37 additions & 0 deletions PMPackageManager.m
Expand Up @@ -22,6 +22,7 @@

#import "PMPackageManager.h"
#import <alpm.h>
#import "PMRepository.h"

static PMPackageManager *_sharedManager = nil;

Expand Down Expand Up @@ -61,6 +62,7 @@ - (id) init
self = [super init];
if(self != nil) {
_cacheDirectories = [NSMutableArray new];
_repositories = [NSMutableArray new];
}
return self;
}
Expand Down Expand Up @@ -135,6 +137,11 @@ - (NSArray *)cacheDirectories
return [NSArray arrayWithArray:_cacheDirectories];
}

- (NSArray *) repositories
{
return _repositories;
}

#pragma mark Public methods

+ (void) initialize
Expand All @@ -161,4 +168,34 @@ - (void) removeCacheDirectory:(NSString *)thePath
}
}

- (PMRepository *) repositoryByRegisteringWithName:(NSString *)aName servers:(NSArray *)servers;
{
PMRepository *repository;
repository = [[PMRepository alloc] initWithName:aName servers:servers];
[_repositories addObject:repository];
return [repository autorelease];
}

- (void) addRepository:(PMRepository *)aRepository
{
[_repositories addObject:aRepository];
}

- (void) removeRepository:(PMRepository *)aRepository
{
[_repositories removeObject:aRepository];
}

- (void) refreshRepositories
{
alpm_list_t *node;
alpm_trans_init(PM_TRANS_TYPE_SYNC, 0, NULL, NULL, NULL);
node = alpm_option_get_syncdbs();
while(node != NULL) {
alpm_db_update(0, alpm_list_getdata(node));
node = alpm_list_next(node);
}
alpm_trans_release();
}

@end

0 comments on commit b3329ad

Please sign in to comment.