Skip to content

Commit

Permalink
Re-implement listing archives again
Browse files Browse the repository at this point in the history
This now works for both password-protected and non-passworded keyfiles
  • Loading branch information
pieter committed Aug 27, 2011
1 parent 6d89b5f commit 26b0245
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
5 changes: 5 additions & 0 deletions Tarsnap GUI/TSGBackup.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ - (void)dealloc
[super dealloc];
}

- (NSString *)description;
{
return [NSString stringWithFormat:@"<%@: %p, name: %@, dateCreated: %@>", [self class], self, self.name, self.dateCreated];
}

@end
10 changes: 10 additions & 0 deletions Tarsnap GUI/TSGDocument.m
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,14 @@ - (void)tarsnapKey:(TSGTarsnapKey *)theKey acceptedPassword:(BOOL)theAcceptedPas
}
}

- (void)tarsnapKey:(TSGTarsnapKey *)theKey foundArchive:(TSGBackup *)theArchive;
{
self.backups = [self.backups arrayByAddingObject:theArchive];
}

- (void)tarsnapKeyFinishedListingArchives:(TSGTarsnapKey *)theKey;
{
self.loading = NO;
}

@end
11 changes: 3 additions & 8 deletions Tarsnap GUI/TSGListArchivesCommand.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,14 @@ - (void)tarsnapDidSendError:(NSNotification *)theNotification;
NSString *errorString = [[[NSString alloc] initWithData:data encoding:NSISOLatin1StringEncoding] autorelease]; // Chose latin1 because it supports all data
if (errorString && [errorString length] > 0) {
NSLog(@"Received an error: %@", errorString);
if ([errorString hasPrefix:@"Please enter passphrase for keyfile"]) {
NSLog(@"The warning asks for a password! Handle: %@", self.task.standardInput);
// [[(NSPipe *)self.task.standardInput fileHandleForWriting] writeData:outData];

}
}

}

- (void)tarsnapDidFinish:(NSNotification *)theNotification;
{
NSData *theData = [[theNotification userInfo] objectForKey:NSFileHandleNotificationDataItem];
NSString *dataAsString = [[[NSString alloc] initWithData:theData encoding:NSUTF8StringEncoding] autorelease];
NSString *dataAsString = [[[NSString alloc] initWithData:theData encoding:NSISOLatin1StringEncoding] autorelease];
// FIXME: handle potential errors here, such as not conforming to NSUTF8StringEncoding

NSArray *items = [dataAsString componentsSeparatedByString:@"\n"];
Expand All @@ -75,9 +70,9 @@ - (void)tarsnapDidFinish:(NSNotification *)theNotification;
NSString *dateStr = [components objectAtIndex:1];
NSDate *date = [NSDate dateWithNaturalLanguageString:dateStr];
TSGBackup *backupItem = [TSGBackup backupWithName:name date:date];

NSLog(@"Found archive: %@", backupItem);
[self.key command:self foundArchive:backupItem];
}
[self.key commandFinishedListingArchives:self];
}

@end
6 changes: 6 additions & 0 deletions Tarsnap GUI/TSGTarsnapKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

@protocol TSGTarsnapKeyDelegate;
@class TSGTarsnapCommand;
@class TSGBackup;

@interface TSGTarsnapKey : NSObject

Expand All @@ -29,9 +30,14 @@
- (void)tarsnapKey:(TSGTarsnapKey *)theKey requiresPassword:(BOOL)theRequiresPassword;
- (void)tarsnapKey:(TSGTarsnapKey *)theKey acceptedPassword:(BOOL)theAcceptedPassword;

- (void)tarsnapKey:(TSGTarsnapKey *)theKey foundArchive:(TSGBackup *)theArchive;
- (void)tarsnapKeyFinishedListingArchives:(TSGTarsnapKey *)theKey;
@end

@interface TSGTarsnapKey (InternalCallbacks)
- (void)command:(TSGTarsnapCommand *)theCommand determinedPasswordRequired:(BOOL)thePasswordRequired;
- (void)command:(TSGTarsnapCommand *)theCommand determinedPasswordValid:(BOOL)thePasswordValid;

- (void)command:(TSGTarsnapCommand *)theCommand foundArchive:(TSGBackup *)theArchive;
- (void)commandFinishedListingArchives:(TSGTarsnapCommand *)theCommand;
@end
10 changes: 10 additions & 0 deletions Tarsnap GUI/TSGTarsnapKey.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,14 @@ - (void)command:(TSGTarsnapCommand *)theCommand determinedPasswordValid:(BOOL)th
{
[self.delegate tarsnapKey:self acceptedPassword:thePasswordValid];
}

- (void)command:(TSGTarsnapCommand *)theCommand foundArchive:(TSGBackup *)theArchive;
{
[self.delegate tarsnapKey:self foundArchive:theArchive];
}
- (void)commandFinishedListingArchives:(TSGTarsnapCommand *)theCommand;
{
[self.delegate tarsnapKeyFinishedListingArchives:self];
}

@end

0 comments on commit 26b0245

Please sign in to comment.