1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
|
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
|
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
-
+
+
+
+
+
|
/*
** If zDbName is a valid local database file, open it and return
** true. If it is not a valid local database file, return 0.
*/
static int isValidLocalDb(const char *zDbName){
i64 lsize;
char *zVFileDef;
if( file_access(zDbName, F_OK) ) return 0;
lsize = file_size(zDbName, ExtFILE);
if( lsize%1024!=0 || lsize<4096 ) return 0;
db_open_or_attach(zDbName, "localdb");
zVFileDef = db_text(0, "SELECT sql FROM localdb.sqlite_master"
" WHERE name=='vfile'");
if( zVFileDef==0 ) return 0;
/* Check to see if the checkout database has the lastest schema changes.
** The most recent schema change (2019-01-19) is the addition of the
** vmerge.mhash field. If the schema has that one column, assume
** everything else is up-to-date.
*/
if( db_table_has_column("localdb","vmerge","mhash") ){
return 1; /* This is a checkout database with the latest schema */
}
/* If there is no vfile table, then assume we have picked up something
** that is not even close to being a valid checkout database */
if( !db_table_exists("localdb","vfile") ){
return 0; /* Not a DB */
}
/* If the "isexe" column is missing from the vfile table, then
** add it now. This code added on 2010-03-06. After all users have
** upgraded, this code can be safely deleted.
*/
if( sqlite3_strglob("* isexe *", zVFileDef)!=0 ){
if( !db_table_has_column("localdb","vfile","isexe") ){
db_multi_exec("ALTER TABLE vfile ADD COLUMN isexe BOOLEAN DEFAULT 0");
}
/* If "islink"/"isLink" columns are missing from tables, then
** add them now. This code added on 2011-01-17 and 2011-08-27.
** After all users have upgraded, this code can be safely deleted.
*/
if( sqlite3_strglob("* islink *", zVFileDef)!=0 ){
if( !db_table_has_column("localdb","vfile","isLink") ){
db_multi_exec("ALTER TABLE vfile ADD COLUMN islink BOOLEAN DEFAULT 0");
if( db_local_table_exists_but_lacks_column("stashfile", "isLink") ){
db_multi_exec("ALTER TABLE stashfile ADD COLUMN isLink BOOL DEFAULT 0");
}
if( db_local_table_exists_but_lacks_column("undo", "isLink") ){
db_multi_exec("ALTER TABLE undo ADD COLUMN isLink BOOLEAN DEFAULT 0");
}
if( db_local_table_exists_but_lacks_column("undo_vfile", "islink") ){
db_multi_exec("ALTER TABLE undo_vfile ADD COLUMN islink BOOL DEFAULT 0");
}
}
fossil_free(zVFileDef);
/* The design of the vmerge table changed on 2019-01-19, adding the mhash
** column and changing the UNIQUE index. However, we must ahve 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.
|
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
|
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
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
|
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
}
/* Make a change to the CHECK constraint on the BLOB table for
** version 2.0 and later.
*/
rebuild_schema_update_2_0(); /* Do the Fossil-2.0 schema updates */
/* Additional checks that occur when opening the checkout database */
if( g.localOpen ){
/* If the checkout database was opened first, then check to make
** sure that the repository database that was just opened has not
** be replaced by a clone of the same project, with different RID
** values.
*/
if( g.localOpen && !db_fingerprint_ok() ){
/* Uncomment the following when we are ready for automatic recovery: */
/* Ensure that the repository database that was just opened has not
** be replaced by a clone of the same project, with different RID
** values.
*/
if( !db_fingerprint_ok() ){
/* Uncomment the following when we are ready for automatic recovery: */
#if 0
stash_rid_renumbering_event();
stash_rid_renumbering_event();
#else
fossil_print(
"Oops. It looks like the repository database file located at\n"
" \"%s\"\n", zDbName
);
fossil_print(
"has been swapped with a clone that may have different\n"
"integer keys for the various artifacts. As of 2019-01-11,\n"
"we are working on enhancing Fossil to be able to deal with\n"
"that automatically, but we are not there yet. Sorry.\n\n"
);
fossil_print(
"As an interim workaround, try:\n"
" %s close --force\n"
" %s open \"%s\" --keep\n"
"Noting that any STASH and UNDO information "
"WILL BE IRREVOCABLY LOST.\n\n",
g.argv[0],
g.argv[0], zDbName
);
fossil_fatal("bad fingerprint");
fossil_print(
"Oops. It looks like the repository database file located at\n"
" \"%s\"\n", zDbName
);
fossil_print(
"has been swapped with a clone that may have different\n"
"integer keys for the various artifacts. As of 2019-01-11,\n"
"we are working on enhancing Fossil to be able to deal with\n"
"that automatically, but we are not there yet. Sorry.\n\n"
);
fossil_print(
"As an interim workaround, try:\n"
" %s close --force\n"
" %s open \"%s\" --keep\n"
"Noting that any STASH and UNDO information "
"WILL BE IRREVOCABLY LOST.\n\n",
g.argv[0],
g.argv[0], zDbName
);
fossil_fatal("bad fingerprint");
#endif
}else
/* Make sure the checkout database schema migration of 2019-01-19
** (the addition of the vmerge.mhash column and making that columns
** part of the PRIMARY KEY) has occurred.
*/
if( !db_table_has_column("localdb", "vmerge", "mhash") ){
db_multi_exec("ALTER TABLE vmerge RENAME TO old_vmerge;");
db_multi_exec(zLocalSchemaVmerge /*works-like:""*/);
db_multi_exec(
"INSERT OR IGNORE INTO vmerge(id,merge,mhash)"
" SELECT id, merge, blob.uuid FROM old_vmerge, blob"
" WHERE old_vmerge.merge=blob.rid;"
"DROP TABLE old_vmerge;"
);
}
}
}
/*
** Return true if there have been any changes to the repository
** database since it was opened.
**
|
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
|
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
|
-
+
|
}
#if defined(_WIN32) || defined(__CYGWIN__)
# define LOCALDB_NAME "./_FOSSIL_"
#else
# define LOCALDB_NAME "./.fslckout"
#endif
db_init_database(LOCALDB_NAME, zLocalSchema,
db_init_database(LOCALDB_NAME, zLocalSchema, zLocalSchemaVmerge,
#ifdef FOSSIL_LOCAL_WAL
"COMMIT; PRAGMA journal_mode=WAL; BEGIN;",
#endif
(char*)0);
db_delete_on_failure(LOCALDB_NAME);
db_open_local(0);
if( allowSymlinks>=0 ){
|