fix samefile check and relative path test

This commit is contained in:
Mike McLean 2024-02-13 15:31:40 -05:00 committed by Tomas Kopecek
parent e8ae18fcc8
commit ce4718f1fb
2 changed files with 7 additions and 5 deletions

View file

@ -576,6 +576,7 @@ def _rmtree_nofork(path, logger=None):
raise koji.GenericError("Not a directory: %s" % path)
dev = st.st_dev
cwd = os.getcwd()
abspath = os.path.abspath(path)
try:
# retry loop
@ -584,7 +585,7 @@ def _rmtree_nofork(path, logger=None):
os.chdir(path)
new_cwd = os.getcwd()
# make sure we're where we think we are
if not os.path.samefile(new_cwd, path):
if not os.path.samefile(new_cwd, abspath):
raise koji.GenericError('chdir to %s resulted in different cwd %s',
path, new_cwd)
except OSError as e:

View file

@ -1640,17 +1640,18 @@ class TestRmtree2(unittest.TestCase):
raise Exception('test directory not removed')
def test_rmtree_relative(self):
dirname = 'some-dir-95628' # relative
os.makedirs('%s/%s/a/b/c/d/e/f/g/h/i/j/k' % (self.tempdir, dirname))
relpath = 'some-dir-95628'
path = "%s/%s" % (self.tempdir, relpath)
os.makedirs('%s/a/b/c/d/e/f/g/h/i/j/k' % path)
oldcwd = os.getcwd()
os.chdir(self.tempdir)
try:
koji.util._rmtree_nofork(dirname)
koji.util._rmtree_nofork(relpath)
finally:
os.chdir(oldcwd)
if not os.path.exists(dirname):
if os.path.exists(path):
raise Exception('test directory not removed')
def test_rmtree_dev_change(self):