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.

stephan 2024-05-04 11:26 trunk
Commit 3cb7d39e1247fbbbb08857ced403cc5609993c171c2fbe9696ae26ddc23d02fe
1 file changed +10 -1
+10 -1
--- src/file.c
+++ src/file.c
@@ -2409,10 +2409,13 @@
24092409
24102410
/*
24112411
** Count the number of objects (files and subdirectories) in a given
24122412
** directory. Return the count. Return -1 if the object is not a
24132413
** directory.
2414
+**
2415
+** This routine never counts the two "." and ".." special directory
2416
+** entries, even if the provided glob would match them.
24142417
*/
24152418
int file_directory_size(const char *zDir, const char *zGlob, int omitDotFiles){
24162419
void *zNative;
24172420
DIR *d;
24182421
int n = -1;
@@ -2421,11 +2424,17 @@
24212424
if( d ){
24222425
struct dirent *pEntry;
24232426
n = 0;
24242427
while( (pEntry=readdir(d))!=0 ){
24252428
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
+ }
24272436
if( zGlob ){
24282437
char *zUtf8 = fossil_path_to_utf8(pEntry->d_name);
24292438
int rc = sqlite3_strglob(zGlob, zUtf8);
24302439
fossil_path_free(zUtf8);
24312440
if( rc ) continue;
24322441
--- 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

Keyboard Shortcuts

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