Fossil SCM
(json wiki save) now returns the results of (json wiki get) but without the page content.
Commit
70ea765873e3d5343b1f1ae712cdc4ea14cae795
Parent
913e0b6628bff13…
1 file changed
+18
-20
+18
-20
| --- src/json_wiki.c | ||
| +++ src/json_wiki.c | ||
| @@ -224,20 +224,17 @@ | ||
| 224 | 224 | ** If allowCreateIfExists is true then this function will allow a new |
| 225 | 225 | ** page to be created even if createMode is false. |
| 226 | 226 | */ |
| 227 | 227 | static cson_value * json_wiki_create_or_save(char createMode, |
| 228 | 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; | |
| 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. */ | |
| 239 | 236 | unsigned int contentLen = 0; |
| 240 | 237 | int rid; |
| 241 | 238 | if( (createMode && !g.perm.NewWiki) |
| 242 | 239 | || (!createMode && !g.perm.WrWiki)){ |
| 243 | 240 | json_set_err(FSL_JSON_E_DENIED, |
| @@ -294,22 +291,23 @@ | ||
| 294 | 291 | if(contentLen){ |
| 295 | 292 | blob_append(&content, cson_string_cstr(jstr),contentLen); |
| 296 | 293 | } |
| 297 | 294 | wiki_cmd_commit(zPageName, 0==rid, &content); |
| 298 | 295 | 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 ); | |
| 306 | 306 | goto ok; |
| 307 | 307 | error: |
| 308 | - assert( 0 != g.json.resultCode ); | |
| 309 | - cson_value_free(payV); | |
| 310 | - payV = NULL; | |
| 308 | + assert( NULL == payV ); | |
| 311 | 309 | ok: |
| 312 | 310 | if( emptyContent ){ |
| 313 | 311 | /* We have some potentially tricky memory ownership |
| 314 | 312 | here, which is why we handle emptyContent separately. |
| 315 | 313 | |
| 316 | 314 |
| --- 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 |