Fossil SCM

In the file_isdir() routine, make sure the filename is simplified (has no "/../" or "/./" components and does not end with "/") in order to work around bugs in mingw.

drh 2009-11-14 14:38 trunk
Commit a7822bcc001e9fce21a6f97803a02ae221f0cea8
1 file changed +10 -6
+10 -6
--- src/file.c
+++ src/file.c
@@ -138,14 +138,18 @@
138138
** does not exist. Return 2 if zFilename exists but is something
139139
** other than a directory.
140140
*/
141141
int file_isdir(const char *zFilename){
142142
struct stat buf;
143
- if( stat(zFilename, &buf)!=0 ){
144
- return 0;
145
- }
146
- return S_ISDIR(buf.st_mode) ? 1 : 2;
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);
147151
}
148152
149153
/*
150154
** Create the directory named in the argument, if it does not already
151155
** exist. If forceFlag is 1, delete any prior non-directory object
@@ -222,15 +226,15 @@
222226
#endif
223227
while( n>1 && z[n-1]=='/' ){ n--; }
224228
for(i=j=0; i<n; i++){
225229
if( z[i]=='/' ){
226230
if( z[i+1]=='/' ) continue;
227
- if( z[i+1]=='.' && i+2<n && z[i+2]=='/' ){
231
+ if( z[i+1]=='.' && (i+2==n || z[i+2]=='/') ){
228232
i += 1;
229233
continue;
230234
}
231
- if( z[i+1]=='.' && i+3<n && z[i+2]=='.' && z[i+3]=='/' ){
235
+ if( z[i+1]=='.' && i+2<n && z[i+2]=='.' && (i+3==n || z[i+3]=='/') ){
232236
while( j>0 && z[j-1]!='/' ){ j--; }
233237
if( j>0 ){ j--; }
234238
i += 2;
235239
continue;
236240
}
237241
--- src/file.c
+++ src/file.c
@@ -138,14 +138,18 @@
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 if( stat(zFilename, &buf)!=0 ){
144 return 0;
145 }
146 return S_ISDIR(buf.st_mode) ? 1 : 2;
 
 
 
 
147 }
148
149 /*
150 ** Create the directory named in the argument, if it does not already
151 ** exist. If forceFlag is 1, delete any prior non-directory object
@@ -222,15 +226,15 @@
222 #endif
223 while( n>1 && z[n-1]=='/' ){ n--; }
224 for(i=j=0; i<n; i++){
225 if( z[i]=='/' ){
226 if( z[i+1]=='/' ) continue;
227 if( z[i+1]=='.' && i+2<n && z[i+2]=='/' ){
228 i += 1;
229 continue;
230 }
231 if( z[i+1]=='.' && i+3<n && z[i+2]=='.' && z[i+3]=='/' ){
232 while( j>0 && z[j-1]!='/' ){ j--; }
233 if( j>0 ){ j--; }
234 i += 2;
235 continue;
236 }
237
--- src/file.c
+++ src/file.c
@@ -138,14 +138,18 @@
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
@@ -222,15 +226,15 @@
226 #endif
227 while( n>1 && z[n-1]=='/' ){ n--; }
228 for(i=j=0; i<n; i++){
229 if( z[i]=='/' ){
230 if( z[i+1]=='/' ) continue;
231 if( z[i+1]=='.' && (i+2==n || z[i+2]=='/') ){
232 i += 1;
233 continue;
234 }
235 if( z[i+1]=='.' && i+2<n && z[i+2]=='.' && (i+3==n || z[i+3]=='/') ){
236 while( j>0 && z[j-1]!='/' ){ j--; }
237 if( j>0 ){ j--; }
238 i += 2;
239 continue;
240 }
241

Keyboard Shortcuts

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