Monotone-Parent: 1cab635a2c57c6953c8a393b67f593bdaccb43b9

Monotone-Revision: 97bd3b4f7ef7920ded0314bd1d5eadce2a2af62a

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2009-08-14T19:17:53
Monotone-Branch: ca.inverse.sogo
maint-2.0.2
Wolfgang Sourdeau 2009-08-14 19:17:53 +00:00
parent 584c3cae01
commit bd43877c6b
2 changed files with 31 additions and 28 deletions

View File

@ -1,5 +1,8 @@
2009-08-14 Wolfgang Sourdeau <wsourdeau@inverse.ca> 2009-08-14 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* Tools/SOGoToolBackup.m (-parseArguments): modified to either
accept "ALL" or a list of identifiers as arguments.
* Tools/SOGoToolRestore.m: new "sogo-tool" utility that restores * Tools/SOGoToolRestore.m: new "sogo-tool" utility that restores
the specified user data previously created by the "backup" the specified user data previously created by the "backup"
command. command.

View File

@ -79,7 +79,7 @@
- (void) usage - (void) usage
{ {
fprintf (stderr, "backup directory user|ALL\n\n" fprintf (stderr, "backup directory ALL|user1 [user2] ...\n\n"
" folder the folder where backup files will be stored\n" " folder the folder where backup files will be stored\n"
" user the user of whom to save the data\n"); " user the user of whom to save the data\n");
} }
@ -116,51 +116,51 @@
return rc; return rc;
} }
- (BOOL) fetchUserIDs: (NSString *) identifier - (BOOL) fetchUserIDs: (NSArray *) users
{ {
BOOL rc;
LDAPUserManager *lm; LDAPUserManager *lm;
NSDictionary *infos; NSDictionary *infos;
NSString *userID; NSString *user;
NSArray *allUsers; id allUsers;
int count, max;
lm = [LDAPUserManager sharedUserManager]; lm = [LDAPUserManager sharedUserManager];
if ([identifier isEqualToString: @"ALL"]) max = [users count];
{ user = [users objectAtIndex: 0];
rc = YES; if (max == 1 && [user isEqualToString: @"ALL"])
allUsers = [lm fetchUsersMatching: @"."]; allUsers = [lm fetchUsersMatching: @"."];
ASSIGN (userIDs, [allUsers objectsForKey: @"c_uid"
notFoundMarker: nil]);
}
else else
{ {
infos = [lm contactInfosForUserWithUIDorEmail: identifier]; allUsers = [NSMutableArray array];
userID = [infos objectForKey: @"c_uid"]; for (count = 0; count < max; count++)
if (userID)
{ {
rc = YES; user = [users objectAtIndex: count];
ASSIGN (userIDs, [NSArray arrayWithObject: userID]); infos = [lm contactInfosForUserWithUIDorEmail: user];
} if (infos)
else [allUsers addObject: infos];
{ else
rc = NO; NSLog (@"user '%@' unknown", user);
NSLog (@"user '%@' not found", identifier);
} }
} }
return rc; ASSIGN (userIDs, [allUsers objectsForKey: @"c_uid" notFoundMarker: nil]);
return ([userIDs count] > 0);
} }
- (BOOL) parseArguments - (BOOL) parseArguments
{ {
BOOL rc; BOOL rc;
NSString *identifier; NSRange rest;
int max;
if ([arguments count] > 1) max = [arguments count];
if (max > 1)
{ {
ASSIGN (directory, [arguments objectAtIndex: 0]); ASSIGN (directory, [arguments objectAtIndex: 0]);
identifier = [arguments objectAtIndex: 1]; rest = NSMakeRange (1, max - 1);
rc = ([self checkDirectory] && [self fetchUserIDs: identifier]); rc = ([self checkDirectory]
&& [self fetchUserIDs: [arguments subarrayWithRange: rest]]);
} }
else else
{ {
@ -287,7 +287,7 @@
{ {
folder = [NSString stringWithFormat: @"%@/%@", folder = [NSString stringWithFormat: @"%@/%@",
basePath, [folders objectAtIndex: count]]; basePath, [folders objectAtIndex: count]];
NSLog (@"folder %d: %@", count, folder); // NSLog (@"folder %d: %@", count, folder);
[self extractFolder: folder withFM: fm [self extractFolder: folder withFM: fm
intoRecord: tables]; intoRecord: tables];
} }