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.
Commit
a7822bcc001e9fce21a6f97803a02ae221f0cea8
Parent
d5695157d0caade…
1 file changed
+10
-6
+10
-6
| --- src/file.c | ||
| +++ src/file.c | ||
| @@ -138,14 +138,18 @@ | ||
| 138 | 138 | ** does not exist. Return 2 if zFilename exists but is something |
| 139 | 139 | ** other than a directory. |
| 140 | 140 | */ |
| 141 | 141 | int file_isdir(const char *zFilename){ |
| 142 | 142 | 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); | |
| 147 | 151 | } |
| 148 | 152 | |
| 149 | 153 | /* |
| 150 | 154 | ** Create the directory named in the argument, if it does not already |
| 151 | 155 | ** exist. If forceFlag is 1, delete any prior non-directory object |
| @@ -222,15 +226,15 @@ | ||
| 222 | 226 | #endif |
| 223 | 227 | while( n>1 && z[n-1]=='/' ){ n--; } |
| 224 | 228 | for(i=j=0; i<n; i++){ |
| 225 | 229 | if( z[i]=='/' ){ |
| 226 | 230 | 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]=='/') ){ | |
| 228 | 232 | i += 1; |
| 229 | 233 | continue; |
| 230 | 234 | } |
| 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]=='/') ){ | |
| 232 | 236 | while( j>0 && z[j-1]!='/' ){ j--; } |
| 233 | 237 | if( j>0 ){ j--; } |
| 234 | 238 | i += 2; |
| 235 | 239 | continue; |
| 236 | 240 | } |
| 237 | 241 |
| --- 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 |