@@ -1222,7 +1222,7 @@ def pgdata_content(self, pgdata, ignore_ptrack=True, exclude_dirs=None):
1222
1222
directory_dict = {}
1223
1223
directory_dict ['pgdata' ] = pgdata
1224
1224
directory_dict ['files' ] = {}
1225
- directory_dict ['dirs' ] = []
1225
+ directory_dict ['dirs' ] = {}
1226
1226
for root , dirs , files in os .walk (pgdata , followlinks = True ):
1227
1227
dirs [:] = [d for d in dirs if d not in dirs_to_ignore ]
1228
1228
for file in files :
@@ -1267,7 +1267,18 @@ def pgdata_content(self, pgdata, ignore_ptrack=True, exclude_dirs=None):
1267
1267
break
1268
1268
1269
1269
if not found :
1270
- directory_dict ['dirs' ].append (directory_relpath )
1270
+ directory_dict ['dirs' ][directory_relpath ] = {}
1271
+
1272
+ # get permissions for every file and directory
1273
+ for file in directory_dict ['dirs' ]:
1274
+ full_path = os .path .join (pgdata , file )
1275
+ directory_dict ['dirs' ][file ]['mode' ] = os .stat (
1276
+ full_path ).st_mode
1277
+
1278
+ for file in directory_dict ['files' ]:
1279
+ full_path = os .path .join (pgdata , file )
1280
+ directory_dict ['files' ][file ]['mode' ] = os .stat (
1281
+ full_path ).st_mode
1271
1282
1272
1283
return directory_dict
1273
1284
@@ -1283,6 +1294,21 @@ def compare_pgdata(self, original_pgdata, restored_pgdata):
1283
1294
error_message += '\n Directory was not present'
1284
1295
error_message += ' in original PGDATA: {0}\n ' .format (
1285
1296
os .path .join (restored_pgdata ['pgdata' ], directory ))
1297
+ else :
1298
+ if (
1299
+ restored_pgdata ['dirs' ][directory ]['mode' ] !=
1300
+ original_pgdata ['dirs' ][directory ]['mode' ]
1301
+ ):
1302
+ fail = True
1303
+ error_message += '\n Dir permissions mismatch:\n '
1304
+ error_message += ' Dir old: {0} Permissions: {1}\n ' .format (
1305
+ os .path .join (original_pgdata ['pgdata' ], directory ),
1306
+ original_pgdata ['dirs' ][directory ]['mode' ])
1307
+ error_message += ' Dir new: {0} Permissions: {1}\n ' .format (
1308
+ os .path .join (restored_pgdata ['pgdata' ], directory ),
1309
+ restored_pgdata ['dirs' ][directory ]['mode' ])
1310
+
1311
+
1286
1312
1287
1313
for directory in original_pgdata ['dirs' ]:
1288
1314
if directory not in restored_pgdata ['dirs' ]:
@@ -1305,6 +1331,19 @@ def compare_pgdata(self, original_pgdata, restored_pgdata):
1305
1331
for file in original_pgdata ['files' ]:
1306
1332
if file in restored_pgdata ['files' ]:
1307
1333
1334
+ if (
1335
+ restored_pgdata ['files' ][file ]['mode' ] !=
1336
+ original_pgdata ['files' ][file ]['mode' ]
1337
+ ):
1338
+ fail = True
1339
+ error_message += '\n File permissions mismatch:\n '
1340
+ error_message += ' File_old: {0} Permissions: {1}\n ' .format (
1341
+ os .path .join (original_pgdata ['pgdata' ], file ),
1342
+ original_pgdata ['files' ][file ]['mode' ])
1343
+ error_message += ' File_new: {0} Permissions: {1}\n ' .format (
1344
+ os .path .join (restored_pgdata ['pgdata' ], file ),
1345
+ restored_pgdata ['files' ][file ]['mode' ])
1346
+
1308
1347
if (
1309
1348
original_pgdata ['files' ][file ]['md5' ] !=
1310
1349
restored_pgdata ['files' ][file ]['md5' ]
0 commit comments