Fossil SCM
Update the "fossil server DIRECTORY" operation so that it will serve static content contained in DIRECTORY in addition to Fossil repositories.
Commit
87d6aa31965d7dd789d38e0faa28e313cba89f57
Parent
2017763c31cfd16…
1 file changed
+16
-4
+16
-4
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -1381,27 +1381,39 @@ | ||
| 1381 | 1381 | while( 1 ){ |
| 1382 | 1382 | while( zPathInfo[i] && zPathInfo[i]!='/' ){ i++; } |
| 1383 | 1383 | zRepo = zToFree = mprintf("%s%.*s.fossil",g.zRepositoryName,i,zPathInfo); |
| 1384 | 1384 | |
| 1385 | 1385 | /* To avoid mischief, make sure the repository basename contains no |
| 1386 | - ** characters other than alphanumerics, "-", "/", and "_". | |
| 1386 | + ** characters other than alphanumerics, "-", "/", "_", and "." beside | |
| 1387 | + ** "/" or ".". | |
| 1387 | 1388 | */ |
| 1388 | 1389 | for(j=strlen(g.zRepositoryName)+1, k=0; zRepo[j] && k<i-1; j++, k++){ |
| 1389 | - if( !fossil_isalnum(zRepo[j]) && zRepo[j]!='-' && zRepo[j]!='/' ){ | |
| 1390 | + char c = zRepo[j]; | |
| 1391 | + if( !fossil_isalnum(c) && c!='-' && c!='/' | |
| 1392 | + && (c!='.' || zRepo[j+1]=='/' || zRepo[j-1]=='/' || zRepo[j+1]=='.') | |
| 1393 | + ){ | |
| 1390 | 1394 | zRepo[j] = '_'; |
| 1391 | 1395 | } |
| 1392 | 1396 | } |
| 1393 | 1397 | if( zRepo[0]=='/' && zRepo[1]=='/' ){ zRepo++; j--; } |
| 1394 | 1398 | |
| 1395 | 1399 | szFile = file_size(zRepo); |
| 1396 | - if( zPathInfo[i]=='/' && szFile<0 ){ | |
| 1400 | + if( szFile<0 ){ | |
| 1397 | 1401 | assert( fossil_strcmp(&zRepo[j], ".fossil")==0 ); |
| 1398 | 1402 | zRepo[j] = 0; |
| 1399 | - if( file_isdir(zRepo)==1 ){ | |
| 1403 | + if( zPathInfo[i]=='/' && file_isdir(zRepo)==1 ){ | |
| 1400 | 1404 | fossil_free(zToFree); |
| 1401 | 1405 | i++; |
| 1402 | 1406 | continue; |
| 1407 | + } | |
| 1408 | + if( file_isfile(zRepo) ){ | |
| 1409 | + Blob content; | |
| 1410 | + blob_read_from_file(&content, zRepo); | |
| 1411 | + cgi_set_content_type(mimetype_from_name(zRepo)); | |
| 1412 | + cgi_set_content(&content); | |
| 1413 | + cgi_reply(); | |
| 1414 | + return; | |
| 1403 | 1415 | } |
| 1404 | 1416 | zRepo[j] = '.'; |
| 1405 | 1417 | } |
| 1406 | 1418 | |
| 1407 | 1419 | if( szFile<1024 ){ |
| 1408 | 1420 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -1381,27 +1381,39 @@ | |
| 1381 | while( 1 ){ |
| 1382 | while( zPathInfo[i] && zPathInfo[i]!='/' ){ i++; } |
| 1383 | zRepo = zToFree = mprintf("%s%.*s.fossil",g.zRepositoryName,i,zPathInfo); |
| 1384 | |
| 1385 | /* To avoid mischief, make sure the repository basename contains no |
| 1386 | ** characters other than alphanumerics, "-", "/", and "_". |
| 1387 | */ |
| 1388 | for(j=strlen(g.zRepositoryName)+1, k=0; zRepo[j] && k<i-1; j++, k++){ |
| 1389 | if( !fossil_isalnum(zRepo[j]) && zRepo[j]!='-' && zRepo[j]!='/' ){ |
| 1390 | zRepo[j] = '_'; |
| 1391 | } |
| 1392 | } |
| 1393 | if( zRepo[0]=='/' && zRepo[1]=='/' ){ zRepo++; j--; } |
| 1394 | |
| 1395 | szFile = file_size(zRepo); |
| 1396 | if( zPathInfo[i]=='/' && szFile<0 ){ |
| 1397 | assert( fossil_strcmp(&zRepo[j], ".fossil")==0 ); |
| 1398 | zRepo[j] = 0; |
| 1399 | if( file_isdir(zRepo)==1 ){ |
| 1400 | fossil_free(zToFree); |
| 1401 | i++; |
| 1402 | continue; |
| 1403 | } |
| 1404 | zRepo[j] = '.'; |
| 1405 | } |
| 1406 | |
| 1407 | if( szFile<1024 ){ |
| 1408 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -1381,27 +1381,39 @@ | |
| 1381 | while( 1 ){ |
| 1382 | while( zPathInfo[i] && zPathInfo[i]!='/' ){ i++; } |
| 1383 | zRepo = zToFree = mprintf("%s%.*s.fossil",g.zRepositoryName,i,zPathInfo); |
| 1384 | |
| 1385 | /* To avoid mischief, make sure the repository basename contains no |
| 1386 | ** characters other than alphanumerics, "-", "/", "_", and "." beside |
| 1387 | ** "/" or ".". |
| 1388 | */ |
| 1389 | for(j=strlen(g.zRepositoryName)+1, k=0; zRepo[j] && k<i-1; j++, k++){ |
| 1390 | char c = zRepo[j]; |
| 1391 | if( !fossil_isalnum(c) && c!='-' && c!='/' |
| 1392 | && (c!='.' || zRepo[j+1]=='/' || zRepo[j-1]=='/' || zRepo[j+1]=='.') |
| 1393 | ){ |
| 1394 | zRepo[j] = '_'; |
| 1395 | } |
| 1396 | } |
| 1397 | if( zRepo[0]=='/' && zRepo[1]=='/' ){ zRepo++; j--; } |
| 1398 | |
| 1399 | szFile = file_size(zRepo); |
| 1400 | if( szFile<0 ){ |
| 1401 | assert( fossil_strcmp(&zRepo[j], ".fossil")==0 ); |
| 1402 | zRepo[j] = 0; |
| 1403 | if( zPathInfo[i]=='/' && file_isdir(zRepo)==1 ){ |
| 1404 | fossil_free(zToFree); |
| 1405 | i++; |
| 1406 | continue; |
| 1407 | } |
| 1408 | if( file_isfile(zRepo) ){ |
| 1409 | Blob content; |
| 1410 | blob_read_from_file(&content, zRepo); |
| 1411 | cgi_set_content_type(mimetype_from_name(zRepo)); |
| 1412 | cgi_set_content(&content); |
| 1413 | cgi_reply(); |
| 1414 | return; |
| 1415 | } |
| 1416 | zRepo[j] = '.'; |
| 1417 | } |
| 1418 | |
| 1419 | if( szFile<1024 ){ |
| 1420 |