Fossil SCM

Avoid the use of chdir() since this seems to cause problems on windows.

drh 2008-07-17 01:49 trunk
Commit 849b94c6317f855aed30ed371f75229c13cfe038
2 files changed +8 -6 +10 -14
+8 -6
--- src/checkin.c
+++ src/checkin.c
@@ -155,15 +155,16 @@
155155
** the current checkout. See also the "clean" command.
156156
*/
157157
void extra_cmd(void){
158158
Blob path;
159159
Stmt q;
160
+ int n;
160161
db_must_be_within_tree();
161162
db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)");
162
- chdir(g.zLocalRoot);
163
- blob_zero(&path);
164
- vfile_scan(0, &path);
163
+ n = strlen(g.zLocalRoot);
164
+ blob_init(&path, g.zLocalRoot, n-1);
165
+ vfile_scan(0, &path, blob_size(&path));
165166
db_prepare(&q,
166167
"SELECT x FROM sfile"
167168
" WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_')"
168169
" ORDER BY 1");
169170
while( db_step(&q)==SQLITE_ROW ){
@@ -186,16 +187,17 @@
186187
*/
187188
void clean_cmd(void){
188189
int allFlag;
189190
Blob path;
190191
Stmt q;
192
+ int n;
191193
allFlag = find_option("all","a",0)!=0;
192194
db_must_be_within_tree();
193195
db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)");
194
- chdir(g.zLocalRoot);
195
- blob_zero(&path);
196
- vfile_scan(0, &path);
196
+ n = strlen(g.zLocalRoot);
197
+ blob_init(&path, g.zLocalRoot, n-1);
198
+ vfile_scan(0, &path, blob_size(&path));
197199
db_prepare(&q,
198200
"SELECT %Q || x FROM sfile"
199201
" WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_')"
200202
" ORDER BY 1", g.zLocalRoot);
201203
while( db_step(&q)==SQLITE_ROW ){
202204
--- src/checkin.c
+++ src/checkin.c
@@ -155,15 +155,16 @@
155 ** the current checkout. See also the "clean" command.
156 */
157 void extra_cmd(void){
158 Blob path;
159 Stmt q;
 
160 db_must_be_within_tree();
161 db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)");
162 chdir(g.zLocalRoot);
163 blob_zero(&path);
164 vfile_scan(0, &path);
165 db_prepare(&q,
166 "SELECT x FROM sfile"
167 " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_')"
168 " ORDER BY 1");
169 while( db_step(&q)==SQLITE_ROW ){
@@ -186,16 +187,17 @@
186 */
187 void clean_cmd(void){
188 int allFlag;
189 Blob path;
190 Stmt q;
 
191 allFlag = find_option("all","a",0)!=0;
192 db_must_be_within_tree();
193 db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)");
194 chdir(g.zLocalRoot);
195 blob_zero(&path);
196 vfile_scan(0, &path);
197 db_prepare(&q,
198 "SELECT %Q || x FROM sfile"
199 " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_')"
200 " ORDER BY 1", g.zLocalRoot);
201 while( db_step(&q)==SQLITE_ROW ){
202
--- src/checkin.c
+++ src/checkin.c
@@ -155,15 +155,16 @@
155 ** the current checkout. See also the "clean" command.
156 */
157 void extra_cmd(void){
158 Blob path;
159 Stmt q;
160 int n;
161 db_must_be_within_tree();
162 db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)");
163 n = strlen(g.zLocalRoot);
164 blob_init(&path, g.zLocalRoot, n-1);
165 vfile_scan(0, &path, blob_size(&path));
166 db_prepare(&q,
167 "SELECT x FROM sfile"
168 " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_')"
169 " ORDER BY 1");
170 while( db_step(&q)==SQLITE_ROW ){
@@ -186,16 +187,17 @@
187 */
188 void clean_cmd(void){
189 int allFlag;
190 Blob path;
191 Stmt q;
192 int n;
193 allFlag = find_option("all","a",0)!=0;
194 db_must_be_within_tree();
195 db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)");
196 n = strlen(g.zLocalRoot);
197 blob_init(&path, g.zLocalRoot, n-1);
198 vfile_scan(0, &path, blob_size(&path));
199 db_prepare(&q,
200 "SELECT %Q || x FROM sfile"
201 " WHERE x NOT IN ('manifest','manifest.uuid','_FOSSIL_')"
202 " ORDER BY 1", g.zLocalRoot);
203 while( db_step(&q)==SQLITE_ROW ){
204
+10 -14
--- src/vfile.c
+++ src/vfile.c
@@ -240,41 +240,37 @@
240240
db_finalize(&q);
241241
}
242242
243243
/*
244244
** Load into table SFILE the name of every ordinary file in
245
-** the directory pPath. Subdirectories are scanned recursively.
245
+** the directory pPath. Omit the first nPrefix characters of
246
+** of pPath when inserting into the SFILE table.
247
+**
248
+** Subdirectories are scanned recursively.
246249
** Omit files named in VFILE.vid
247250
*/
248
-void vfile_scan(int vid, Blob *pPath){
251
+void vfile_scan(int vid, Blob *pPath, int nPrefix){
249252
DIR *d;
250253
int origSize;
251254
const char *zDir;
252
- const char *zFormat;
253255
struct dirent *pEntry;
254256
static const char *zSql = "SELECT 1 FROM vfile "
255
- " WHERE pathname=%B AND NOT deleted";
257
+ " WHERE pathname=%Q AND NOT deleted";
256258
257259
origSize = blob_size(pPath);
258260
zDir = blob_str(pPath);
259
- if( zDir[0]==0 ){
260
- zDir = ".";
261
- zFormat = "%s";
262
- }else{
263
- zFormat = "/%s";
264
- }
265261
d = opendir(zDir);
266262
if( d ){
267263
while( (pEntry=readdir(d))!=0 ){
268264
char *zPath;
269265
if( pEntry->d_name[0]=='.' ) continue;
270
- blob_appendf(pPath, zFormat, pEntry->d_name);
266
+ blob_appendf(pPath, "/%s", pEntry->d_name);
271267
zPath = blob_str(pPath);
272268
if( file_isdir(zPath)==1 ){
273
- vfile_scan(vid, pPath);
274
- }else if( file_isfile(zPath) && !db_exists(zSql,pPath) ){
275
- db_multi_exec("INSERT INTO sfile VALUES(%B)", pPath);
269
+ vfile_scan(vid, pPath, nPrefix);
270
+ }else if( file_isfile(zPath) && !db_exists(zSql, &zPath[nPrefix+1]) ){
271
+ db_multi_exec("INSERT INTO sfile VALUES(%Q)", &zPath[nPrefix+1]);
276272
}
277273
blob_resize(pPath, origSize);
278274
}
279275
}
280276
closedir(d);
281277
--- src/vfile.c
+++ src/vfile.c
@@ -240,41 +240,37 @@
240 db_finalize(&q);
241 }
242
243 /*
244 ** Load into table SFILE the name of every ordinary file in
245 ** the directory pPath. Subdirectories are scanned recursively.
 
 
 
246 ** Omit files named in VFILE.vid
247 */
248 void vfile_scan(int vid, Blob *pPath){
249 DIR *d;
250 int origSize;
251 const char *zDir;
252 const char *zFormat;
253 struct dirent *pEntry;
254 static const char *zSql = "SELECT 1 FROM vfile "
255 " WHERE pathname=%B AND NOT deleted";
256
257 origSize = blob_size(pPath);
258 zDir = blob_str(pPath);
259 if( zDir[0]==0 ){
260 zDir = ".";
261 zFormat = "%s";
262 }else{
263 zFormat = "/%s";
264 }
265 d = opendir(zDir);
266 if( d ){
267 while( (pEntry=readdir(d))!=0 ){
268 char *zPath;
269 if( pEntry->d_name[0]=='.' ) continue;
270 blob_appendf(pPath, zFormat, pEntry->d_name);
271 zPath = blob_str(pPath);
272 if( file_isdir(zPath)==1 ){
273 vfile_scan(vid, pPath);
274 }else if( file_isfile(zPath) && !db_exists(zSql,pPath) ){
275 db_multi_exec("INSERT INTO sfile VALUES(%B)", pPath);
276 }
277 blob_resize(pPath, origSize);
278 }
279 }
280 closedir(d);
281
--- src/vfile.c
+++ src/vfile.c
@@ -240,41 +240,37 @@
240 db_finalize(&q);
241 }
242
243 /*
244 ** Load into table SFILE the name of every ordinary file in
245 ** the directory pPath. Omit the first nPrefix characters of
246 ** of pPath when inserting into the SFILE table.
247 **
248 ** Subdirectories are scanned recursively.
249 ** Omit files named in VFILE.vid
250 */
251 void vfile_scan(int vid, Blob *pPath, int nPrefix){
252 DIR *d;
253 int origSize;
254 const char *zDir;
 
255 struct dirent *pEntry;
256 static const char *zSql = "SELECT 1 FROM vfile "
257 " WHERE pathname=%Q AND NOT deleted";
258
259 origSize = blob_size(pPath);
260 zDir = blob_str(pPath);
 
 
 
 
 
 
261 d = opendir(zDir);
262 if( d ){
263 while( (pEntry=readdir(d))!=0 ){
264 char *zPath;
265 if( pEntry->d_name[0]=='.' ) continue;
266 blob_appendf(pPath, "/%s", pEntry->d_name);
267 zPath = blob_str(pPath);
268 if( file_isdir(zPath)==1 ){
269 vfile_scan(vid, pPath, nPrefix);
270 }else if( file_isfile(zPath) && !db_exists(zSql, &zPath[nPrefix+1]) ){
271 db_multi_exec("INSERT INTO sfile VALUES(%Q)", &zPath[nPrefix+1]);
272 }
273 blob_resize(pPath, origSize);
274 }
275 }
276 closedir(d);
277

Keyboard Shortcuts

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