@@ -40,7 +40,7 @@ static void send_int8_string(StringInfoData *buf, int64 intval);
4040static void SendBackupHeader (List * tablespaces );
4141static void SendBackupDirectory (char * location ,char * spcoid );
4242static 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 );
4444
4545typedef struct
4646{
@@ -67,13 +67,50 @@ base_backup_cleanup(int code, Datum arg)
6767 * clobbered by longjmp" from stupider versions of gcc.
6868 */
6969static void
70- perform_base_backup (const char * backup_label ,List * tablespaces )
70+ perform_base_backup (const char * backup_label ,bool progress , DIR * tblspcdir )
7171{
7272do_pg_start_backup (backup_label , true);
7373
7474PG_ENSURE_ERROR_CLEANUP (base_backup_cleanup , (Datum )0 );
7575{
76+ List * tablespaces = NIL ;
7677ListCell * 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+
77114
78115/* Send tablespace header */
79116SendBackupHeader (tablespaces );
101138SendBaseBackup (const char * backup_label ,bool progress )
102139{
103140DIR * dir ;
104- struct dirent * de ;
105- List * tablespaces = NIL ;
106- tablespaceinfo * ti ;
107141MemoryContext backup_context ;
108142MemoryContext old_context ;
109143
@@ -134,41 +168,10 @@ SendBaseBackup(const char *backup_label, bool progress)
134168ereport (ERROR ,
135169(errmsg ("unable to open directory pg_tblspc: %m" )));
136170
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 );
161172
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- }
168173FreeDir (dir );
169174
170- perform_base_backup (backup_label ,tablespaces );
171-
172175MemoryContextSwitchTo (old_context );
173176MemoryContextDelete (backup_context );
174177}