@@ -40,7 +40,7 @@ static void send_int8_string(StringInfoData *buf, int64 intval);
40
40
static void SendBackupHeader (List * tablespaces );
41
41
static void SendBackupDirectory (char * location , char * spcoid );
42
42
static void base_backup_cleanup (int code , Datum arg );
43
- static void perform_base_backup (const char * backup_label , List * tablespaces );
43
+ static void perform_base_backup (const char * backup_label , bool progress , DIR * tblspcdir );
44
44
45
45
typedef struct
46
46
{
@@ -67,13 +67,50 @@ base_backup_cleanup(int code, Datum arg)
67
67
* clobbered by longjmp" from stupider versions of gcc.
68
68
*/
69
69
static void
70
- perform_base_backup (const char * backup_label , List * tablespaces )
70
+ perform_base_backup (const char * backup_label , bool progress , DIR * tblspcdir )
71
71
{
72
72
do_pg_start_backup (backup_label , true);
73
73
74
74
PG_ENSURE_ERROR_CLEANUP (base_backup_cleanup , (Datum ) 0 );
75
75
{
76
+ List * tablespaces = NIL ;
76
77
ListCell * lc ;
78
+ struct dirent * de ;
79
+ tablespaceinfo * ti ;
80
+
81
+
82
+ /* Add a node for the base directory */
83
+ ti = palloc0 (sizeof (tablespaceinfo ));
84
+ ti -> size = progress ? sendDir ("." , 1 , true) : -1 ;
85
+ tablespaces = lappend (tablespaces , ti );
86
+
87
+ /* Collect information about all tablespaces */
88
+ while ((de = ReadDir (tblspcdir , "pg_tblspc" )) != NULL )
89
+ {
90
+ char fullpath [MAXPGPATH ];
91
+ char linkpath [MAXPGPATH ];
92
+
93
+ /* Skip special stuff */
94
+ if (strcmp (de -> d_name , "." ) == 0 || strcmp (de -> d_name , ".." ) == 0 )
95
+ continue ;
96
+
97
+ snprintf (fullpath , sizeof (fullpath ), "pg_tblspc/%s" , de -> d_name );
98
+
99
+ MemSet (linkpath , 0 , sizeof (linkpath ));
100
+ if (readlink (fullpath , linkpath , sizeof (linkpath ) - 1 ) == -1 )
101
+ {
102
+ ereport (WARNING ,
103
+ (errmsg ("unable to read symbolic link %s: %m" , fullpath )));
104
+ continue ;
105
+ }
106
+
107
+ ti = palloc (sizeof (tablespaceinfo ));
108
+ ti -> oid = pstrdup (de -> d_name );
109
+ ti -> path = pstrdup (linkpath );
110
+ ti -> size = progress ? sendDir (linkpath , strlen (linkpath ), true) : -1 ;
111
+ tablespaces = lappend (tablespaces , ti );
112
+ }
113
+
77
114
78
115
/* Send tablespace header */
79
116
SendBackupHeader (tablespaces );
101
138
SendBaseBackup (const char * backup_label , bool progress )
102
139
{
103
140
DIR * dir ;
104
- struct dirent * de ;
105
- List * tablespaces = NIL ;
106
- tablespaceinfo * ti ;
107
141
MemoryContext backup_context ;
108
142
MemoryContext old_context ;
109
143
@@ -134,41 +168,10 @@ SendBaseBackup(const char *backup_label, bool progress)
134
168
ereport (ERROR ,
135
169
(errmsg ("unable to open directory pg_tblspc: %m" )));
136
170
137
- /* Add a node for the base directory */
138
- ti = palloc0 (sizeof (tablespaceinfo ));
139
- ti -> size = progress ? sendDir ("." , 1 , true) : -1 ;
140
- tablespaces = lappend (tablespaces , ti );
141
-
142
- /* Collect information about all tablespaces */
143
- while ((de = ReadDir (dir , "pg_tblspc" )) != NULL )
144
- {
145
- char fullpath [MAXPGPATH ];
146
- char linkpath [MAXPGPATH ];
147
-
148
- /* Skip special stuff */
149
- if (strcmp (de -> d_name , "." ) == 0 || strcmp (de -> d_name , ".." ) == 0 )
150
- continue ;
151
-
152
- snprintf (fullpath , sizeof (fullpath ), "pg_tblspc/%s" , de -> d_name );
153
-
154
- MemSet (linkpath , 0 , sizeof (linkpath ));
155
- if (readlink (fullpath , linkpath , sizeof (linkpath ) - 1 ) == -1 )
156
- {
157
- ereport (WARNING ,
158
- (errmsg ("unable to read symbolic link %s: %m" , fullpath )));
159
- continue ;
160
- }
171
+ perform_base_backup (backup_label , progress , dir );
161
172
162
- ti = palloc (sizeof (tablespaceinfo ));
163
- ti -> oid = pstrdup (de -> d_name );
164
- ti -> path = pstrdup (linkpath );
165
- ti -> size = progress ? sendDir (linkpath , strlen (linkpath ), true) : -1 ;
166
- tablespaces = lappend (tablespaces , ti );
167
- }
168
173
FreeDir (dir );
169
174
170
- perform_base_backup (backup_label , tablespaces );
171
-
172
175
MemoryContextSwitchTo (old_context );
173
176
MemoryContextDelete (backup_context );
174
177
}
0 commit comments