Skip to content

Commit

Permalink
[PBCKP-159] fix false directory init, add test to init.py
Browse files Browse the repository at this point in the history
Tags: pg_probackup
  • Loading branch information
Sofia Kopikova committed May 23, 2022
1 parent 22c8083 commit 54ce603
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ do_init(CatalogState *catalogState)
elog(ERROR, "cannot open backup catalog directory \"%s\": %s",
catalogState->catalog_path, strerror(errno_tmp));
}
else if (results == 1)
{
/* Check whether we have all(rwx) rights for directory */
if (access(catalogState->catalog_path, R_OK | W_OK | X_OK) == -1)
{
int errno_tmp = errno;
elog(ERROR, "cannot access backup catalog directory \"%s\": %s",
catalogState->catalog_path, strerror(errno_tmp));
}
}

/* create backup catalog root directory */
dir_create_dir(catalogState->catalog_path, DIR_PERMISSION, false);
Expand Down
26 changes: 26 additions & 0 deletions tests/init.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import stat # for chmod
import unittest
from .helpers.ptrack_helpers import dir_files, ProbackupTest, ProbackupException
import shutil
Expand Down Expand Up @@ -86,6 +87,31 @@ def test_already_exist(self):

# Clean after yourself
self.del_test_dir(module_name, fname)

# @unittest.skip("skip")
def test_no_rights_for_directory(self):
"""
Failure with backup catalog existed and empty
but current user has no rights for writing to it
"""
fname = self.id().split(".")[3]
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
os.mkdir(backup_dir)
os.chmod(backup_dir, stat.S_IREAD) # set read-only flag for current user
node = self.make_simple_node(base_dir=os.path.join(module_name, fname, 'node'))
self.init_pb(backup_dir)
try:
self.show_pb(backup_dir, 'node')
self.assertEqual(1, 0, 'Expecting Error due to initialization in empty directory with no rithts for writing. Output: {0} \n CMD: {1}'.format(
repr(self.output), self.cmd))
except ProbackupException as e:
self.assertIn(
"ERROR: Instance 'node' does not exist in this backup catalog",
e.message,
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(repr(e.message), self.cmd))

# Clean after yourself
self.del_test_dir(module_name, fname)

# @unittest.skip("skip")
def test_abs_path(self):
Expand Down

0 comments on commit 54ce603

Please sign in to comment.