NSException *error;
NSString *sql;
- if ([[self performSQL: [NSString stringWithFormat: @"SELECT * FROM %@"
- @" WHERE c_path = '%@'",
- [self folderInfoTableName], _path]]
- isNotEmpty]) {
+ // TBD: fix SQL injection issue!
+ sql = [NSString stringWithFormat: @"SELECT * FROM %@ WHERE c_path = '%@'",
+ [self folderInfoTableName], _path];
+ if ([[self performSQL: sql] isNotEmpty]) {
return [NSException exceptionWithName:@"GCSExitingFolder"
reason:@"a folder already exists at that path"
userInfo:nil];
reason:@"could not open channel"
userInfo:nil];
}
-
+
tableName = [self baseTableNameForFolderAtPath: _path];
baseURL
= [[folderInfoLocation absoluteString] stringByDeletingLastPathComponent];
tableName = [self finalizedTableNameForBaseName: tableName
atBaseURL: baseURL withChannel: channel];
- quickTableName = [NSString stringWithFormat: @"%@_quick", tableName];
- aclTableName = [NSString stringWithFormat: @"%@_acl", tableName];
-
+ quickTableName = [tableName stringByAppendingString: @"_quick"];
+ aclTableName = [tableName stringByAppendingString: @"_acl"];
+
+ sql = [@"DROP TABLE " stringByAppendingString:quickTableName];
+ if ((error = [channel evaluateExpressionX:sql]) != nil)
+ ; // 'DROP TABLE' is allowed to fail (DROP IF EXISTS is not in PG<8.2)
+
sql = [@"DROP TABLE " stringByAppendingString:tableName];
if ((error = [channel evaluateExpressionX:sql]) != nil)
- return error;
+ ; // 'DROP TABLE' is allowed to fail (DROP IF EXISTS is not in PG<8.2)
- sql = [@"DROP TABLE " stringByAppendingString:quickTableName];
+ sql = [@"DROP TABLE " stringByAppendingString:aclTableName];
if ((error = [channel evaluateExpressionX:sql]) != nil)
- return error;
+ ; // 'DROP TABLE' is allowed to fail (DROP IF EXISTS is not in PG<8.2)
sql = [self sqlCreateWithTableName: tableName];
if ((error = [channel evaluateExpressionX:sql]) != nil)
return error;
-
- sql = [ftype sqlQuickCreateWithTableName: quickTableName];
- if ((error = [channel evaluateExpressionX:sql]) != nil)
- return error;
- sql = [@"DROP TABLE " stringByAppendingString:aclTableName];
- if ((error = [channel evaluateExpressionX:sql]) != nil)
+ sql = [ftype sqlQuickCreateWithTableName: quickTableName];
+ if ((error = [channel evaluateExpressionX:sql]) != nil) {
+ /* 'rollback' TBD: wrap in proper tx */
+ sql = [@"DROP TABLE " stringByAppendingString:tableName];
+ if ((error = [channel evaluateExpressionX:sql]) != nil) {
+ [self warnWithFormat:@"failed to drop freshly created table: %@",
+ tableName];
+ }
+
return error;
+ }
sql = [self sqlAclCreateWithTableName: aclTableName];
- if ((error = [channel evaluateExpressionX:sql]) != nil)
+ if ((error = [channel evaluateExpressionX:sql]) != nil) {
+ /* 'rollback' TBD: wrap in proper tx */
+ sql = [@"DROP TABLE " stringByAppendingString:quickTableName];
+ if ((error = [channel evaluateExpressionX:sql]) != nil) {
+ [self warnWithFormat:@"failed to drop freshly created table: %@",
+ tableName];
+ }
+ sql = [@"DROP TABLE " stringByAppendingString:tableName];
+ if ((error = [channel evaluateExpressionX:sql]) != nil) {
+ [self warnWithFormat:@"failed to drop freshly created table: %@",
+ tableName];
+ }
+
return error;
+ }
paths = [[NSMutableArray alloc] initWithCapacity: 5];
pathElements = [[_path componentsSeparatedByString: @"/"] objectEnumerator];
- while ((pathElement = [pathElements nextObject]) != nil) {
+ while ((pathElement = [pathElements nextObject]) != nil) {
NSString *p = [[NSString alloc] initWithFormat: @"'%@'", pathElement];
[paths addObject: p];
[p release]; p = nil;
while ([paths count] < 5)
[paths addObject: @"NULL"];
-
+
+ // TBD: fix SQL injection issues
sql = [NSString stringWithFormat: @"INSERT INTO %@"
@" (c_path, c_path1, c_path2, c_path3, c_path4,"
@" c_foldername, c_location, c_quick_location,"