Skip to content

Commit 64452d7

Browse files
author
Sofia Kopikova
committed
[PBCKP-159] fix false directory init, add test to init.py
Tags: pg_probackup
1 parent 22c8083 commit 64452d7

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/init.c

+10
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ do_init(CatalogState *catalogState)
3131
elog(ERROR, "cannot open backup catalog directory \"%s\": %s",
3232
catalogState->catalog_path, strerror(errno_tmp));
3333
}
34+
else if (results == 1)
35+
{
36+
/* Check whether we have all(rwx) rights for directory */
37+
if (access(catalogState->catalog_path, R_OK | W_OK | X_OK) == -1)
38+
{
39+
int errno_tmp = errno;
40+
elog(ERROR, "cannot access backup catalog directory \"%s\": %s",
41+
catalogState->catalog_path, strerror(errno_tmp));
42+
}
43+
}
3444

3545
/* create backup catalog root directory */
3646
dir_create_dir(catalogState->catalog_path, DIR_PERMISSION, false);

tests/init.py

+24
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import stat # for chmod
23
import unittest
34
from .helpers.ptrack_helpers import dir_files, ProbackupTest, ProbackupException
45
import shutil
@@ -86,6 +87,29 @@ def test_already_exist(self):
8687

8788
# Clean after yourself
8889
self.del_test_dir(module_name, fname)
90+
91+
# @unittest.skip("skip")
92+
def test_no_rights_for_directory(self):
93+
"""Failure with backup catalog existed and empty but user has no writing permissions"""
94+
fname = self.id().split(".")[3]
95+
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
96+
os.mkdir(backup_dir)
97+
os.chmod(backup_dir, stat.S_IREAD) # set read-only flag for current user
98+
assert os.access(backup_dir, os.R_OK) and not os.access(backup_dir, os.W_OK)
99+
node = self.make_simple_node(base_dir=os.path.join(module_name, fname, 'node'))
100+
self.init_pb(backup_dir)
101+
try:
102+
self.show_pb(backup_dir, 'node')
103+
self.assertEqual(1, 0, 'Expecting Error due to initialization in empty directory with no rithts for writing. Output: {0} \n CMD: {1}'.format(
104+
repr(self.output), self.cmd))
105+
except ProbackupException as e:
106+
self.assertIn(
107+
"ERROR: Instance 'node' does not exist in this backup catalog",
108+
e.message,
109+
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(e.message), self.cmd))
110+
111+
# Clean after yourself
112+
self.del_test_dir(module_name, fname)
89113

90114
# @unittest.skip("skip")
91115
def test_abs_path(self):

0 commit comments

Comments
 (0)