Fossil SCM
The 'add' command now fails for filenames that are reserved on Windows unless the --allow-reserved flag is used. See [forum:5116485456|forum discussion 5116485456] for more details.
Commit
922b5c4d1521994b2f79bffbb8183841558d74c2b76e5a860331d01a7f338091
Parent
b06953e15e93b4c…
1 file changed
+17
-2
+17
-2
| --- src/add.c | ||
| +++ src/add.c | ||
| @@ -375,10 +375,13 @@ | ||
| 375 | 375 | ** --reset Reset the ADDED state of a checkout, such |
| 376 | 376 | ** that all newly-added (but not yet committed) |
| 377 | 377 | ** files are no longer added. No flags other |
| 378 | 378 | ** than --verbose and --dry-run may be used |
| 379 | 379 | ** with --reset. |
| 380 | +** --allow-reserved Permit filenames which are reserved on | |
| 381 | +** Windows platforms. Such files cannot be | |
| 382 | +** checked out on Windows, so use with care. | |
| 380 | 383 | ** |
| 381 | 384 | ** The following options are only valid with --reset: |
| 382 | 385 | ** -v|--verbose Output information about each --reset file |
| 383 | 386 | ** -n|--dry-run Display instead of run actions |
| 384 | 387 | ** |
| @@ -391,10 +394,11 @@ | ||
| 391 | 394 | const char *zCleanFlag; /* The --clean option or clean-glob setting */ |
| 392 | 395 | const char *zIgnoreFlag; /* The --ignore option or ignore-glob setting */ |
| 393 | 396 | Glob *pIgnore, *pClean; /* Ignore everything matching the glob patterns */ |
| 394 | 397 | unsigned scanFlags = 0; /* Flags passed to vfile_scan() */ |
| 395 | 398 | int forceFlag; |
| 399 | + int allowReservedFlag = 0; /* --allow-reserved flag */ | |
| 396 | 400 | |
| 397 | 401 | if(0!=find_option("reset",0,0)){ |
| 398 | 402 | int const verboseFlag = find_option("verbose","v",0)!=0; |
| 399 | 403 | int const dryRunFlag = find_option("dry-run","n",0)!=0; |
| 400 | 404 | db_must_be_within_tree(); |
| @@ -405,10 +409,11 @@ | ||
| 405 | 409 | |
| 406 | 410 | zCleanFlag = find_option("clean",0,1); |
| 407 | 411 | zIgnoreFlag = find_option("ignore",0,1); |
| 408 | 412 | forceFlag = find_option("force","f",0)!=0; |
| 409 | 413 | if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL; |
| 414 | + allowReservedFlag = find_option("allow-reserved",0,0)!=0; | |
| 410 | 415 | |
| 411 | 416 | /* We should be done with options.. */ |
| 412 | 417 | verify_all_options(); |
| 413 | 418 | |
| 414 | 419 | db_must_be_within_tree(); |
| @@ -429,17 +434,27 @@ | ||
| 429 | 434 | |
| 430 | 435 | /* Load the names of all files that are to be added into sfile temp table */ |
| 431 | 436 | for(i=2; i<g.argc; i++){ |
| 432 | 437 | char *zName; |
| 433 | 438 | int isDir; |
| 434 | - Blob fullName; | |
| 439 | + Blob fullName = empty_blob; | |
| 435 | 440 | |
| 436 | 441 | /* file_tree_name() throws a fatal error if g.argv[i] is outside of the |
| 437 | 442 | ** checkout. */ |
| 438 | 443 | file_tree_name(g.argv[i], &fullName, 0, 1); |
| 444 | + if(0==allowReservedFlag | |
| 445 | + && 0!=file_is_win_reserved(blob_str(&fullName))){ | |
| 446 | + /* Note that the 'add' internal machinery already _silently_ | |
| 447 | + ** skips over any names for which file_is_reserved_name() | |
| 448 | + ** returns true or which is in the fossil_reserved_name() | |
| 449 | + ** list. We do not need to warn for those, as they're outright | |
| 450 | + ** verboten. */ | |
| 451 | + fossil_fatal("Filename is reserved: %b\n" | |
| 452 | + "Use --allow-reserved to permit " | |
| 453 | + "reserved filenames.", &fullName); | |
| 454 | + } | |
| 439 | 455 | blob_reset(&fullName); |
| 440 | - | |
| 441 | 456 | file_canonical_name(g.argv[i], &fullName, 0); |
| 442 | 457 | zName = blob_str(&fullName); |
| 443 | 458 | isDir = file_isdir(zName, RepoFILE); |
| 444 | 459 | if( isDir==1 ){ |
| 445 | 460 | vfile_scan(&fullName, nRoot-1, scanFlags, pClean, pIgnore, RepoFILE); |
| 446 | 461 |
| --- src/add.c | |
| +++ src/add.c | |
| @@ -375,10 +375,13 @@ | |
| 375 | ** --reset Reset the ADDED state of a checkout, such |
| 376 | ** that all newly-added (but not yet committed) |
| 377 | ** files are no longer added. No flags other |
| 378 | ** than --verbose and --dry-run may be used |
| 379 | ** with --reset. |
| 380 | ** |
| 381 | ** The following options are only valid with --reset: |
| 382 | ** -v|--verbose Output information about each --reset file |
| 383 | ** -n|--dry-run Display instead of run actions |
| 384 | ** |
| @@ -391,10 +394,11 @@ | |
| 391 | const char *zCleanFlag; /* The --clean option or clean-glob setting */ |
| 392 | const char *zIgnoreFlag; /* The --ignore option or ignore-glob setting */ |
| 393 | Glob *pIgnore, *pClean; /* Ignore everything matching the glob patterns */ |
| 394 | unsigned scanFlags = 0; /* Flags passed to vfile_scan() */ |
| 395 | int forceFlag; |
| 396 | |
| 397 | if(0!=find_option("reset",0,0)){ |
| 398 | int const verboseFlag = find_option("verbose","v",0)!=0; |
| 399 | int const dryRunFlag = find_option("dry-run","n",0)!=0; |
| 400 | db_must_be_within_tree(); |
| @@ -405,10 +409,11 @@ | |
| 405 | |
| 406 | zCleanFlag = find_option("clean",0,1); |
| 407 | zIgnoreFlag = find_option("ignore",0,1); |
| 408 | forceFlag = find_option("force","f",0)!=0; |
| 409 | if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL; |
| 410 | |
| 411 | /* We should be done with options.. */ |
| 412 | verify_all_options(); |
| 413 | |
| 414 | db_must_be_within_tree(); |
| @@ -429,17 +434,27 @@ | |
| 429 | |
| 430 | /* Load the names of all files that are to be added into sfile temp table */ |
| 431 | for(i=2; i<g.argc; i++){ |
| 432 | char *zName; |
| 433 | int isDir; |
| 434 | Blob fullName; |
| 435 | |
| 436 | /* file_tree_name() throws a fatal error if g.argv[i] is outside of the |
| 437 | ** checkout. */ |
| 438 | file_tree_name(g.argv[i], &fullName, 0, 1); |
| 439 | blob_reset(&fullName); |
| 440 | |
| 441 | file_canonical_name(g.argv[i], &fullName, 0); |
| 442 | zName = blob_str(&fullName); |
| 443 | isDir = file_isdir(zName, RepoFILE); |
| 444 | if( isDir==1 ){ |
| 445 | vfile_scan(&fullName, nRoot-1, scanFlags, pClean, pIgnore, RepoFILE); |
| 446 |
| --- src/add.c | |
| +++ src/add.c | |
| @@ -375,10 +375,13 @@ | |
| 375 | ** --reset Reset the ADDED state of a checkout, such |
| 376 | ** that all newly-added (but not yet committed) |
| 377 | ** files are no longer added. No flags other |
| 378 | ** than --verbose and --dry-run may be used |
| 379 | ** with --reset. |
| 380 | ** --allow-reserved Permit filenames which are reserved on |
| 381 | ** Windows platforms. Such files cannot be |
| 382 | ** checked out on Windows, so use with care. |
| 383 | ** |
| 384 | ** The following options are only valid with --reset: |
| 385 | ** -v|--verbose Output information about each --reset file |
| 386 | ** -n|--dry-run Display instead of run actions |
| 387 | ** |
| @@ -391,10 +394,11 @@ | |
| 394 | const char *zCleanFlag; /* The --clean option or clean-glob setting */ |
| 395 | const char *zIgnoreFlag; /* The --ignore option or ignore-glob setting */ |
| 396 | Glob *pIgnore, *pClean; /* Ignore everything matching the glob patterns */ |
| 397 | unsigned scanFlags = 0; /* Flags passed to vfile_scan() */ |
| 398 | int forceFlag; |
| 399 | int allowReservedFlag = 0; /* --allow-reserved flag */ |
| 400 | |
| 401 | if(0!=find_option("reset",0,0)){ |
| 402 | int const verboseFlag = find_option("verbose","v",0)!=0; |
| 403 | int const dryRunFlag = find_option("dry-run","n",0)!=0; |
| 404 | db_must_be_within_tree(); |
| @@ -405,10 +409,11 @@ | |
| 409 | |
| 410 | zCleanFlag = find_option("clean",0,1); |
| 411 | zIgnoreFlag = find_option("ignore",0,1); |
| 412 | forceFlag = find_option("force","f",0)!=0; |
| 413 | if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL; |
| 414 | allowReservedFlag = find_option("allow-reserved",0,0)!=0; |
| 415 | |
| 416 | /* We should be done with options.. */ |
| 417 | verify_all_options(); |
| 418 | |
| 419 | db_must_be_within_tree(); |
| @@ -429,17 +434,27 @@ | |
| 434 | |
| 435 | /* Load the names of all files that are to be added into sfile temp table */ |
| 436 | for(i=2; i<g.argc; i++){ |
| 437 | char *zName; |
| 438 | int isDir; |
| 439 | Blob fullName = empty_blob; |
| 440 | |
| 441 | /* file_tree_name() throws a fatal error if g.argv[i] is outside of the |
| 442 | ** checkout. */ |
| 443 | file_tree_name(g.argv[i], &fullName, 0, 1); |
| 444 | if(0==allowReservedFlag |
| 445 | && 0!=file_is_win_reserved(blob_str(&fullName))){ |
| 446 | /* Note that the 'add' internal machinery already _silently_ |
| 447 | ** skips over any names for which file_is_reserved_name() |
| 448 | ** returns true or which is in the fossil_reserved_name() |
| 449 | ** list. We do not need to warn for those, as they're outright |
| 450 | ** verboten. */ |
| 451 | fossil_fatal("Filename is reserved: %b\n" |
| 452 | "Use --allow-reserved to permit " |
| 453 | "reserved filenames.", &fullName); |
| 454 | } |
| 455 | blob_reset(&fullName); |
| 456 | file_canonical_name(g.argv[i], &fullName, 0); |
| 457 | zName = blob_str(&fullName); |
| 458 | isDir = file_isdir(zName, RepoFILE); |
| 459 | if( isDir==1 ){ |
| 460 | vfile_scan(&fullName, nRoot-1, scanFlags, pClean, pIgnore, RepoFILE); |
| 461 |