20
20
#include "datapagemap.h"
21
21
22
22
/* directory exclusion list for backup mode listing */
23
- const char * pgdata_exclude []=
23
+ const char * pgdata_exclude_dir []=
24
24
{
25
25
"pg_xlog" ,
26
26
"pg_stat_tmp" ,
27
27
"pgsql_tmp" ,
28
+ NULL ,/* arclog_path will be set later */
29
+ NULL ,/* pg_log will be set later */
30
+ NULL
31
+ };
32
+
33
+ static char * pgdata_exclude_files []=
34
+ {
28
35
"recovery.conf" ,
29
36
"postmaster.pid" ,
30
37
"postmaster.opts" ,
31
- NULL ,/* arclog_path will be set later */
32
- NULL ,/* pg_log will be set later */
33
38
NULL
34
39
};
35
40
@@ -249,7 +254,8 @@ BlackListCompare(const void *str1, const void *str2)
249
254
* directory llnked to will be listed.
250
255
*/
251
256
void
252
- dir_list_file (parray * files ,const char * root ,const char * exclude [],bool omit_symlink ,bool add_root )
257
+ dir_list_file (parray * files ,const char * root ,bool exclude ,bool omit_symlink ,
258
+ bool add_root )
253
259
{
254
260
char path [MAXPGPATH ];
255
261
char buf [MAXPGPATH * 2 ];
@@ -288,8 +294,8 @@ dir_list_file(parray *files, const char *root, const char *exclude[], bool omit_
288
294
}
289
295
290
296
void
291
- dir_list_file_internal (parray * files ,const char * root ,const char * exclude [] ,
292
- bool omit_symlink ,bool add_root ,parray * black_list )
297
+ dir_list_file_internal (parray * files ,const char * root ,bool exclude ,
298
+ bool omit_symlink ,bool add_root ,parray * black_list )
293
299
{
294
300
pgFile * file ;
295
301
@@ -305,7 +311,33 @@ dir_list_file_internal(parray *files, const char *root, const char *exclude[],
305
311
}
306
312
307
313
if (add_root )
314
+ {
315
+ /* Skip files */
316
+ if (!S_ISDIR (file -> mode )&& exclude )
317
+ {
318
+ char * file_name ;
319
+ int i ;
320
+
321
+ /* Extract file name */
322
+ file_name = strrchr (file -> path ,'/' );
323
+ if (file_name == NULL )
324
+ file_name = file -> path ;
325
+ else
326
+ file_name ++ ;
327
+
328
+ /*
329
+ * If the item in the exclude list starts with '/', compare to the
330
+ * absolute path of the directory. Otherwise compare to the directory
331
+ * name portion.
332
+ */
333
+ for (i = 0 ;pgdata_exclude_files [i ];i ++ )
334
+ if (strcmp (file_name ,pgdata_exclude_files [i ])== 0 )
335
+ /* Skip */
336
+ return ;
337
+ }
338
+
308
339
parray_append (files ,file );
340
+ }
309
341
310
342
/* chase symbolic link chain and find regular file or directory */
311
343
while (S_ISLNK (file -> mode ))
@@ -351,45 +383,49 @@ dir_list_file_internal(parray *files, const char *root, const char *exclude[],
351
383
*/
352
384
while (S_ISDIR (file -> mode ))
353
385
{
354
- int i ;
355
386
bool skip = false;
356
387
DIR * dir ;
357
388
struct dirent * dent ;
358
- char * dirname ;
359
389
360
- /* skip entry which matches exclude list */
361
- dirname = strrchr (file -> path ,'/' );
362
- if (dirname == NULL )
363
- dirname = file -> path ;
364
- else
365
- dirname ++ ;
366
-
367
- /*
368
- * If the item in the exclude list starts with '/', compare to the
369
- * absolute path of the directory. Otherwise compare to the directory
370
- * name portion.
371
- */
372
- for (i = 0 ;exclude && exclude [i ];i ++ )
390
+ if (exclude )
373
391
{
374
- if (exclude [i ][0 ]== '/' )
392
+ int i ;
393
+ char * dirname ;
394
+
395
+ /* skip entry which matches exclude list */
396
+ dirname = strrchr (file -> path ,'/' );
397
+ if (dirname == NULL )
398
+ dirname = file -> path ;
399
+ else
400
+ dirname ++ ;
401
+
402
+ /*
403
+ * If the item in the exclude list starts with '/', compare to the
404
+ * absolute path of the directory. Otherwise compare to the directory
405
+ * name portion.
406
+ */
407
+ for (i = 0 ;exclude && pgdata_exclude_dir [i ];i ++ )
375
408
{
376
- if (strcmp ( file -> path , exclude [i ]) == 0 )
409
+ if (pgdata_exclude_dir [i ][ 0 ] == '/' )
377
410
{
378
- skip = true;
379
- break ;
411
+ if (strcmp (file -> path ,pgdata_exclude_dir [i ])== 0 )
412
+ {
413
+ skip = true;
414
+ break ;
415
+ }
380
416
}
381
- }
382
- else
383
- {
384
- if (strcmp (dirname ,exclude [i ])== 0 )
417
+ else
385
418
{
386
- skip = true;
387
- break ;
419
+ if (strcmp (dirname ,pgdata_exclude_dir [i ])== 0 )
420
+ {
421
+ skip = true;
422
+ break ;
423
+ }
388
424
}
389
425
}
426
+ if (skip )
427
+ break ;
390
428
}
391
- if (skip )
392
- break ;
393
429
394
430
/* open directory and list contents */
395
431
dir = opendir (file -> path );
@@ -636,7 +672,7 @@ dir_copy_files(const char *from_root, const char *to_root)
636
672
parray * files = parray_new ();
637
673
638
674
/* don't copy root directory */
639
- dir_list_file (files ,from_root ,NULL , true, false);
675
+ dir_list_file (files ,from_root ,false , true, false);
640
676
641
677
for (i = 0 ;i < parray_num (files );i ++ )
642
678
{