Skip to content

Commit 54ce603

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

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-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

+26
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,31 @@ 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+
"""
94+
Failure with backup catalog existed and empty
95+
but current user has no rights for writing to it
96+
"""
97+
fname = self.id().split(".")[3]
98+
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
99+
os.mkdir(backup_dir)
100+
os.chmod(backup_dir, stat.S_IREAD) # set read-only flag for current user
101+
node = self.make_simple_node(base_dir=os.path.join(module_name, fname, 'node'))
102+
self.init_pb(backup_dir)
103+
try:
104+
self.show_pb(backup_dir, 'node')
105+
self.assertEqual(1, 0, 'Expecting Error due to initialization in empty directory with no rithts for writing. Output: {0} \n CMD: {1}'.format(
106+
repr(self.output), self.cmd))
107+
except ProbackupException as e:
108+
self.assertIn(
109+
"ERROR: Instance 'node' does not exist in this backup catalog",
110+
e.message,
111+
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(e.message), self.cmd))
112+
113+
# Clean after yourself
114+
self.del_test_dir(module_name, fname)
89115

90116
# @unittest.skip("skip")
91117
def test_abs_path(self):

0 commit comments

Comments
 (0)