Fossil SCM
file_directory_size() now unconditionally skips the magic "." and ".." entries. This does not affect current uses of the routine but a proposed patch provided in [forum:383838fbd0b6c881|forum post 383838fbd0b6c881] would be awkwardly affected by them.
Commit
3cb7d39e1247fbbbb08857ced403cc5609993c171c2fbe9696ae26ddc23d02fe
Parent
40086b74bac8976…
1 file changed
+10
-1
+10
-1
| --- src/file.c | ||
| +++ src/file.c | ||
| @@ -2409,10 +2409,13 @@ | ||
| 2409 | 2409 | |
| 2410 | 2410 | /* |
| 2411 | 2411 | ** Count the number of objects (files and subdirectories) in a given |
| 2412 | 2412 | ** directory. Return the count. Return -1 if the object is not a |
| 2413 | 2413 | ** directory. |
| 2414 | +** | |
| 2415 | +** This routine never counts the two "." and ".." special directory | |
| 2416 | +** entries, even if the provided glob would match them. | |
| 2414 | 2417 | */ |
| 2415 | 2418 | int file_directory_size(const char *zDir, const char *zGlob, int omitDotFiles){ |
| 2416 | 2419 | void *zNative; |
| 2417 | 2420 | DIR *d; |
| 2418 | 2421 | int n = -1; |
| @@ -2421,11 +2424,17 @@ | ||
| 2421 | 2424 | if( d ){ |
| 2422 | 2425 | struct dirent *pEntry; |
| 2423 | 2426 | n = 0; |
| 2424 | 2427 | while( (pEntry=readdir(d))!=0 ){ |
| 2425 | 2428 | if( pEntry->d_name[0]==0 ) continue; |
| 2426 | - if( omitDotFiles && pEntry->d_name[0]=='.' ) continue; | |
| 2429 | + if( pEntry->d_name[0]=='.' && | |
| 2430 | + (omitDotFiles | |
| 2431 | + /* Skip the special "." and ".." entries. */ | |
| 2432 | + || pEntry->d_name[1]==0 | |
| 2433 | + || (pEntry->d_name[1]=='.' && pEntry->d_name[2]==0))){ | |
| 2434 | + continue; | |
| 2435 | + } | |
| 2427 | 2436 | if( zGlob ){ |
| 2428 | 2437 | char *zUtf8 = fossil_path_to_utf8(pEntry->d_name); |
| 2429 | 2438 | int rc = sqlite3_strglob(zGlob, zUtf8); |
| 2430 | 2439 | fossil_path_free(zUtf8); |
| 2431 | 2440 | if( rc ) continue; |
| 2432 | 2441 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -2409,10 +2409,13 @@ | |
| 2409 | |
| 2410 | /* |
| 2411 | ** Count the number of objects (files and subdirectories) in a given |
| 2412 | ** directory. Return the count. Return -1 if the object is not a |
| 2413 | ** directory. |
| 2414 | */ |
| 2415 | int file_directory_size(const char *zDir, const char *zGlob, int omitDotFiles){ |
| 2416 | void *zNative; |
| 2417 | DIR *d; |
| 2418 | int n = -1; |
| @@ -2421,11 +2424,17 @@ | |
| 2421 | if( d ){ |
| 2422 | struct dirent *pEntry; |
| 2423 | n = 0; |
| 2424 | while( (pEntry=readdir(d))!=0 ){ |
| 2425 | if( pEntry->d_name[0]==0 ) continue; |
| 2426 | if( omitDotFiles && pEntry->d_name[0]=='.' ) continue; |
| 2427 | if( zGlob ){ |
| 2428 | char *zUtf8 = fossil_path_to_utf8(pEntry->d_name); |
| 2429 | int rc = sqlite3_strglob(zGlob, zUtf8); |
| 2430 | fossil_path_free(zUtf8); |
| 2431 | if( rc ) continue; |
| 2432 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -2409,10 +2409,13 @@ | |
| 2409 | |
| 2410 | /* |
| 2411 | ** Count the number of objects (files and subdirectories) in a given |
| 2412 | ** directory. Return the count. Return -1 if the object is not a |
| 2413 | ** directory. |
| 2414 | ** |
| 2415 | ** This routine never counts the two "." and ".." special directory |
| 2416 | ** entries, even if the provided glob would match them. |
| 2417 | */ |
| 2418 | int file_directory_size(const char *zDir, const char *zGlob, int omitDotFiles){ |
| 2419 | void *zNative; |
| 2420 | DIR *d; |
| 2421 | int n = -1; |
| @@ -2421,11 +2424,17 @@ | |
| 2424 | if( d ){ |
| 2425 | struct dirent *pEntry; |
| 2426 | n = 0; |
| 2427 | while( (pEntry=readdir(d))!=0 ){ |
| 2428 | if( pEntry->d_name[0]==0 ) continue; |
| 2429 | if( pEntry->d_name[0]=='.' && |
| 2430 | (omitDotFiles |
| 2431 | /* Skip the special "." and ".." entries. */ |
| 2432 | || pEntry->d_name[1]==0 |
| 2433 | || (pEntry->d_name[1]=='.' && pEntry->d_name[2]==0))){ |
| 2434 | continue; |
| 2435 | } |
| 2436 | if( zGlob ){ |
| 2437 | char *zUtf8 = fossil_path_to_utf8(pEntry->d_name); |
| 2438 | int rc = sqlite3_strglob(zGlob, zUtf8); |
| 2439 | fossil_path_free(zUtf8); |
| 2440 | if( rc ) continue; |
| 2441 |