| ︙ | | |
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
|
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
|
-
+
+
+
+
+
+
+
+
+
|
}
/*
** zDbName is the name of a database file. If no other database
** file is open, then open this one. If another database file is
** already open, then attach zDbName using the name zLabel.
*/
void db_open_or_attach(const char *zDbName, const char *zLabel){
void db_open_or_attach(
const char *zDbName,
const char *zLabel,
int *pWasAttached
){
if( !g.db ){
assert( g.zMainDbType==0 );
g.db = openDatabase(zDbName);
g.zMainDbType = zLabel;
db_connection_init();
if ( pWasAttached ) *pWasAttached = 0;
}else{
assert( g.zMainDbType!=0 );
db_attach(zDbName, zLabel);
if ( pWasAttached ) *pWasAttached = 1;
}
}
/*
** Open the user database in "~/.fossil". Create the database anew if
** it does not already exist.
**
|
| ︙ | | |
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
|
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
|
-
-
+
+
+
+
|
zDbName = mprintf("%//_fossil", zHome);
#else
zDbName = mprintf("%s/.fossil", zHome);
#endif
if( file_size(zDbName)<1024*3 ){
db_init_database(zDbName, zConfigSchema, (char*)0);
}
g.useAttach = useAttach;
if( useAttach ){
db_open_or_attach(zDbName, "configdb");
db_open_or_attach(zDbName, "configdb", &g.useAttach);
g.dbConfig = 0;
g.zConfigDbType = 0;
}else{
g.useAttach = 0;
g.dbConfig = openDatabase(zDbName);
g.zConfigDbType = "configdb";
}
g.configOpen = 1;
free(zDbName);
}
/*
|
| ︙ | | |
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
|
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
|
-
+
|
static int isValidLocalDb(const char *zDbName){
i64 lsize;
char *zVFileDef;
if( file_access(zDbName, F_OK) ) return 0;
lsize = file_size(zDbName);
if( lsize%1024!=0 || lsize<4096 ) return 0;
db_open_or_attach(zDbName, "localdb");
db_open_or_attach(zDbName, "localdb", 0);
zVFileDef = db_text(0, "SELECT sql FROM %s.sqlite_master"
" WHERE name=='vfile'", db_name("localdb"));
/* 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.
*/
|
| ︙ | | |
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
|
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
|
-
+
|
}else{
#ifdef FOSSIL_ENABLE_JSON
g.json.resultCode = FSL_JSON_E_DB_NOT_VALID;
#endif
fossil_panic("not a valid repository: %s", zDbName);
}
}
db_open_or_attach(zDbName, "repository");
db_open_or_attach(zDbName, "repository", 0);
g.repositoryOpen = 1;
g.zRepositoryName = mprintf("%s", zDbName);
/* Cache "allow-symlinks" option, because we'll need it on every stat call */
g.allowSymlinks = db_get_boolean("allow-symlinks", 0);
}
/*
|
| ︙ | | |
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
|
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
|
-
+
|
return;
}
file_canonical_name(g.argv[2], &repo, 0);
zRepo = blob_str(&repo);
if( file_access(zRepo, 0) ){
fossil_fatal("no such file: %s", zRepo);
}
db_open_or_attach(zRepo, "test_repo");
db_open_or_attach(zRepo, "test_repo", 0);
db_lset("repository", blob_str(&repo));
db_close(1);
}
/*
** Open the local database. If unable, exit with an error.
|
| ︙ | | |
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
|
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
|
+
+
|
}
g.repositoryOpen = 0;
g.localOpen = 0;
g.configOpen = 0;
sqlite3_wal_checkpoint(g.db, 0);
sqlite3_close(g.db);
g.db = 0;
g.zMainDbType = 0;
if( g.dbConfig ){
sqlite3_close(g.dbConfig);
g.dbConfig = 0;
g.zConfigDbType = 0;
}
}
/*
** Create a new empty repository database with the given name.
**
|
| ︙ | | |
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
|
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
|
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
|
}
/*
** Swap the g.db and g.dbConfig connections so that the various db_* routines
** work on the ~/.fossil database instead of on the repository database.
** Be sure to swap them back after doing the operation.
**
** If g.useAttach that means the ~/.fossil database was opened with
** the useAttach flag set to 1. In that case no connection swap is required
** so this routine is a no-op.
** If the ~/.fossil database has already been opened as the main database or
** is attached to the main database, no connection swaps are required so this
** routine is a no-op.
*/
void db_swap_connections(void){
/*
** When swapping the main database connection with the config database
** connection, the config database connection must be open (not simply
** attached); otherwise, the swap would end up leaving the main database
** connection invalid, defeating the very purpose of this routine. This
** same constraint also holds true when restoring the previously swapped
** database connection; otherwise, it means that no swap was performed
** because the main database connection was already pointing to the config
** database.
*/
if( !g.useAttach ){
if( g.dbConfig ){
sqlite3 *dbTemp = g.db;
const char *zTempDbType = g.zMainDbType;
g.db = g.dbConfig;
g.zMainDbType = g.zConfigDbType;
g.dbConfig = dbTemp;
g.zConfigDbType = zTempDbType;
}
}
/*
** Logic for reading potentially versioned settings from
** .fossil-settings/<name> , and emits warnings if necessary.
** Returns the non-versioned value without modification if there is no
|
| ︙ | | |