Fossil SCM
Finish(?) /uvlist file upload feature.
Commit
ecfdf535378408d9285316e614c3757d2f9f7e918270b145acec7f5923a0d912
Parent
152cc642e7f95d6…
2 files changed
+5
-1
+37
-6
+5
-1
| --- src/style.uvlist.css | ||
| +++ src/style.uvlist.css | ||
| @@ -1,3 +1,7 @@ | ||
| 1 | -body.uvlist form.uvupload label { | |
| 1 | +body.uvlist input { | |
| 2 | + margin: 0.5em; | |
| 3 | +} | |
| 4 | + | |
| 5 | +body.uvlist form { | |
| 2 | 6 | display: block; |
| 3 | 7 | } |
| 4 | 8 |
| --- src/style.uvlist.css | |
| +++ src/style.uvlist.css | |
| @@ -1,3 +1,7 @@ | |
| 1 | body.uvlist form.uvupload label { |
| 2 | display: block; |
| 3 | } |
| 4 |
| --- src/style.uvlist.css | |
| +++ src/style.uvlist.css | |
| @@ -1,3 +1,7 @@ | |
| 1 | body.uvlist input { |
| 2 | margin: 0.5em; |
| 3 | } |
| 4 | |
| 5 | body.uvlist form { |
| 6 | display: block; |
| 7 | } |
| 8 |
+37
-6
| --- src/unversioned.c | ||
| +++ src/unversioned.c | ||
| @@ -525,16 +525,48 @@ | ||
| 525 | 525 | |
| 526 | 526 | /* |
| 527 | 527 | ** Emit an HTML form for uploading a new unversioned file if |
| 528 | 528 | ** the current user has WrUnver permissions, else this is |
| 529 | 529 | ** a no-op. |
| 530 | +** | |
| 531 | +** If this function detects that the form it emits has been submitted, | |
| 532 | +** it will add the uploaded file to the unversioned file list before | |
| 533 | +** returning. | |
| 534 | +** | |
| 535 | +** Intended only for use by /uvlist, and its form's action is that | |
| 536 | +** page. | |
| 530 | 537 | */ |
| 531 | -static void uv_form_upload(void){ | |
| 538 | +static void uvlist_upload(void){ | |
| 539 | + const char * aContent; | |
| 532 | 540 | if( !g.perm.WrUnver ) return; |
| 533 | - CX("<form class='uvupload' method='POST'>"); | |
| 534 | - CX("<label for='uvupload'>Select file to upload:</label>"); | |
| 535 | - CX("<input type='file' id='uvupload' name='uvupload'/>"); | |
| 541 | + aContent = P("f"); | |
| 542 | + if( aContent!=0 ){ | |
| 543 | + const char * const zName = P("f:filename"); | |
| 544 | + int const nContent = atoi(PD("f:bytes","0")); | |
| 545 | + const char * zError = 0; | |
| 546 | + Blob content; | |
| 547 | + if( zName[0]==0 ){ | |
| 548 | + zError = "be an empty string"; | |
| 549 | + }else if( contains_whitespace(zName) ){ | |
| 550 | + zError = "contain spaces"; | |
| 551 | + } | |
| 552 | + if( zError ){ | |
| 553 | + fossil_fatal("Unversioned filenames may not %s: %Q", | |
| 554 | + zError, zName); | |
| 555 | + } | |
| 556 | + db_begin_transaction(); | |
| 557 | + content_rcvid_init("#!fossil /uvlist upload"); | |
| 558 | + blob_init(&content, aContent, nContent); | |
| 559 | + unversioned_write(zName, &content, time(0)); | |
| 560 | + blob_reset(&content); | |
| 561 | + db_end_transaction(0); | |
| 562 | + CX("<div>Added: %s</div>", zName); | |
| 563 | + } | |
| 564 | + form_begin("enctype='multipart/form-data'", "%R/uvlist"); | |
| 565 | + CX("<label for='uvupload'>Upload unversioned file:</label>"); | |
| 566 | + CX("<input type='file' id='uvupload' name='f'/>"); | |
| 567 | + CX("<input type='submit' value='Upload'/>"); | |
| 536 | 568 | CX("</form>"); |
| 537 | 569 | } |
| 538 | 570 | |
| 539 | 571 | /* |
| 540 | 572 | ** WEBPAGE: uvlist |
| @@ -558,13 +590,13 @@ | ||
| 558 | 590 | login_check_credentials(); |
| 559 | 591 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 560 | 592 | cgi_check_for_malice(); |
| 561 | 593 | etag_check(ETAG_DATA,0); |
| 562 | 594 | style_header("Unversioned Files"); |
| 595 | + uvlist_upload(); | |
| 563 | 596 | if( !db_table_exists("repository","unversioned") ){ |
| 564 | 597 | @ No unversioned files on this server |
| 565 | - uv_form_upload(); | |
| 566 | 598 | style_finish_page(); |
| 567 | 599 | return; |
| 568 | 600 | } |
| 569 | 601 | if( PB("byage") ) zOrderBy = "mtime DESC"; |
| 570 | 602 | if( PB("showdel") ) showDel = 1; |
| @@ -653,11 +685,10 @@ | ||
| 653 | 685 | @ </tfoot> |
| 654 | 686 | @ </table></div> |
| 655 | 687 | }else{ |
| 656 | 688 | @ No unversioned files on this server. |
| 657 | 689 | } |
| 658 | - uv_form_upload(); | |
| 659 | 690 | style_finish_page(); |
| 660 | 691 | } |
| 661 | 692 | |
| 662 | 693 | /* |
| 663 | 694 | ** WEBPAGE: juvlist |
| 664 | 695 |
| --- src/unversioned.c | |
| +++ src/unversioned.c | |
| @@ -525,16 +525,48 @@ | |
| 525 | |
| 526 | /* |
| 527 | ** Emit an HTML form for uploading a new unversioned file if |
| 528 | ** the current user has WrUnver permissions, else this is |
| 529 | ** a no-op. |
| 530 | */ |
| 531 | static void uv_form_upload(void){ |
| 532 | if( !g.perm.WrUnver ) return; |
| 533 | CX("<form class='uvupload' method='POST'>"); |
| 534 | CX("<label for='uvupload'>Select file to upload:</label>"); |
| 535 | CX("<input type='file' id='uvupload' name='uvupload'/>"); |
| 536 | CX("</form>"); |
| 537 | } |
| 538 | |
| 539 | /* |
| 540 | ** WEBPAGE: uvlist |
| @@ -558,13 +590,13 @@ | |
| 558 | login_check_credentials(); |
| 559 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 560 | cgi_check_for_malice(); |
| 561 | etag_check(ETAG_DATA,0); |
| 562 | style_header("Unversioned Files"); |
| 563 | if( !db_table_exists("repository","unversioned") ){ |
| 564 | @ No unversioned files on this server |
| 565 | uv_form_upload(); |
| 566 | style_finish_page(); |
| 567 | return; |
| 568 | } |
| 569 | if( PB("byage") ) zOrderBy = "mtime DESC"; |
| 570 | if( PB("showdel") ) showDel = 1; |
| @@ -653,11 +685,10 @@ | |
| 653 | @ </tfoot> |
| 654 | @ </table></div> |
| 655 | }else{ |
| 656 | @ No unversioned files on this server. |
| 657 | } |
| 658 | uv_form_upload(); |
| 659 | style_finish_page(); |
| 660 | } |
| 661 | |
| 662 | /* |
| 663 | ** WEBPAGE: juvlist |
| 664 |
| --- src/unversioned.c | |
| +++ src/unversioned.c | |
| @@ -525,16 +525,48 @@ | |
| 525 | |
| 526 | /* |
| 527 | ** Emit an HTML form for uploading a new unversioned file if |
| 528 | ** the current user has WrUnver permissions, else this is |
| 529 | ** a no-op. |
| 530 | ** |
| 531 | ** If this function detects that the form it emits has been submitted, |
| 532 | ** it will add the uploaded file to the unversioned file list before |
| 533 | ** returning. |
| 534 | ** |
| 535 | ** Intended only for use by /uvlist, and its form's action is that |
| 536 | ** page. |
| 537 | */ |
| 538 | static void uvlist_upload(void){ |
| 539 | const char * aContent; |
| 540 | if( !g.perm.WrUnver ) return; |
| 541 | aContent = P("f"); |
| 542 | if( aContent!=0 ){ |
| 543 | const char * const zName = P("f:filename"); |
| 544 | int const nContent = atoi(PD("f:bytes","0")); |
| 545 | const char * zError = 0; |
| 546 | Blob content; |
| 547 | if( zName[0]==0 ){ |
| 548 | zError = "be an empty string"; |
| 549 | }else if( contains_whitespace(zName) ){ |
| 550 | zError = "contain spaces"; |
| 551 | } |
| 552 | if( zError ){ |
| 553 | fossil_fatal("Unversioned filenames may not %s: %Q", |
| 554 | zError, zName); |
| 555 | } |
| 556 | db_begin_transaction(); |
| 557 | content_rcvid_init("#!fossil /uvlist upload"); |
| 558 | blob_init(&content, aContent, nContent); |
| 559 | unversioned_write(zName, &content, time(0)); |
| 560 | blob_reset(&content); |
| 561 | db_end_transaction(0); |
| 562 | CX("<div>Added: %s</div>", zName); |
| 563 | } |
| 564 | form_begin("enctype='multipart/form-data'", "%R/uvlist"); |
| 565 | CX("<label for='uvupload'>Upload unversioned file:</label>"); |
| 566 | CX("<input type='file' id='uvupload' name='f'/>"); |
| 567 | CX("<input type='submit' value='Upload'/>"); |
| 568 | CX("</form>"); |
| 569 | } |
| 570 | |
| 571 | /* |
| 572 | ** WEBPAGE: uvlist |
| @@ -558,13 +590,13 @@ | |
| 590 | login_check_credentials(); |
| 591 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 592 | cgi_check_for_malice(); |
| 593 | etag_check(ETAG_DATA,0); |
| 594 | style_header("Unversioned Files"); |
| 595 | uvlist_upload(); |
| 596 | if( !db_table_exists("repository","unversioned") ){ |
| 597 | @ No unversioned files on this server |
| 598 | style_finish_page(); |
| 599 | return; |
| 600 | } |
| 601 | if( PB("byage") ) zOrderBy = "mtime DESC"; |
| 602 | if( PB("showdel") ) showDel = 1; |
| @@ -653,11 +685,10 @@ | |
| 685 | @ </tfoot> |
| 686 | @ </table></div> |
| 687 | }else{ |
| 688 | @ No unversioned files on this server. |
| 689 | } |
| 690 | style_finish_page(); |
| 691 | } |
| 692 | |
| 693 | /* |
| 694 | ** WEBPAGE: juvlist |
| 695 |