Fossil SCM
Remove commands "test-nondir-path" and "test-is-reserved-name" and add the equivalent functionality to "test-file-environment".
Commit
0cec61e451c6c818108a3f80b8701e5b998246c38a819cf464d92cb6f4db549a
Parent
ff811934e078a75…
1 file changed
+21
-46
+21
-46
| --- src/file.c | ||
| +++ src/file.c | ||
| @@ -371,32 +371,10 @@ | ||
| 371 | 371 | } |
| 372 | 372 | fossil_free(z); |
| 373 | 373 | return 0; |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | -/* | |
| 377 | -** COMMAND: test-nondir-path | |
| 378 | -** Usage: %fossil test-nondir-path ROOT FILE | |
| 379 | -** | |
| 380 | -** If there are any objects on the path from ROOT to FILE (exluding | |
| 381 | -** ROOT and FILE themselves) that are not directories, then print | |
| 382 | -** the name of the first object found. | |
| 383 | -*/ | |
| 384 | -void test_nondir_path_cmd(void){ | |
| 385 | - int n; | |
| 386 | - if( g.argc!=4 ){ | |
| 387 | - usage("ROOT FILE"); | |
| 388 | - } | |
| 389 | - if( fossil_strnicmp(g.argv[2],g.argv[3],(int)strlen(g.argv[2]))!=0 ){ | |
| 390 | - fossil_fatal("%s should be a prefix of %s", g.argv[2], g.argv[3]); | |
| 391 | - } | |
| 392 | - n = file_nondir_objects_on_path(g.argv[2],g.argv[3]); | |
| 393 | - if( n ){ | |
| 394 | - fossil_print("%.*s\n", n, g.argv[3]); | |
| 395 | - } | |
| 396 | -} | |
| 397 | - | |
| 398 | 376 | /* |
| 399 | 377 | ** The file named zFile is suppose to be an in-tree file. Check to |
| 400 | 378 | ** ensure that it will be safe to write to this file by verifying that |
| 401 | 379 | ** there are no symlinks or other non-directory objects in between the |
| 402 | 380 | ** root of the checkout and zFile. |
| @@ -1333,12 +1311,12 @@ | ||
| 1333 | 1311 | sqlite3_int64 iMtime; |
| 1334 | 1312 | struct fossilStat testFileStat; |
| 1335 | 1313 | memset(zBuf, 0, sizeof(zBuf)); |
| 1336 | 1314 | blob_zero(&x); |
| 1337 | 1315 | file_canonical_name(zPath, &x, slash); |
| 1338 | - fossil_print("[%s] -> [%s]\n", zPath, blob_buffer(&x)); | |
| 1339 | - blob_reset(&x); | |
| 1316 | + char *zFull = blob_str(&x); | |
| 1317 | + fossil_print("[%s] -> [%s]\n", zPath, zFull); | |
| 1340 | 1318 | memset(&testFileStat, 0, sizeof(struct fossilStat)); |
| 1341 | 1319 | rc = fossil_stat(zPath, &testFileStat, 0); |
| 1342 | 1320 | fossil_print(" stat_rc = %d\n", rc); |
| 1343 | 1321 | sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", testFileStat.st_size); |
| 1344 | 1322 | fossil_print(" stat_size = %s\n", zBuf); |
| @@ -1382,10 +1360,13 @@ | ||
| 1382 | 1360 | fossil_print(" file_isfile_or_link = %d\n", file_isfile_or_link(zPath)); |
| 1383 | 1361 | fossil_print(" file_islink = %d\n", file_islink(zPath)); |
| 1384 | 1362 | fossil_print(" file_isexe(RepoFILE) = %d\n", file_isexe(zPath,RepoFILE)); |
| 1385 | 1363 | fossil_print(" file_isdir(RepoFILE) = %d\n", file_isdir(zPath,RepoFILE)); |
| 1386 | 1364 | fossil_print(" file_is_repository = %d\n", file_is_repository(zPath)); |
| 1365 | + fossil_print(" file_is_reserved_name = %d\n", | |
| 1366 | + file_is_reserved_name(zFull,-1)); | |
| 1367 | + blob_reset(&x); | |
| 1387 | 1368 | if( reset ) resetStat(); |
| 1388 | 1369 | } |
| 1389 | 1370 | |
| 1390 | 1371 | /* |
| 1391 | 1372 | ** COMMAND: test-file-environment |
| @@ -1397,17 +1378,19 @@ | ||
| 1397 | 1378 | ** |
| 1398 | 1379 | ** Options: |
| 1399 | 1380 | ** |
| 1400 | 1381 | ** --allow-symlinks BOOLEAN Temporarily turn allow-symlinks on/off |
| 1401 | 1382 | ** --open-config Open the configuration database first. |
| 1402 | -** --slash Trailing slashes, if any, are retained. | |
| 1403 | 1383 | ** --reset Reset cached stat() info for each file. |
| 1384 | +** --root ROOT Use ROOT as the root of the checkout | |
| 1385 | +** --slash Trailing slashes, if any, are retained. | |
| 1404 | 1386 | */ |
| 1405 | 1387 | void cmd_test_file_environment(void){ |
| 1406 | 1388 | int i; |
| 1407 | 1389 | int slashFlag = find_option("slash",0,0)!=0; |
| 1408 | 1390 | int resetFlag = find_option("reset",0,0)!=0; |
| 1391 | + const char *zRoot = find_option("root",0,1); | |
| 1409 | 1392 | const char *zAllow = find_option("allow-symlinks",0,1); |
| 1410 | 1393 | if( find_option("open-config", 0, 0)!=0 ){ |
| 1411 | 1394 | Th_OpenConfig(1); |
| 1412 | 1395 | } |
| 1413 | 1396 | db_find_and_open_repository(OPEN_ANY_SCHEMA|OPEN_OK_NOT_FOUND, 0); |
| @@ -1414,13 +1397,26 @@ | ||
| 1414 | 1397 | fossil_print("filenames_are_case_sensitive() = %d\n", |
| 1415 | 1398 | filenames_are_case_sensitive()); |
| 1416 | 1399 | if( zAllow ){ |
| 1417 | 1400 | g.allowSymlinks = !is_false(zAllow); |
| 1418 | 1401 | } |
| 1402 | + if( zRoot==0 ) zRoot = g.zLocalRoot; | |
| 1419 | 1403 | fossil_print("db_allow_symlinks() = %d\n", db_allow_symlinks()); |
| 1404 | + fossil_print("local-root = [%s]\n", zRoot); | |
| 1420 | 1405 | for(i=2; i<g.argc; i++){ |
| 1406 | + char *z; | |
| 1421 | 1407 | emitFileStat(g.argv[i], slashFlag, resetFlag); |
| 1408 | + z = file_canonical_name_dup(g.argv[i]); | |
| 1409 | + fossil_print(" file_canonical_name = %s\n", z); | |
| 1410 | + fossil_print(" file_nondir_path = "); | |
| 1411 | + if( fossil_strnicmp(zRoot,z,(int)strlen(zRoot))!=0 ){ | |
| 1412 | + fossil_print("(--root is not a prefix of this file)\n"); | |
| 1413 | + }else{ | |
| 1414 | + int n = file_nondir_objects_on_path(zRoot, z); | |
| 1415 | + fossil_print("%.*s\n", n, z); | |
| 1416 | + } | |
| 1417 | + fossil_free(z); | |
| 1422 | 1418 | } |
| 1423 | 1419 | } |
| 1424 | 1420 | |
| 1425 | 1421 | /* |
| 1426 | 1422 | ** COMMAND: test-canonical-name |
| @@ -2565,26 +2561,5 @@ | ||
| 2565 | 2561 | default:{ |
| 2566 | 2562 | return 0; |
| 2567 | 2563 | } |
| 2568 | 2564 | } |
| 2569 | 2565 | } |
| 2570 | - | |
| 2571 | -/* | |
| 2572 | -** COMMAND: test-is-reserved-name | |
| 2573 | -** | |
| 2574 | -** Usage: %fossil test-is-reserved-name FILENAMES... | |
| 2575 | -** | |
| 2576 | -** Passes each given name to file_is_reserved_name() and outputs one | |
| 2577 | -** line per file: the result value of that function followed by the | |
| 2578 | -** name. | |
| 2579 | -*/ | |
| 2580 | -void test_is_reserved_name_cmd(void){ | |
| 2581 | - int i; | |
| 2582 | - | |
| 2583 | - if(g.argc<3){ | |
| 2584 | - usage("FILENAME_1 [...FILENAME_N]"); | |
| 2585 | - } | |
| 2586 | - for( i = 2; i < g.argc; ++i ){ | |
| 2587 | - const int check = file_is_reserved_name(g.argv[i], -1); | |
| 2588 | - fossil_print("%d %s\n", check, g.argv[i]); | |
| 2589 | - } | |
| 2590 | -} | |
| 2591 | 2566 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -371,32 +371,10 @@ | |
| 371 | } |
| 372 | fossil_free(z); |
| 373 | return 0; |
| 374 | } |
| 375 | |
| 376 | /* |
| 377 | ** COMMAND: test-nondir-path |
| 378 | ** Usage: %fossil test-nondir-path ROOT FILE |
| 379 | ** |
| 380 | ** If there are any objects on the path from ROOT to FILE (exluding |
| 381 | ** ROOT and FILE themselves) that are not directories, then print |
| 382 | ** the name of the first object found. |
| 383 | */ |
| 384 | void test_nondir_path_cmd(void){ |
| 385 | int n; |
| 386 | if( g.argc!=4 ){ |
| 387 | usage("ROOT FILE"); |
| 388 | } |
| 389 | if( fossil_strnicmp(g.argv[2],g.argv[3],(int)strlen(g.argv[2]))!=0 ){ |
| 390 | fossil_fatal("%s should be a prefix of %s", g.argv[2], g.argv[3]); |
| 391 | } |
| 392 | n = file_nondir_objects_on_path(g.argv[2],g.argv[3]); |
| 393 | if( n ){ |
| 394 | fossil_print("%.*s\n", n, g.argv[3]); |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | /* |
| 399 | ** The file named zFile is suppose to be an in-tree file. Check to |
| 400 | ** ensure that it will be safe to write to this file by verifying that |
| 401 | ** there are no symlinks or other non-directory objects in between the |
| 402 | ** root of the checkout and zFile. |
| @@ -1333,12 +1311,12 @@ | |
| 1333 | sqlite3_int64 iMtime; |
| 1334 | struct fossilStat testFileStat; |
| 1335 | memset(zBuf, 0, sizeof(zBuf)); |
| 1336 | blob_zero(&x); |
| 1337 | file_canonical_name(zPath, &x, slash); |
| 1338 | fossil_print("[%s] -> [%s]\n", zPath, blob_buffer(&x)); |
| 1339 | blob_reset(&x); |
| 1340 | memset(&testFileStat, 0, sizeof(struct fossilStat)); |
| 1341 | rc = fossil_stat(zPath, &testFileStat, 0); |
| 1342 | fossil_print(" stat_rc = %d\n", rc); |
| 1343 | sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", testFileStat.st_size); |
| 1344 | fossil_print(" stat_size = %s\n", zBuf); |
| @@ -1382,10 +1360,13 @@ | |
| 1382 | fossil_print(" file_isfile_or_link = %d\n", file_isfile_or_link(zPath)); |
| 1383 | fossil_print(" file_islink = %d\n", file_islink(zPath)); |
| 1384 | fossil_print(" file_isexe(RepoFILE) = %d\n", file_isexe(zPath,RepoFILE)); |
| 1385 | fossil_print(" file_isdir(RepoFILE) = %d\n", file_isdir(zPath,RepoFILE)); |
| 1386 | fossil_print(" file_is_repository = %d\n", file_is_repository(zPath)); |
| 1387 | if( reset ) resetStat(); |
| 1388 | } |
| 1389 | |
| 1390 | /* |
| 1391 | ** COMMAND: test-file-environment |
| @@ -1397,17 +1378,19 @@ | |
| 1397 | ** |
| 1398 | ** Options: |
| 1399 | ** |
| 1400 | ** --allow-symlinks BOOLEAN Temporarily turn allow-symlinks on/off |
| 1401 | ** --open-config Open the configuration database first. |
| 1402 | ** --slash Trailing slashes, if any, are retained. |
| 1403 | ** --reset Reset cached stat() info for each file. |
| 1404 | */ |
| 1405 | void cmd_test_file_environment(void){ |
| 1406 | int i; |
| 1407 | int slashFlag = find_option("slash",0,0)!=0; |
| 1408 | int resetFlag = find_option("reset",0,0)!=0; |
| 1409 | const char *zAllow = find_option("allow-symlinks",0,1); |
| 1410 | if( find_option("open-config", 0, 0)!=0 ){ |
| 1411 | Th_OpenConfig(1); |
| 1412 | } |
| 1413 | db_find_and_open_repository(OPEN_ANY_SCHEMA|OPEN_OK_NOT_FOUND, 0); |
| @@ -1414,13 +1397,26 @@ | |
| 1414 | fossil_print("filenames_are_case_sensitive() = %d\n", |
| 1415 | filenames_are_case_sensitive()); |
| 1416 | if( zAllow ){ |
| 1417 | g.allowSymlinks = !is_false(zAllow); |
| 1418 | } |
| 1419 | fossil_print("db_allow_symlinks() = %d\n", db_allow_symlinks()); |
| 1420 | for(i=2; i<g.argc; i++){ |
| 1421 | emitFileStat(g.argv[i], slashFlag, resetFlag); |
| 1422 | } |
| 1423 | } |
| 1424 | |
| 1425 | /* |
| 1426 | ** COMMAND: test-canonical-name |
| @@ -2565,26 +2561,5 @@ | |
| 2565 | default:{ |
| 2566 | return 0; |
| 2567 | } |
| 2568 | } |
| 2569 | } |
| 2570 | |
| 2571 | /* |
| 2572 | ** COMMAND: test-is-reserved-name |
| 2573 | ** |
| 2574 | ** Usage: %fossil test-is-reserved-name FILENAMES... |
| 2575 | ** |
| 2576 | ** Passes each given name to file_is_reserved_name() and outputs one |
| 2577 | ** line per file: the result value of that function followed by the |
| 2578 | ** name. |
| 2579 | */ |
| 2580 | void test_is_reserved_name_cmd(void){ |
| 2581 | int i; |
| 2582 | |
| 2583 | if(g.argc<3){ |
| 2584 | usage("FILENAME_1 [...FILENAME_N]"); |
| 2585 | } |
| 2586 | for( i = 2; i < g.argc; ++i ){ |
| 2587 | const int check = file_is_reserved_name(g.argv[i], -1); |
| 2588 | fossil_print("%d %s\n", check, g.argv[i]); |
| 2589 | } |
| 2590 | } |
| 2591 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -371,32 +371,10 @@ | |
| 371 | } |
| 372 | fossil_free(z); |
| 373 | return 0; |
| 374 | } |
| 375 | |
| 376 | /* |
| 377 | ** The file named zFile is suppose to be an in-tree file. Check to |
| 378 | ** ensure that it will be safe to write to this file by verifying that |
| 379 | ** there are no symlinks or other non-directory objects in between the |
| 380 | ** root of the checkout and zFile. |
| @@ -1333,12 +1311,12 @@ | |
| 1311 | sqlite3_int64 iMtime; |
| 1312 | struct fossilStat testFileStat; |
| 1313 | memset(zBuf, 0, sizeof(zBuf)); |
| 1314 | blob_zero(&x); |
| 1315 | file_canonical_name(zPath, &x, slash); |
| 1316 | char *zFull = blob_str(&x); |
| 1317 | fossil_print("[%s] -> [%s]\n", zPath, zFull); |
| 1318 | memset(&testFileStat, 0, sizeof(struct fossilStat)); |
| 1319 | rc = fossil_stat(zPath, &testFileStat, 0); |
| 1320 | fossil_print(" stat_rc = %d\n", rc); |
| 1321 | sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", testFileStat.st_size); |
| 1322 | fossil_print(" stat_size = %s\n", zBuf); |
| @@ -1382,10 +1360,13 @@ | |
| 1360 | fossil_print(" file_isfile_or_link = %d\n", file_isfile_or_link(zPath)); |
| 1361 | fossil_print(" file_islink = %d\n", file_islink(zPath)); |
| 1362 | fossil_print(" file_isexe(RepoFILE) = %d\n", file_isexe(zPath,RepoFILE)); |
| 1363 | fossil_print(" file_isdir(RepoFILE) = %d\n", file_isdir(zPath,RepoFILE)); |
| 1364 | fossil_print(" file_is_repository = %d\n", file_is_repository(zPath)); |
| 1365 | fossil_print(" file_is_reserved_name = %d\n", |
| 1366 | file_is_reserved_name(zFull,-1)); |
| 1367 | blob_reset(&x); |
| 1368 | if( reset ) resetStat(); |
| 1369 | } |
| 1370 | |
| 1371 | /* |
| 1372 | ** COMMAND: test-file-environment |
| @@ -1397,17 +1378,19 @@ | |
| 1378 | ** |
| 1379 | ** Options: |
| 1380 | ** |
| 1381 | ** --allow-symlinks BOOLEAN Temporarily turn allow-symlinks on/off |
| 1382 | ** --open-config Open the configuration database first. |
| 1383 | ** --reset Reset cached stat() info for each file. |
| 1384 | ** --root ROOT Use ROOT as the root of the checkout |
| 1385 | ** --slash Trailing slashes, if any, are retained. |
| 1386 | */ |
| 1387 | void cmd_test_file_environment(void){ |
| 1388 | int i; |
| 1389 | int slashFlag = find_option("slash",0,0)!=0; |
| 1390 | int resetFlag = find_option("reset",0,0)!=0; |
| 1391 | const char *zRoot = find_option("root",0,1); |
| 1392 | const char *zAllow = find_option("allow-symlinks",0,1); |
| 1393 | if( find_option("open-config", 0, 0)!=0 ){ |
| 1394 | Th_OpenConfig(1); |
| 1395 | } |
| 1396 | db_find_and_open_repository(OPEN_ANY_SCHEMA|OPEN_OK_NOT_FOUND, 0); |
| @@ -1414,13 +1397,26 @@ | |
| 1397 | fossil_print("filenames_are_case_sensitive() = %d\n", |
| 1398 | filenames_are_case_sensitive()); |
| 1399 | if( zAllow ){ |
| 1400 | g.allowSymlinks = !is_false(zAllow); |
| 1401 | } |
| 1402 | if( zRoot==0 ) zRoot = g.zLocalRoot; |
| 1403 | fossil_print("db_allow_symlinks() = %d\n", db_allow_symlinks()); |
| 1404 | fossil_print("local-root = [%s]\n", zRoot); |
| 1405 | for(i=2; i<g.argc; i++){ |
| 1406 | char *z; |
| 1407 | emitFileStat(g.argv[i], slashFlag, resetFlag); |
| 1408 | z = file_canonical_name_dup(g.argv[i]); |
| 1409 | fossil_print(" file_canonical_name = %s\n", z); |
| 1410 | fossil_print(" file_nondir_path = "); |
| 1411 | if( fossil_strnicmp(zRoot,z,(int)strlen(zRoot))!=0 ){ |
| 1412 | fossil_print("(--root is not a prefix of this file)\n"); |
| 1413 | }else{ |
| 1414 | int n = file_nondir_objects_on_path(zRoot, z); |
| 1415 | fossil_print("%.*s\n", n, z); |
| 1416 | } |
| 1417 | fossil_free(z); |
| 1418 | } |
| 1419 | } |
| 1420 | |
| 1421 | /* |
| 1422 | ** COMMAND: test-canonical-name |
| @@ -2565,26 +2561,5 @@ | |
| 2561 | default:{ |
| 2562 | return 0; |
| 2563 | } |
| 2564 | } |
| 2565 | } |
| 2566 |