Fossil

Check-in [ddd1273ea2]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Part 1 of ticket [980a72dedd]: efficient check for determining whether a filename ends with a checkout db name.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | reject-ckout-db
Files: files | file ages | folders
SHA3-256: ddd1273ea2358dd9882bb296346f63a2ad55ccccda798928ac9eb25e54a39f1a
User & Date: stephan 2020-08-17 15:17:29.675
Context
2020-08-17
15:40
switch/case style tweak, per request. check-in: 9784e5cdab user: stephan tags: reject-ckout-db
15:17
Part 1 of ticket [980a72dedd]: efficient check for determining whether a filename ends with a checkout db name. check-in: ddd1273ea2 user: stephan tags: reject-ckout-db
07:02
Reinstate symlink capability. (Unintended change with prior symlink test?) check-in: c840617b8b user: andygoth tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/db.c.
1702
1703
1704
1705
1706
1707
1708























































1709
1710
1711
1712
1713
1714
1715
  /* The design of the checkout database changed on 2019-01-19, adding the mhash
  ** column to vfile and vmerge and changing the UNIQUE index on vmerge into
  ** a PRIMARY KEY that includes the new mhash column.  However, we must have
  ** the repository database at hand in order to do the migration, so that
  ** step is deferred. */
  return 1;
}
























































/*
** Locate the root directory of the local repository tree.  The root
** directory is found by searching for a file named "_FOSSIL_" or ".fslckout"
** that contains a valid repository database.
**
** For legacy, also look for ".fos".  The use of ".fos" is deprecated







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
  /* The design of the checkout database changed on 2019-01-19, adding the mhash
  ** column to vfile and vmerge and changing the UNIQUE index on vmerge into
  ** a PRIMARY KEY that includes the new mhash column.  However, we must have
  ** the repository database at hand in order to do the migration, so that
  ** step is deferred. */
  return 1;
}

/*
** Returns true if the given filename ends with any of fossil's
** checkout database filenames: _FOSSIL_ or .fslckout. Specifically,
** it returns 1 if it's an exact match and 2 if it's the tail match
** on a longer input.
**
** zFilename must, for efficiency's sake, be a
** canonicalized/normalized name, e.g. using only '/' as directory
** separators.
**
** nFilename must be the strlen of zFilename. If it is negative,
** strlen() is used to calculate it.
*/
int is_fossil_ckout_db_name(const char *zFilename, int nFilename){
  const char *zEnd;

  if(nFilename>=0 && nFilename<8/*strlen _FOSSIL_*/) return 0;
  else if(nFilename<0) nFilename = (int)strlen(zFilename);
  if(nFilename<8) return 0;
  zEnd = zFilename + nFilename;
  switch(zEnd[-1]){
    case '_':
      return fossil_strcmp("_FOSSIL_", &zEnd[-8])
        ? 0 : (8==nFilename ? 1 : ('/'==zEnd[-9] ? 2 : 0));
    case 't':
      return (nFilename<9
              || '.'!=zEnd[-9]
              || fossil_strcmp(".fslckout", &zEnd[-9]))
        ? 0 : (9==nFilename ? 1 : ('/'==zEnd[-10] ? 2 : 0));
    default:
      return 0;
  }
}

/*
** COMMAND: test-is-ckout-db
**
** Usage: %fossil test-is-ckout-db FILENAMES...
**
** Passes each given name to is_fossil_ckout_db_name() and outputs one
** line per file: the result value of that function followed by the
** name.
*/
void test_is_ckout_name_cmd(void){
  int i;

  if(g.argc<3){
    usage("FILENAME_1 [...FILENAME_N]");
  }
  for( i = 2; i < g.argc; ++i ){
    const int check = is_fossil_ckout_db_name(g.argv[i], -1);
    fossil_print("%d %s\n", check, g.argv[i]);
  }
}

/*
** Locate the root directory of the local repository tree.  The root
** directory is found by searching for a file named "_FOSSIL_" or ".fslckout"
** that contains a valid repository database.
**
** For legacy, also look for ".fos".  The use of ".fos" is deprecated