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

Commitb84334b

Browse files
author
Michael Paquier
committed
Remove unportable code of IsDir
IsDir was somewhat optimized on systems where DT_DIR (dirent.d_typebeing not part of the POSIX spec) is present on some systems leadingto more complex logic depending on the file system used, particularlyon XFS this routine was actually broken. Having a call to stat()should not be that expensive to check if a path is a directory ornot and this is proving to be far more stable coding, so just relyon that, that's more portable anyway and will avoid future surprises.Report by Yury Zhuravlev, though I did not use his patch.
1 parent7254d30 commitb84334b

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

‎catalog.c

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,24 +90,14 @@ catalog_get_backup(time_t timestamp)
9090
}
9191

9292
staticbool
93-
IsDir(constchar*dirpath,constDIR*dir,conststructdirent*ent)
93+
IsDir(constchar*dirpath,constchar*entry)
9494
{
95-
#if defined(DT_DIR)
96-
returnent->d_type==DT_DIR;
97-
#elif defined(_finddata_t)
98-
/* Optimization for VC++ on Windows. */
99-
return (dir->dd_dta.attrib&FILE_ATTRIBUTE_DIRECTORY)!=0;
100-
#else
101-
/* Portable implementation because dirent.d_type is not in POSIX. */
10295
charpath[MAXPGPATH];
10396
structstatst;
10497

105-
strlcpy(path,dirpath,MAXPGPATH);
106-
strlcat(path,"/",MAXPGPATH);
107-
strlcat(path,ent->d_name,MAXPGPATH);
98+
snprintf(path,MAXPGPATH,"%s/%s",dirpath,entry);
10899

109100
returnstat(path,&st)==0&&S_ISDIR(st.st_mode);
110-
#endif
111101
}
112102

113103
/*
@@ -157,7 +147,7 @@ catalog_get_backup_list(const pgBackupRange *range)
157147
for (; (date_ent=readdir(date_dir))!=NULL;errno=0)
158148
{
159149
/* skip not-directory entries and hidden entries */
160-
if (!IsDir(backup_path,date_dir,date_ent)||date_ent->d_name[0]=='.')
150+
if (!IsDir(backup_path,date_ent->d_name)||date_ent->d_name[0]=='.')
161151
continue;
162152

163153
/* skip online WAL backup directory */
@@ -183,20 +173,21 @@ catalog_get_backup_list(const pgBackupRange *range)
183173
{
184174
charini_path[MAXPGPATH];
185175

186-
/* skipnot-directory and hidden directories */
187-
if (!IsDir(date_path,date_dir,time_ent)||time_ent->d_name[0]=='.')
176+
/* skipentries that are directories and hidden directories */
177+
if (!IsDir(date_path,time_ent->d_name)||time_ent->d_name[0]=='.')
188178
continue;
189179

190180
/* If the time is out of range, skip it. */
191181
if (pgBackupRangeIsValid(range)&&
192-
(strcmp(begin_time,time_ent->d_name)>0||
193-
strcmp(end_time,time_ent->d_name)<0))
182+
(strcmp(begin_time,time_ent->d_name)>0||
183+
strcmp(end_time,time_ent->d_name)<0))
194184
continue;
195185

196186
/* read backup information from backup.ini */
197187
snprintf(ini_path,MAXPGPATH,"%s/%s/%s",date_path,
198-
time_ent->d_name,BACKUP_INI_FILE);
188+
time_ent->d_name,BACKUP_INI_FILE);
199189
backup=catalog_read_ini(ini_path);
190+
200191
/* ignore corrupted backup */
201192
if (backup)
202193
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp