Fossil SCM

(json wiki save) now returns the results of (json wiki get) but without the page content.

stephan 2012-02-12 10:58 trunk
Commit 70ea765873e3d5343b1f1ae712cdc4ea14cae795
1 file changed +18 -20
+18 -20
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -224,20 +224,17 @@
224224
** If allowCreateIfExists is true then this function will allow a new
225225
** page to be created even if createMode is false.
226226
*/
227227
static cson_value * json_wiki_create_or_save(char createMode,
228228
char allowCreateIfExists){
229
- Blob content = empty_blob;
230
- cson_value * nameV;
231
- cson_value * contentV;
232
- cson_value * emptyContent = NULL;
233
- cson_value * payV = NULL;
234
- cson_object * pay = NULL;
235
- cson_string const * jstr = NULL;
236
- char const * zContent;
237
- char const * zBody = NULL;
238
- char const * zPageName;
229
+ Blob content = empty_blob; /* wiki page content */
230
+ cson_value * nameV; /* wiki page name */
231
+ char const * zPageName; /* cstr form of page name */
232
+ cson_value * contentV; /* passed-in content */
233
+ cson_value * emptyContent = NULL; /* placeholder for empty content. */
234
+ cson_value * payV = NULL; /* payload/return value */
235
+ cson_string const * jstr = NULL; /* temp for cson_value-to-cson_string conversions. */
239236
unsigned int contentLen = 0;
240237
int rid;
241238
if( (createMode && !g.perm.NewWiki)
242239
|| (!createMode && !g.perm.WrWiki)){
243240
json_set_err(FSL_JSON_E_DENIED,
@@ -294,22 +291,23 @@
294291
if(contentLen){
295292
blob_append(&content, cson_string_cstr(jstr),contentLen);
296293
}
297294
wiki_cmd_commit(zPageName, 0==rid, &content);
298295
blob_reset(&content);
299
-
300
- payV = cson_value_new_object();
301
- pay = cson_value_get_object(payV);
302
- cson_object_set( pay, "name", nameV );
303
- cson_object_set( pay, FossilJsonKeys.timestamp,
304
- json_new_timestamp(-1) );
305
-
296
+ /*
297
+ Our return value here has a race condition: if the page is saved
298
+ again before the next line finishes, payV could be the results
299
+ of the other save operation.
300
+ */
301
+ payV = json_get_wiki_page_by_name(
302
+ cson_string_cstr(
303
+ cson_value_get_string(nameV)),
304
+ 0);
305
+ assert( 0 != g.json.resultCode );
306306
goto ok;
307307
error:
308
- assert( 0 != g.json.resultCode );
309
- cson_value_free(payV);
310
- payV = NULL;
308
+ assert( NULL == payV );
311309
ok:
312310
if( emptyContent ){
313311
/* We have some potentially tricky memory ownership
314312
here, which is why we handle emptyContent separately.
315313
316314
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -224,20 +224,17 @@
224 ** If allowCreateIfExists is true then this function will allow a new
225 ** page to be created even if createMode is false.
226 */
227 static cson_value * json_wiki_create_or_save(char createMode,
228 char allowCreateIfExists){
229 Blob content = empty_blob;
230 cson_value * nameV;
231 cson_value * contentV;
232 cson_value * emptyContent = NULL;
233 cson_value * payV = NULL;
234 cson_object * pay = NULL;
235 cson_string const * jstr = NULL;
236 char const * zContent;
237 char const * zBody = NULL;
238 char const * zPageName;
239 unsigned int contentLen = 0;
240 int rid;
241 if( (createMode && !g.perm.NewWiki)
242 || (!createMode && !g.perm.WrWiki)){
243 json_set_err(FSL_JSON_E_DENIED,
@@ -294,22 +291,23 @@
294 if(contentLen){
295 blob_append(&content, cson_string_cstr(jstr),contentLen);
296 }
297 wiki_cmd_commit(zPageName, 0==rid, &content);
298 blob_reset(&content);
299
300 payV = cson_value_new_object();
301 pay = cson_value_get_object(payV);
302 cson_object_set( pay, "name", nameV );
303 cson_object_set( pay, FossilJsonKeys.timestamp,
304 json_new_timestamp(-1) );
305
 
 
 
306 goto ok;
307 error:
308 assert( 0 != g.json.resultCode );
309 cson_value_free(payV);
310 payV = NULL;
311 ok:
312 if( emptyContent ){
313 /* We have some potentially tricky memory ownership
314 here, which is why we handle emptyContent separately.
315
316
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -224,20 +224,17 @@
224 ** If allowCreateIfExists is true then this function will allow a new
225 ** page to be created even if createMode is false.
226 */
227 static cson_value * json_wiki_create_or_save(char createMode,
228 char allowCreateIfExists){
229 Blob content = empty_blob; /* wiki page content */
230 cson_value * nameV; /* wiki page name */
231 char const * zPageName; /* cstr form of page name */
232 cson_value * contentV; /* passed-in content */
233 cson_value * emptyContent = NULL; /* placeholder for empty content. */
234 cson_value * payV = NULL; /* payload/return value */
235 cson_string const * jstr = NULL; /* temp for cson_value-to-cson_string conversions. */
 
 
 
236 unsigned int contentLen = 0;
237 int rid;
238 if( (createMode && !g.perm.NewWiki)
239 || (!createMode && !g.perm.WrWiki)){
240 json_set_err(FSL_JSON_E_DENIED,
@@ -294,22 +291,23 @@
291 if(contentLen){
292 blob_append(&content, cson_string_cstr(jstr),contentLen);
293 }
294 wiki_cmd_commit(zPageName, 0==rid, &content);
295 blob_reset(&content);
296 /*
297 Our return value here has a race condition: if the page is saved
298 again before the next line finishes, payV could be the results
299 of the other save operation.
300 */
301 payV = json_get_wiki_page_by_name(
302 cson_string_cstr(
303 cson_value_get_string(nameV)),
304 0);
305 assert( 0 != g.json.resultCode );
306 goto ok;
307 error:
308 assert( NULL == payV );
 
 
309 ok:
310 if( emptyContent ){
311 /* We have some potentially tricky memory ownership
312 here, which is why we handle emptyContent separately.
313
314

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button