Fossil SCM

Make the mtime-changes setting the default. Avoid redundant calls to stat().

drh 2010-01-20 20:35 trunk
Commit d7a583e697fdbbb4e5e219434fc6e7a39f0bab1d
3 files changed +1 -1 +68 -57 +3 -3
+1 -1
--- src/db.c
+++ src/db.c
@@ -1502,11 +1502,11 @@
15021502
** 127.0.0.1 be authenticated by password. If
15031503
** false, all HTTP requests from localhost have
15041504
** unrestricted access to the repository.
15051505
**
15061506
** mtime-changes Use file modification times (mtimes) to detect when
1507
-** files have been modified.
1507
+** files have been modified. (Default "on".)
15081508
**
15091509
** pgp-command Command used to clear-sign manifests at check-in.
15101510
** The default is "gpg --clearsign -o ".
15111511
**
15121512
** proxy URL of the HTTP proxy. If undefined or "off" then
15131513
--- src/db.c
+++ src/db.c
@@ -1502,11 +1502,11 @@
1502 ** 127.0.0.1 be authenticated by password. If
1503 ** false, all HTTP requests from localhost have
1504 ** unrestricted access to the repository.
1505 **
1506 ** mtime-changes Use file modification times (mtimes) to detect when
1507 ** files have been modified.
1508 **
1509 ** pgp-command Command used to clear-sign manifests at check-in.
1510 ** The default is "gpg --clearsign -o ".
1511 **
1512 ** proxy URL of the HTTP proxy. If undefined or "off" then
1513
--- src/db.c
+++ src/db.c
@@ -1502,11 +1502,11 @@
1502 ** 127.0.0.1 be authenticated by password. If
1503 ** false, all HTTP requests from localhost have
1504 ** unrestricted access to the repository.
1505 **
1506 ** mtime-changes Use file modification times (mtimes) to detect when
1507 ** files have been modified. (Default "on".)
1508 **
1509 ** pgp-command Command used to clear-sign manifests at check-in.
1510 ** The default is "gpg --clearsign -o ".
1511 **
1512 ** proxy URL of the HTTP proxy. If undefined or "off" then
1513
+68 -57
--- src/file.c
+++ src/file.c
@@ -27,33 +27,90 @@
2727
#include <sys/types.h>
2828
#include <sys/stat.h>
2929
#include <unistd.h>
3030
#include "file.h"
3131
32
+/*
33
+** The file status information from the most recent stat() call.
34
+*/
35
+static struct stat fileStat;
36
+static int fileStatValid = 0;
37
+
38
+/*
39
+** Fill in the fileStat variable for the file named zFilename.
40
+** If zFilename==0, then use the previous value of fileStat if
41
+** there is a previous value.
42
+**
43
+** Return the number of errors. No error messages are generated.
44
+*/
45
+static int getStat(const char *zFilename){
46
+ if( zFilename==0 ){
47
+ if( fileStatValid==0 ) return 1;
48
+ }else{
49
+ if( stat(zFilename, &fileStat)!=0 ) return 1;
50
+ }
51
+ return 0;
52
+}
53
+
3254
3355
/*
3456
** Return the size of a file in bytes. Return -1 if the file does not
35
-** exist.
57
+** exist. If zFilename is NULL, return the size of the most recently
58
+** stat-ed file.
3659
*/
3760
i64 file_size(const char *zFilename){
38
- struct stat buf;
39
- if( stat(zFilename, &buf)!=0 ){
40
- return -1;
41
- }
42
- return buf.st_size;
61
+ return getStat(zFilename) ? -1 : fileStat.st_size;
4362
}
4463
4564
/*
4665
** Return the modification time for a file. Return -1 if the file
47
-** does not exist.
66
+** does not exist. If zFilename is NULL return the size of the most
67
+** recently stat-ed file.
4868
*/
4969
i64 file_mtime(const char *zFilename){
50
- struct stat buf;
51
- if( stat(zFilename, &buf)!=0 ){
52
- return -1;
70
+ return getStat(zFilename) ? -1 : fileStat.st_mtime;
71
+}
72
+
73
+/*
74
+** Return TRUE if the named file is an ordinary file. Return false
75
+** for directories, devices, fifos, symlinks, etc.
76
+*/
77
+int file_isfile(const char *zFilename){
78
+ return getStat(zFilename) ? 0 : S_ISREG(fileStat.st_mode);
79
+}
80
+
81
+/*
82
+** Return TRUE if the named file is an executable. Return false
83
+** for directories, devices, fifos, symlinks, etc.
84
+*/
85
+int file_isexe(const char *zFilename){
86
+ if( getStat(zFilename) || !S_ISREG(fileStat.st_mode) ) return 0;
87
+#ifdef __MINGW32__
88
+ return ((S_IXUSR)&fileStat.st_mode)!=0;
89
+#else
90
+ return ((S_IXUSR|S_IXGRP|S_IXOTH)&fileStat.st_mode)!=0;
91
+#endif
92
+}
93
+
94
+
95
+/*
96
+** Return 1 if zFilename is a directory. Return 0 if zFilename
97
+** does not exist. Return 2 if zFilename exists but is something
98
+** other than a directory.
99
+*/
100
+int file_isdir(const char *zFilename){
101
+ int rc;
102
+
103
+ if( zFilename ){
104
+ char *zFN = mprintf("%s", zFilename);
105
+ file_simplify_name(zFN, strlen(zFN));
106
+ rc = getStat(zFN);
107
+ free(zFN);
108
+ }else{
109
+ rc = getStat(0);
53110
}
54
- return buf.st_mtime;
111
+ return rc ? 0 : (S_ISDIR(fileStat.st_mode) ? 1 : 2);
55112
}
56113
57114
/*
58115
** Return the tail of a file pathname. The tail is the last component
59116
** of the path. For example, the tail of "/a/b/c.d" is "c.d".
@@ -83,39 +140,10 @@
83140
}
84141
fclose(in);
85142
fclose(out);
86143
}
87144
88
-/*
89
-** Return TRUE if the named file is an ordinary file. Return false
90
-** for directories, devices, fifos, symlinks, etc.
91
-*/
92
-int file_isfile(const char *zFilename){
93
- struct stat buf;
94
- if( stat(zFilename, &buf)!=0 ){
95
- return 0;
96
- }
97
- return S_ISREG(buf.st_mode);
98
-}
99
-
100
-/*
101
-** Return TRUE if the named file is an executable. Return false
102
-** for directories, devices, fifos, symlinks, etc.
103
-*/
104
-int file_isexe(const char *zFilename){
105
- struct stat buf;
106
- if( stat(zFilename, &buf)!=0 ){
107
- return 0;
108
- }
109
- if( !S_ISREG(buf.st_mode) ) return 0;
110
-#ifdef __MINGW32__
111
- return ((S_IXUSR)&buf.st_mode)!=0;
112
-#else
113
- return ((S_IXUSR|S_IXGRP|S_IXOTH)&buf.st_mode)!=0;
114
-#endif
115
-}
116
-
117145
/*
118146
** Set or clear the execute bit on a file.
119147
*/
120148
void file_setexe(const char *zFilename, int onoff){
121149
#ifndef __MINGW32__
@@ -131,27 +159,10 @@
131159
}
132160
}
133161
#endif
134162
}
135163
136
-/*
137
-** Return 1 if zFilename is a directory. Return 0 if zFilename
138
-** does not exist. Return 2 if zFilename exists but is something
139
-** other than a directory.
140
-*/
141
-int file_isdir(const char *zFilename){
142
- struct stat buf;
143
- int rc;
144
- char *zFN;
145
-
146
- zFN = mprintf("%s", zFilename);
147
- file_simplify_name(zFN, strlen(zFN));
148
- rc = stat(zFN, &buf);
149
- free(zFN);
150
- return rc!=0 ? 0 : (S_ISDIR(buf.st_mode) ? 1 : 2);
151
-}
152
-
153164
/*
154165
** Create the directory named in the argument, if it does not already
155166
** exist. If forceFlag is 1, delete any prior non-directory object
156167
** with the same name.
157168
**
158169
--- src/file.c
+++ src/file.c
@@ -27,33 +27,90 @@
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <unistd.h>
30 #include "file.h"
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
33 /*
34 ** Return the size of a file in bytes. Return -1 if the file does not
35 ** exist.
 
36 */
37 i64 file_size(const char *zFilename){
38 struct stat buf;
39 if( stat(zFilename, &buf)!=0 ){
40 return -1;
41 }
42 return buf.st_size;
43 }
44
45 /*
46 ** Return the modification time for a file. Return -1 if the file
47 ** does not exist.
 
48 */
49 i64 file_mtime(const char *zFilename){
50 struct stat buf;
51 if( stat(zFilename, &buf)!=0 ){
52 return -1;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53 }
54 return buf.st_mtime;
55 }
56
57 /*
58 ** Return the tail of a file pathname. The tail is the last component
59 ** of the path. For example, the tail of "/a/b/c.d" is "c.d".
@@ -83,39 +140,10 @@
83 }
84 fclose(in);
85 fclose(out);
86 }
87
88 /*
89 ** Return TRUE if the named file is an ordinary file. Return false
90 ** for directories, devices, fifos, symlinks, etc.
91 */
92 int file_isfile(const char *zFilename){
93 struct stat buf;
94 if( stat(zFilename, &buf)!=0 ){
95 return 0;
96 }
97 return S_ISREG(buf.st_mode);
98 }
99
100 /*
101 ** Return TRUE if the named file is an executable. Return false
102 ** for directories, devices, fifos, symlinks, etc.
103 */
104 int file_isexe(const char *zFilename){
105 struct stat buf;
106 if( stat(zFilename, &buf)!=0 ){
107 return 0;
108 }
109 if( !S_ISREG(buf.st_mode) ) return 0;
110 #ifdef __MINGW32__
111 return ((S_IXUSR)&buf.st_mode)!=0;
112 #else
113 return ((S_IXUSR|S_IXGRP|S_IXOTH)&buf.st_mode)!=0;
114 #endif
115 }
116
117 /*
118 ** Set or clear the execute bit on a file.
119 */
120 void file_setexe(const char *zFilename, int onoff){
121 #ifndef __MINGW32__
@@ -131,27 +159,10 @@
131 }
132 }
133 #endif
134 }
135
136 /*
137 ** Return 1 if zFilename is a directory. Return 0 if zFilename
138 ** does not exist. Return 2 if zFilename exists but is something
139 ** other than a directory.
140 */
141 int file_isdir(const char *zFilename){
142 struct stat buf;
143 int rc;
144 char *zFN;
145
146 zFN = mprintf("%s", zFilename);
147 file_simplify_name(zFN, strlen(zFN));
148 rc = stat(zFN, &buf);
149 free(zFN);
150 return rc!=0 ? 0 : (S_ISDIR(buf.st_mode) ? 1 : 2);
151 }
152
153 /*
154 ** Create the directory named in the argument, if it does not already
155 ** exist. If forceFlag is 1, delete any prior non-directory object
156 ** with the same name.
157 **
158
--- src/file.c
+++ src/file.c
@@ -27,33 +27,90 @@
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <unistd.h>
30 #include "file.h"
31
32 /*
33 ** The file status information from the most recent stat() call.
34 */
35 static struct stat fileStat;
36 static int fileStatValid = 0;
37
38 /*
39 ** Fill in the fileStat variable for the file named zFilename.
40 ** If zFilename==0, then use the previous value of fileStat if
41 ** there is a previous value.
42 **
43 ** Return the number of errors. No error messages are generated.
44 */
45 static int getStat(const char *zFilename){
46 if( zFilename==0 ){
47 if( fileStatValid==0 ) return 1;
48 }else{
49 if( stat(zFilename, &fileStat)!=0 ) return 1;
50 }
51 return 0;
52 }
53
54
55 /*
56 ** Return the size of a file in bytes. Return -1 if the file does not
57 ** exist. If zFilename is NULL, return the size of the most recently
58 ** stat-ed file.
59 */
60 i64 file_size(const char *zFilename){
61 return getStat(zFilename) ? -1 : fileStat.st_size;
 
 
 
 
62 }
63
64 /*
65 ** Return the modification time for a file. Return -1 if the file
66 ** does not exist. If zFilename is NULL return the size of the most
67 ** recently stat-ed file.
68 */
69 i64 file_mtime(const char *zFilename){
70 return getStat(zFilename) ? -1 : fileStat.st_mtime;
71 }
72
73 /*
74 ** Return TRUE if the named file is an ordinary file. Return false
75 ** for directories, devices, fifos, symlinks, etc.
76 */
77 int file_isfile(const char *zFilename){
78 return getStat(zFilename) ? 0 : S_ISREG(fileStat.st_mode);
79 }
80
81 /*
82 ** Return TRUE if the named file is an executable. Return false
83 ** for directories, devices, fifos, symlinks, etc.
84 */
85 int file_isexe(const char *zFilename){
86 if( getStat(zFilename) || !S_ISREG(fileStat.st_mode) ) return 0;
87 #ifdef __MINGW32__
88 return ((S_IXUSR)&fileStat.st_mode)!=0;
89 #else
90 return ((S_IXUSR|S_IXGRP|S_IXOTH)&fileStat.st_mode)!=0;
91 #endif
92 }
93
94
95 /*
96 ** Return 1 if zFilename is a directory. Return 0 if zFilename
97 ** does not exist. Return 2 if zFilename exists but is something
98 ** other than a directory.
99 */
100 int file_isdir(const char *zFilename){
101 int rc;
102
103 if( zFilename ){
104 char *zFN = mprintf("%s", zFilename);
105 file_simplify_name(zFN, strlen(zFN));
106 rc = getStat(zFN);
107 free(zFN);
108 }else{
109 rc = getStat(0);
110 }
111 return rc ? 0 : (S_ISDIR(fileStat.st_mode) ? 1 : 2);
112 }
113
114 /*
115 ** Return the tail of a file pathname. The tail is the last component
116 ** of the path. For example, the tail of "/a/b/c.d" is "c.d".
@@ -83,39 +140,10 @@
140 }
141 fclose(in);
142 fclose(out);
143 }
144
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145 /*
146 ** Set or clear the execute bit on a file.
147 */
148 void file_setexe(const char *zFilename, int onoff){
149 #ifndef __MINGW32__
@@ -131,27 +159,10 @@
159 }
160 }
161 #endif
162 }
163
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164 /*
165 ** Create the directory named in the argument, if it does not already
166 ** exist. If forceFlag is 1, delete any prior non-directory object
167 ** with the same name.
168 **
169
+3 -3
--- src/vfile.c
+++ src/vfile.c
@@ -146,11 +146,11 @@
146146
*/
147147
void vfile_check_signature(int vid, int notFileIsFatal){
148148
int nErr = 0;
149149
Stmt q;
150150
Blob fileCksum, origCksum;
151
- int checkMtime = db_get_boolean("mtime-changes", 0);
151
+ int checkMtime = db_get_boolean("mtime-changes", 1);
152152
153153
db_begin_transaction();
154154
db_prepare(&q, "SELECT id, %Q || pathname,"
155155
" vfile.mrid, deleted, chnged, uuid, mtime"
156156
" FROM vfile LEFT JOIN blob ON vfile.mrid=blob.rid"
@@ -167,11 +167,11 @@
167167
zName = db_column_text(&q, 1);
168168
rid = db_column_int(&q, 2);
169169
isDeleted = db_column_int(&q, 3);
170170
oldChnged = db_column_int(&q, 4);
171171
oldMtime = db_column_int64(&q, 6);
172
- if( !file_isfile(zName) && file_size(zName)>=0 ){
172
+ if( !file_isfile(zName) && file_size(0)>=0 ){
173173
if( notFileIsFatal ){
174174
fossil_warning("not a ordinary file: %s", zName);
175175
nErr++;
176176
}
177177
chnged = 1;
@@ -179,11 +179,11 @@
179179
chnged = oldChnged;
180180
}else if( isDeleted || rid==0 ){
181181
chnged = 1;
182182
}
183183
if( chnged!=1 ){
184
- currentMtime = file_mtime(zName);
184
+ currentMtime = file_mtime(0);
185185
}
186186
if( chnged!=1 && (checkMtime==0 || currentMtime!=oldMtime) ){
187187
db_ephemeral_blob(&q, 5, &origCksum);
188188
if( sha1sum_file(zName, &fileCksum) ){
189189
blob_zero(&fileCksum);
190190
--- src/vfile.c
+++ src/vfile.c
@@ -146,11 +146,11 @@
146 */
147 void vfile_check_signature(int vid, int notFileIsFatal){
148 int nErr = 0;
149 Stmt q;
150 Blob fileCksum, origCksum;
151 int checkMtime = db_get_boolean("mtime-changes", 0);
152
153 db_begin_transaction();
154 db_prepare(&q, "SELECT id, %Q || pathname,"
155 " vfile.mrid, deleted, chnged, uuid, mtime"
156 " FROM vfile LEFT JOIN blob ON vfile.mrid=blob.rid"
@@ -167,11 +167,11 @@
167 zName = db_column_text(&q, 1);
168 rid = db_column_int(&q, 2);
169 isDeleted = db_column_int(&q, 3);
170 oldChnged = db_column_int(&q, 4);
171 oldMtime = db_column_int64(&q, 6);
172 if( !file_isfile(zName) && file_size(zName)>=0 ){
173 if( notFileIsFatal ){
174 fossil_warning("not a ordinary file: %s", zName);
175 nErr++;
176 }
177 chnged = 1;
@@ -179,11 +179,11 @@
179 chnged = oldChnged;
180 }else if( isDeleted || rid==0 ){
181 chnged = 1;
182 }
183 if( chnged!=1 ){
184 currentMtime = file_mtime(zName);
185 }
186 if( chnged!=1 && (checkMtime==0 || currentMtime!=oldMtime) ){
187 db_ephemeral_blob(&q, 5, &origCksum);
188 if( sha1sum_file(zName, &fileCksum) ){
189 blob_zero(&fileCksum);
190
--- src/vfile.c
+++ src/vfile.c
@@ -146,11 +146,11 @@
146 */
147 void vfile_check_signature(int vid, int notFileIsFatal){
148 int nErr = 0;
149 Stmt q;
150 Blob fileCksum, origCksum;
151 int checkMtime = db_get_boolean("mtime-changes", 1);
152
153 db_begin_transaction();
154 db_prepare(&q, "SELECT id, %Q || pathname,"
155 " vfile.mrid, deleted, chnged, uuid, mtime"
156 " FROM vfile LEFT JOIN blob ON vfile.mrid=blob.rid"
@@ -167,11 +167,11 @@
167 zName = db_column_text(&q, 1);
168 rid = db_column_int(&q, 2);
169 isDeleted = db_column_int(&q, 3);
170 oldChnged = db_column_int(&q, 4);
171 oldMtime = db_column_int64(&q, 6);
172 if( !file_isfile(zName) && file_size(0)>=0 ){
173 if( notFileIsFatal ){
174 fossil_warning("not a ordinary file: %s", zName);
175 nErr++;
176 }
177 chnged = 1;
@@ -179,11 +179,11 @@
179 chnged = oldChnged;
180 }else if( isDeleted || rid==0 ){
181 chnged = 1;
182 }
183 if( chnged!=1 ){
184 currentMtime = file_mtime(0);
185 }
186 if( chnged!=1 && (checkMtime==0 || currentMtime!=oldMtime) ){
187 db_ephemeral_blob(&q, 5, &origCksum);
188 if( sha1sum_file(zName, &fileCksum) ){
189 blob_zero(&fileCksum);
190

Keyboard Shortcuts

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