@@ -939,6 +939,7 @@ opt_externaldir_map(ConfigOption *opt, const char *arg)
939
939
* Enforce permissions from backup_content.control. The only
940
940
* problem now is with PGDATA itself.
941
941
* TODO: we must preserve PGDATA permissions somewhere. Is it actually a problem?
942
+ * Shouldn`t starting postgres force correct permissions on PGDATA?
942
943
*
943
944
* TODO: symlink handling. If user located symlink in PG_TBLSPC_DIR, it will
944
945
* be restored as directory.
@@ -949,35 +950,9 @@ create_data_directories(parray *dest_files, const char *data_dir, const char *ba
949
950
{
950
951
int i ;
951
952
parray * links = NULL ;
952
- mode_t pg_tablespace_mode = 0 ;
953
+ mode_t pg_tablespace_mode = DIR_PERMISSION ;
953
954
char to_path [MAXPGPATH ];
954
955
955
- /* Ugly: get PG_TBLSPC_DIR pemission mask.
956
- * We will use it to set permissions for tablespace directories.
957
- */
958
- for (i = 0 ; i < parray_num (dest_files ); i ++ )
959
- {
960
- pgFile * file = (pgFile * ) parray_get (dest_files , i );
961
-
962
- if (!S_ISDIR (file -> mode ))
963
- continue ;
964
-
965
- /* skip external directory content */
966
- if (file -> external_dir_num != 0 )
967
- continue ;
968
-
969
- /* look for 'pg_tblspc' directory */
970
- if (strcmp (file -> rel_path , PG_TBLSPC_DIR ) == 0 )
971
- {
972
- pg_tablespace_mode = file -> mode ;
973
- break ;
974
- }
975
- }
976
-
977
- /* sanity */
978
- if (!pg_tablespace_mode )
979
- pg_tablespace_mode = DIR_PERMISSION ;
980
-
981
956
/* get tablespace map */
982
957
if (extract_tablespaces )
983
958
{
@@ -987,6 +962,39 @@ create_data_directories(parray *dest_files, const char *data_dir, const char *ba
987
962
parray_qsort (links , pgFileCompareName );
988
963
}
989
964
965
+ /*
966
+ * We have no idea about tablespace permission
967
+ * For PG < 11 we can just force default permissions.
968
+ */
969
+ #if PG_VERSION_NUM >= 110000
970
+ if (links )
971
+ {
972
+ /* For PG>=11 we use temp kludge: trust permissions on 'pg_tblspc'
973
+ * and force them on every tablespace.
974
+ * TODO: remove kludge and ask data_directory_mode
975
+ * at the start of backup.
976
+ */
977
+ for (i = 0 ; i < parray_num (dest_files ); i ++ )
978
+ {
979
+ pgFile * file = (pgFile * ) parray_get (dest_files , i );
980
+
981
+ if (!S_ISDIR (file -> mode ))
982
+ continue ;
983
+
984
+ /* skip external directory content */
985
+ if (file -> external_dir_num != 0 )
986
+ continue ;
987
+
988
+ /* look for 'pg_tblspc' directory */
989
+ if (strcmp (file -> rel_path , PG_TBLSPC_DIR ) == 0 )
990
+ {
991
+ pg_tablespace_mode = file -> mode ;
992
+ break ;
993
+ }
994
+ }
995
+ }
996
+ #endif
997
+
990
998
/*
991
999
* We iterate over dest_files and for every directory with parent 'pg_tblspc'
992
1000
* we must lookup this directory name in tablespace map.
0 commit comments