Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9a90ec9

Browse files
committed
Improve pg_check_dir code and comments.
Avoid losing errno if readdir() fails and closedir() works. Consistentlyreturn 4 rather than 3 if both a lost+found directory and other files arefound, rather than returning one value or the other depending on theorder of the directory listing. Update comments to match the actualbehavior.These oversights date to commits6f03927and17f1523.Marco Nenciarini
1 parent7bc6e59 commit9a90ec9

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

‎src/port/pgcheckdir.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
* Returns:
2323
*0 if nonexistent
2424
*1 if exists and empty
25-
*2 if exists and not empty
25+
*2 if exists and contains _only_ dot files
26+
*3 if exists and contains a mount point
27+
*4 if exists and not empty
2628
*-1 if trouble accessing directory (errno reflects the error)
2729
*/
2830
int
@@ -32,6 +34,8 @@ pg_check_dir(const char *dir)
3234
DIR*chkdir;
3335
structdirent*file;
3436
booldot_found= false;
37+
boolmount_found= false;
38+
intreaddir_errno;
3539

3640
chkdir=opendir(dir);
3741
if (chkdir==NULL)
@@ -51,10 +55,10 @@ pg_check_dir(const char *dir)
5155
{
5256
dot_found= true;
5357
}
58+
/* lost+found directory */
5459
elseif (strcmp("lost+found",file->d_name)==0)
5560
{
56-
result=3;/* not empty, mount point */
57-
break;
61+
mount_found= true;
5862
}
5963
#endif
6064
else
@@ -70,9 +74,20 @@ pg_check_dir(const char *dir)
7074
errno=0;
7175
#endif
7276

73-
if (errno||closedir(chkdir))
77+
if (errno)
7478
result=-1;/* some kind of I/O error? */
7579

80+
/* Close chkdir and avoid overwriting the readdir errno on success */
81+
readdir_errno=errno;
82+
if (closedir(chkdir))
83+
result=-1;/* error executing closedir */
84+
else
85+
errno=readdir_errno;
86+
87+
/* We report on mount point if we find a lost+found directory */
88+
if (result==1&&mount_found)
89+
result=3;
90+
7691
/* We report on dot-files if we _only_ find dot files */
7792
if (result==1&&dot_found)
7893
result=2;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp