mirror of
https://github.com/samsonjs/arq_restore.git
synced 2026-03-25 09:25:53 +00:00
added an option to specify a path within the folder to restore
This commit is contained in:
parent
3bd7f247c9
commit
cc41a6552d
2 changed files with 44 additions and 10 deletions
|
|
@ -431,7 +431,7 @@
|
|||
}
|
||||
|
||||
- (BOOL)restore:(NSArray *)args error:(NSError **)error {
|
||||
if ([args count] != 5) {
|
||||
if ([args count] != 5 && [args count] != 6) {
|
||||
SETNSERROR([self errorDomain], ERROR_USAGE, @"invalid arguments");
|
||||
return NO;
|
||||
}
|
||||
|
|
@ -490,7 +490,40 @@
|
|||
return NO;
|
||||
}
|
||||
|
||||
NSString *destinationPath = [[[NSFileManager defaultManager] currentDirectoryPath] stringByAppendingPathComponent:[[matchingBucket localPath] lastPathComponent]];
|
||||
BlobKey *treeBlobKey = [commit treeBlobKey];
|
||||
NSString *nodeName = nil;
|
||||
if ([args count] == 6) {
|
||||
NSString *path = [args objectAtIndex:5];
|
||||
if ([path hasPrefix:@"/"]) {
|
||||
path = [path substringFromIndex:1];
|
||||
}
|
||||
NSArray *pathComponents = [path pathComponents];
|
||||
for (NSUInteger index = 0; index < [pathComponents count]; index++) {
|
||||
NSString *component = [pathComponents objectAtIndex:index];
|
||||
Tree *childTree = [repo treeForBlobKey:treeBlobKey error:error];
|
||||
if (childTree == nil) {
|
||||
return NO;
|
||||
}
|
||||
Node *childNode = [childTree childNodeWithName:component];
|
||||
if (childNode == nil) {
|
||||
SETNSERROR([self errorDomain], ERROR_NOT_FOUND, @"path component '%@' not found", component);
|
||||
return NO;
|
||||
}
|
||||
if (![childNode isTree] && index < ([pathComponents count] - 1)) {
|
||||
// If it's a directory and we're not at the end of the path, fail.
|
||||
SETNSERROR([self errorDomain], -1, @"'%@' is not a directory", component);
|
||||
return NO;
|
||||
}
|
||||
if ([childNode isTree]) {
|
||||
treeBlobKey = [childNode treeBlobKey];
|
||||
} else {
|
||||
nodeName = component;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NSString *restoreFileName = [args count] == 6 ? [[args objectAtIndex:5] lastPathComponent] : [[matchingBucket localPath] lastPathComponent];
|
||||
NSString *destinationPath = [[[NSFileManager defaultManager] currentDirectoryPath] stringByAppendingPathComponent:restoreFileName];
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath:destinationPath]) {
|
||||
SETNSERROR([self errorDomain], -1, @"%@ already exists", destinationPath);
|
||||
return NO;
|
||||
|
|
@ -511,8 +544,9 @@
|
|||
commitBlobKey:commitBlobKey
|
||||
rootItemName:[[matchingBucket localPath] lastPathComponent]
|
||||
treeVersion:CURRENT_TREE_VERSION
|
||||
treeBlobKey:[commit treeBlobKey]
|
||||
nodeName:nil targetUID:getuid()
|
||||
treeBlobKey:treeBlobKey
|
||||
nodeName:nodeName
|
||||
targetUID:getuid()
|
||||
targetGID:getgid()
|
||||
useTargetUIDAndGID:YES
|
||||
destinationPath:destinationPath
|
||||
|
|
@ -527,8 +561,8 @@
|
|||
commitBlobKey:commitBlobKey
|
||||
rootItemName:[[matchingBucket localPath] lastPathComponent]
|
||||
treeVersion:CURRENT_TREE_VERSION
|
||||
treeBlobKey:[commit treeBlobKey]
|
||||
nodeName:nil
|
||||
treeBlobKey:treeBlobKey
|
||||
nodeName:nodeName
|
||||
targetUID:getuid()
|
||||
targetGID:getgid()
|
||||
useTargetUIDAndGID:YES
|
||||
|
|
@ -542,8 +576,8 @@
|
|||
commitBlobKey:commitBlobKey
|
||||
rootItemName:[[matchingBucket localPath] lastPathComponent]
|
||||
treeVersion:CURRENT_TREE_VERSION
|
||||
treeBlobKey:[commit treeBlobKey]
|
||||
nodeName:nil
|
||||
treeBlobKey:treeBlobKey
|
||||
nodeName:nodeName
|
||||
targetUID:getuid()
|
||||
targetGID:getgid()
|
||||
useTargetUIDAndGID:YES
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ static void printUsage(const char *exeName) {
|
|||
fprintf(stderr, "\t%s [-l loglevel] listfolders <target_nickname> <computer_uuid>\n", exeName);
|
||||
fprintf(stderr, "\t%s [-l loglevel] printplist <target_nickname> <computer_uuid> <folder_uuid>\n", exeName);
|
||||
fprintf(stderr, "\t%s [-l loglevel] listtree <target_nickname> <computer_uuid> <folder_uuid>\n", exeName);
|
||||
fprintf(stderr, "\t%s [-l loglevel] restore <target_nickname> <computer_uuid> <folder_uuid>\n", exeName);
|
||||
fprintf(stderr, "\t%s [-l loglevel] restore <target_nickname> <computer_uuid> <folder_uuid> [relative_path]\n", exeName);
|
||||
fprintf(stderr, "\t%s [-l loglevel] clearcache <target_nickname>\n", exeName);
|
||||
fprintf(stderr, "\n");
|
||||
fprintf(stderr, "log levels: none, error, warn, info, and debug\n");
|
||||
|
|
|
|||
Loading…
Reference in a new issue