Fossil SCM

Add the /sqlar webpage. Link to this page from the /info page.

drh 2017-12-04 21:29 trunk
Commit 768e19219f86937b0b8af3289639798142557c63187232c75831359c28f39151
2 files changed +2 -2 +37 -14
+2 -2
--- src/info.c
+++ src/info.c
@@ -756,12 +756,12 @@
756756
char *zUrl = mprintf("%R/tarball/%t-%S.tar.gz?uuid=%s",
757757
zPJ, zUuid, zUuid);
758758
@ </td></tr>
759759
@ <tr><th>Downloads:</th><td>
760760
@ %z(href("%s",zUrl))Tarball</a>
761
- @ | %z(href("%R/zip/%t-%S.zip?uuid=%!S",zPJ,zUuid,zUuid))
762
- @ ZIP archive</a>
761
+ @ | %z(href("%R/zip/%t-%S.zip?uuid=%!S",zPJ,zUuid,zUuid))ZIP archive</a>
762
+ @ | %z(href("%R/sqlar/%t-%S.sqlar?uuid=%!S",zPJ,zUuid,zUuid))SQL archive</a>
763763
fossil_free(zUrl);
764764
}
765765
@ </td></tr>
766766
@ <tr><th>Other&nbsp;Links:</th>
767767
@ <td>
768768
--- src/info.c
+++ src/info.c
@@ -756,12 +756,12 @@
756 char *zUrl = mprintf("%R/tarball/%t-%S.tar.gz?uuid=%s",
757 zPJ, zUuid, zUuid);
758 @ </td></tr>
759 @ <tr><th>Downloads:</th><td>
760 @ %z(href("%s",zUrl))Tarball</a>
761 @ | %z(href("%R/zip/%t-%S.zip?uuid=%!S",zPJ,zUuid,zUuid))
762 @ ZIP archive</a>
763 fossil_free(zUrl);
764 }
765 @ </td></tr>
766 @ <tr><th>Other&nbsp;Links:</th>
767 @ <td>
768
--- src/info.c
+++ src/info.c
@@ -756,12 +756,12 @@
756 char *zUrl = mprintf("%R/tarball/%t-%S.tar.gz?uuid=%s",
757 zPJ, zUuid, zUuid);
758 @ </td></tr>
759 @ <tr><th>Downloads:</th><td>
760 @ %z(href("%s",zUrl))Tarball</a>
761 @ | %z(href("%R/zip/%t-%S.zip?uuid=%!S",zPJ,zUuid,zUuid))ZIP archive</a>
762 @ | %z(href("%R/sqlar/%t-%S.sqlar?uuid=%!S",zPJ,zUuid,zUuid))SQL archive</a>
763 fossil_free(zUrl);
764 }
765 @ </td></tr>
766 @ <tr><th>Other&nbsp;Links:</th>
767 @ <td>
768
+37 -14
--- src/zip.c
+++ src/zip.c
@@ -825,19 +825,19 @@
825825
void sqlar_cmd(void){
826826
archive_cmd(ARCHIVE_SQLAR);
827827
}
828828
829829
/*
830
+** WEBPAGE: sqlar
830831
** WEBPAGE: zip
831
-** URL: /zip
832832
**
833
-** Generate a ZIP archive for the check-in specified by the "r"
834
-** query parameter. Return that ZIP archive as the HTTP reply content.
833
+** Generate a ZIP or SQL archive for the check-in specified by the "r"
834
+** query parameter. Return the archive as the HTTP reply content.
835835
**
836836
** Query parameters:
837837
**
838
-** name=NAME[.zip] The base name of the output file. The default
838
+** name=NAME The base name of the output file. The default
839839
** value is a configuration parameter in the project
840840
** settings. A prefix of the name, omitting the
841841
** extension, is used as the top-most directory name.
842842
**
843843
** r=TAG The check-in that is turned into a ZIP archive.
@@ -864,13 +864,22 @@
864864
const char *zExclude; /* The ex= query parameter */
865865
Blob cacheKey; /* The key to cache */
866866
Glob *pInclude = 0; /* The compiled in= glob pattern */
867867
Glob *pExclude = 0; /* The compiled ex= glob pattern */
868868
Blob zip; /* ZIP archive accumulated here */
869
+ int eType = ARCHIVE_ZIP; /* Type of archive to generate */
870
+ char *zType; /* Human-readable archive type */
869871
870872
login_check_credentials();
871873
if( !g.perm.Zip ){ login_needed(g.anon.Zip); return; }
874
+ if( fossil_strcmp(g.zPath, "sqlar")==0 ){
875
+ eType = ARCHIVE_SQLAR;
876
+ zType = "SQL";
877
+ }else{
878
+ eType = ARCHIVE_ZIP;
879
+ zType = "ZIP";
880
+ }
872881
load_control();
873882
zName = mprintf("%s", PD("name",""));
874883
nName = strlen(zName);
875884
z = P("r");
876885
if( z==0 ) z = P("uuid");
@@ -879,16 +888,26 @@
879888
nRid = strlen(zRid);
880889
zInclude = P("in");
881890
if( zInclude ) pInclude = glob_create(zInclude);
882891
zExclude = P("ex");
883892
if( zExclude ) pExclude = glob_create(zExclude);
884
- if( nName>4 && fossil_strcmp(&zName[nName-4], ".zip")==0 ){
893
+ if( eType==ARCHIVE_ZIP
894
+ && nName>4
895
+ && fossil_strcmp(&zName[nName-4], ".zip")==0
896
+ ){
885897
/* Special case: Remove the ".zip" suffix. */
886898
nName -= 4;
887899
zName[nName] = 0;
900
+ }else if( eType==ARCHIVE_SQLAR
901
+ && nName>6
902
+ && fossil_strcmp(&zName[nName-6], ".sqlar")==0
903
+ ){
904
+ /* Special case: Remove the ".sqlar" suffix. */
905
+ nName -= 6;
906
+ zName[nName] = 0;
888907
}else{
889
- /* If the file suffix is not ".zip" then just remove the
908
+ /* If the file suffix is not ".zip" or ".sqlar" then just remove the
890909
** suffix up to and including the last "." */
891910
for(nName=strlen(zName)-1; nName>5; nName--){
892911
if( zName[nName]=='.' ){
893912
zName[nName] = 0;
894913
break;
@@ -903,18 +922,18 @@
903922
}
904923
if( nRid==0 && nName>10 ) zName[10] = 0;
905924
906925
/* Compute a unique key for the cache entry based on query parameters */
907926
blob_init(&cacheKey, 0, 0);
908
- blob_appendf(&cacheKey, "/zip/%z", rid_to_uuid(rid));
927
+ blob_appendf(&cacheKey, "/%s/%z", g.zPath, rid_to_uuid(rid));
909928
blob_appendf(&cacheKey, "/%q", zName);
910929
if( zInclude ) blob_appendf(&cacheKey, ",in=%Q", zInclude);
911930
if( zExclude ) blob_appendf(&cacheKey, ",ex=%Q", zExclude);
912931
zKey = blob_str(&cacheKey);
913932
914933
if( P("debug")!=0 ){
915
- style_header("ZIP Archive Generator Debug Screen");
934
+ style_header("%s Archive Generator Debug Screen", zType);
916935
@ zName = "%h(zName)"<br />
917936
@ rid = %d(rid)<br />
918937
if( zInclude ){
919938
@ zInclude = "%h(zInclude)"<br />
920939
}
@@ -924,28 +943,32 @@
924943
@ zKey = "%h(zKey)"
925944
style_footer();
926945
return;
927946
}
928947
if( referred_from_login() ){
929
- style_header("ZIP Archive Download");
930
- @ <form action='%R/zip/%h(zName).zip'>
948
+ style_header("%s Archive Download", zType);
949
+ @ <form action='%R/%s(g.zPath)/%h(zName).%s(g.zPath)'>
931950
cgi_query_parameters_to_hidden();
932
- @ <p>ZIP Archive named <b>%h(zName).zip</b> holding the content
933
- @ of check-in <b>%h(zRid)</b>:
951
+ @ <p>%s(zType) Archive named <b>%h(zName).%s(g.zPath)</b>
952
+ @ holding the content of check-in <b>%h(zRid)</b>:
934953
@ <input type="submit" value="Download" />
935954
@ </form>
936955
style_footer();
937956
return;
938957
}
939958
blob_zero(&zip);
940959
if( cache_read(&zip, zKey)==0 ){
941
- zip_of_checkin(ARCHIVE_ZIP, rid, &zip, zName, pInclude, pExclude);
960
+ zip_of_checkin(eType, rid, &zip, zName, pInclude, pExclude);
942961
cache_write(&zip, zKey);
943962
}
944963
glob_free(pInclude);
945964
glob_free(pExclude);
946965
fossil_free(zName);
947966
fossil_free(zRid);
948967
blob_reset(&cacheKey);
949968
cgi_set_content(&zip);
950
- cgi_set_content_type("application/zip");
969
+ if( eType==ARCHIVE_ZIP ){
970
+ cgi_set_content_type("application/zip");
971
+ }else{
972
+ cgi_set_content_type("application/sqlar");
973
+ }
951974
}
952975
--- src/zip.c
+++ src/zip.c
@@ -825,19 +825,19 @@
825 void sqlar_cmd(void){
826 archive_cmd(ARCHIVE_SQLAR);
827 }
828
829 /*
 
830 ** WEBPAGE: zip
831 ** URL: /zip
832 **
833 ** Generate a ZIP archive for the check-in specified by the "r"
834 ** query parameter. Return that ZIP archive as the HTTP reply content.
835 **
836 ** Query parameters:
837 **
838 ** name=NAME[.zip] The base name of the output file. The default
839 ** value is a configuration parameter in the project
840 ** settings. A prefix of the name, omitting the
841 ** extension, is used as the top-most directory name.
842 **
843 ** r=TAG The check-in that is turned into a ZIP archive.
@@ -864,13 +864,22 @@
864 const char *zExclude; /* The ex= query parameter */
865 Blob cacheKey; /* The key to cache */
866 Glob *pInclude = 0; /* The compiled in= glob pattern */
867 Glob *pExclude = 0; /* The compiled ex= glob pattern */
868 Blob zip; /* ZIP archive accumulated here */
 
 
869
870 login_check_credentials();
871 if( !g.perm.Zip ){ login_needed(g.anon.Zip); return; }
 
 
 
 
 
 
 
872 load_control();
873 zName = mprintf("%s", PD("name",""));
874 nName = strlen(zName);
875 z = P("r");
876 if( z==0 ) z = P("uuid");
@@ -879,16 +888,26 @@
879 nRid = strlen(zRid);
880 zInclude = P("in");
881 if( zInclude ) pInclude = glob_create(zInclude);
882 zExclude = P("ex");
883 if( zExclude ) pExclude = glob_create(zExclude);
884 if( nName>4 && fossil_strcmp(&zName[nName-4], ".zip")==0 ){
 
 
 
885 /* Special case: Remove the ".zip" suffix. */
886 nName -= 4;
887 zName[nName] = 0;
 
 
 
 
 
 
 
888 }else{
889 /* If the file suffix is not ".zip" then just remove the
890 ** suffix up to and including the last "." */
891 for(nName=strlen(zName)-1; nName>5; nName--){
892 if( zName[nName]=='.' ){
893 zName[nName] = 0;
894 break;
@@ -903,18 +922,18 @@
903 }
904 if( nRid==0 && nName>10 ) zName[10] = 0;
905
906 /* Compute a unique key for the cache entry based on query parameters */
907 blob_init(&cacheKey, 0, 0);
908 blob_appendf(&cacheKey, "/zip/%z", rid_to_uuid(rid));
909 blob_appendf(&cacheKey, "/%q", zName);
910 if( zInclude ) blob_appendf(&cacheKey, ",in=%Q", zInclude);
911 if( zExclude ) blob_appendf(&cacheKey, ",ex=%Q", zExclude);
912 zKey = blob_str(&cacheKey);
913
914 if( P("debug")!=0 ){
915 style_header("ZIP Archive Generator Debug Screen");
916 @ zName = "%h(zName)"<br />
917 @ rid = %d(rid)<br />
918 if( zInclude ){
919 @ zInclude = "%h(zInclude)"<br />
920 }
@@ -924,28 +943,32 @@
924 @ zKey = "%h(zKey)"
925 style_footer();
926 return;
927 }
928 if( referred_from_login() ){
929 style_header("ZIP Archive Download");
930 @ <form action='%R/zip/%h(zName).zip'>
931 cgi_query_parameters_to_hidden();
932 @ <p>ZIP Archive named <b>%h(zName).zip</b> holding the content
933 @ of check-in <b>%h(zRid)</b>:
934 @ <input type="submit" value="Download" />
935 @ </form>
936 style_footer();
937 return;
938 }
939 blob_zero(&zip);
940 if( cache_read(&zip, zKey)==0 ){
941 zip_of_checkin(ARCHIVE_ZIP, rid, &zip, zName, pInclude, pExclude);
942 cache_write(&zip, zKey);
943 }
944 glob_free(pInclude);
945 glob_free(pExclude);
946 fossil_free(zName);
947 fossil_free(zRid);
948 blob_reset(&cacheKey);
949 cgi_set_content(&zip);
950 cgi_set_content_type("application/zip");
 
 
 
 
951 }
952
--- src/zip.c
+++ src/zip.c
@@ -825,19 +825,19 @@
825 void sqlar_cmd(void){
826 archive_cmd(ARCHIVE_SQLAR);
827 }
828
829 /*
830 ** WEBPAGE: sqlar
831 ** WEBPAGE: zip
 
832 **
833 ** Generate a ZIP or SQL archive for the check-in specified by the "r"
834 ** query parameter. Return the archive as the HTTP reply content.
835 **
836 ** Query parameters:
837 **
838 ** name=NAME The base name of the output file. The default
839 ** value is a configuration parameter in the project
840 ** settings. A prefix of the name, omitting the
841 ** extension, is used as the top-most directory name.
842 **
843 ** r=TAG The check-in that is turned into a ZIP archive.
@@ -864,13 +864,22 @@
864 const char *zExclude; /* The ex= query parameter */
865 Blob cacheKey; /* The key to cache */
866 Glob *pInclude = 0; /* The compiled in= glob pattern */
867 Glob *pExclude = 0; /* The compiled ex= glob pattern */
868 Blob zip; /* ZIP archive accumulated here */
869 int eType = ARCHIVE_ZIP; /* Type of archive to generate */
870 char *zType; /* Human-readable archive type */
871
872 login_check_credentials();
873 if( !g.perm.Zip ){ login_needed(g.anon.Zip); return; }
874 if( fossil_strcmp(g.zPath, "sqlar")==0 ){
875 eType = ARCHIVE_SQLAR;
876 zType = "SQL";
877 }else{
878 eType = ARCHIVE_ZIP;
879 zType = "ZIP";
880 }
881 load_control();
882 zName = mprintf("%s", PD("name",""));
883 nName = strlen(zName);
884 z = P("r");
885 if( z==0 ) z = P("uuid");
@@ -879,16 +888,26 @@
888 nRid = strlen(zRid);
889 zInclude = P("in");
890 if( zInclude ) pInclude = glob_create(zInclude);
891 zExclude = P("ex");
892 if( zExclude ) pExclude = glob_create(zExclude);
893 if( eType==ARCHIVE_ZIP
894 && nName>4
895 && fossil_strcmp(&zName[nName-4], ".zip")==0
896 ){
897 /* Special case: Remove the ".zip" suffix. */
898 nName -= 4;
899 zName[nName] = 0;
900 }else if( eType==ARCHIVE_SQLAR
901 && nName>6
902 && fossil_strcmp(&zName[nName-6], ".sqlar")==0
903 ){
904 /* Special case: Remove the ".sqlar" suffix. */
905 nName -= 6;
906 zName[nName] = 0;
907 }else{
908 /* If the file suffix is not ".zip" or ".sqlar" then just remove the
909 ** suffix up to and including the last "." */
910 for(nName=strlen(zName)-1; nName>5; nName--){
911 if( zName[nName]=='.' ){
912 zName[nName] = 0;
913 break;
@@ -903,18 +922,18 @@
922 }
923 if( nRid==0 && nName>10 ) zName[10] = 0;
924
925 /* Compute a unique key for the cache entry based on query parameters */
926 blob_init(&cacheKey, 0, 0);
927 blob_appendf(&cacheKey, "/%s/%z", g.zPath, rid_to_uuid(rid));
928 blob_appendf(&cacheKey, "/%q", zName);
929 if( zInclude ) blob_appendf(&cacheKey, ",in=%Q", zInclude);
930 if( zExclude ) blob_appendf(&cacheKey, ",ex=%Q", zExclude);
931 zKey = blob_str(&cacheKey);
932
933 if( P("debug")!=0 ){
934 style_header("%s Archive Generator Debug Screen", zType);
935 @ zName = "%h(zName)"<br />
936 @ rid = %d(rid)<br />
937 if( zInclude ){
938 @ zInclude = "%h(zInclude)"<br />
939 }
@@ -924,28 +943,32 @@
943 @ zKey = "%h(zKey)"
944 style_footer();
945 return;
946 }
947 if( referred_from_login() ){
948 style_header("%s Archive Download", zType);
949 @ <form action='%R/%s(g.zPath)/%h(zName).%s(g.zPath)'>
950 cgi_query_parameters_to_hidden();
951 @ <p>%s(zType) Archive named <b>%h(zName).%s(g.zPath)</b>
952 @ holding the content of check-in <b>%h(zRid)</b>:
953 @ <input type="submit" value="Download" />
954 @ </form>
955 style_footer();
956 return;
957 }
958 blob_zero(&zip);
959 if( cache_read(&zip, zKey)==0 ){
960 zip_of_checkin(eType, rid, &zip, zName, pInclude, pExclude);
961 cache_write(&zip, zKey);
962 }
963 glob_free(pInclude);
964 glob_free(pExclude);
965 fossil_free(zName);
966 fossil_free(zRid);
967 blob_reset(&cacheKey);
968 cgi_set_content(&zip);
969 if( eType==ARCHIVE_ZIP ){
970 cgi_set_content_type("application/zip");
971 }else{
972 cgi_set_content_type("application/sqlar");
973 }
974 }
975

Keyboard Shortcuts

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