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.

drh 2021-03-13 00:35 trunk merge
Commit 922b5c4d1521994b2f79bffbb8183841558d74c2b76e5a860331d01a7f338091
1 file changed +17 -2
+17 -2
--- src/add.c
+++ src/add.c
@@ -375,10 +375,13 @@
375375
** --reset Reset the ADDED state of a checkout, such
376376
** that all newly-added (but not yet committed)
377377
** files are no longer added. No flags other
378378
** than --verbose and --dry-run may be used
379379
** 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.
380383
**
381384
** The following options are only valid with --reset:
382385
** -v|--verbose Output information about each --reset file
383386
** -n|--dry-run Display instead of run actions
384387
**
@@ -391,10 +394,11 @@
391394
const char *zCleanFlag; /* The --clean option or clean-glob setting */
392395
const char *zIgnoreFlag; /* The --ignore option or ignore-glob setting */
393396
Glob *pIgnore, *pClean; /* Ignore everything matching the glob patterns */
394397
unsigned scanFlags = 0; /* Flags passed to vfile_scan() */
395398
int forceFlag;
399
+ int allowReservedFlag = 0; /* --allow-reserved flag */
396400
397401
if(0!=find_option("reset",0,0)){
398402
int const verboseFlag = find_option("verbose","v",0)!=0;
399403
int const dryRunFlag = find_option("dry-run","n",0)!=0;
400404
db_must_be_within_tree();
@@ -405,10 +409,11 @@
405409
406410
zCleanFlag = find_option("clean",0,1);
407411
zIgnoreFlag = find_option("ignore",0,1);
408412
forceFlag = find_option("force","f",0)!=0;
409413
if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL;
414
+ allowReservedFlag = find_option("allow-reserved",0,0)!=0;
410415
411416
/* We should be done with options.. */
412417
verify_all_options();
413418
414419
db_must_be_within_tree();
@@ -429,17 +434,27 @@
429434
430435
/* Load the names of all files that are to be added into sfile temp table */
431436
for(i=2; i<g.argc; i++){
432437
char *zName;
433438
int isDir;
434
- Blob fullName;
439
+ Blob fullName = empty_blob;
435440
436441
/* file_tree_name() throws a fatal error if g.argv[i] is outside of the
437442
** checkout. */
438443
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
+ }
439455
blob_reset(&fullName);
440
-
441456
file_canonical_name(g.argv[i], &fullName, 0);
442457
zName = blob_str(&fullName);
443458
isDir = file_isdir(zName, RepoFILE);
444459
if( isDir==1 ){
445460
vfile_scan(&fullName, nRoot-1, scanFlags, pClean, pIgnore, RepoFILE);
446461
--- 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

Keyboard Shortcuts

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