summaryrefslogtreecommitdiff
path: root/linuxnamespaces/atlocation.py
diff options
context:
space:
mode:
Diffstat (limited to 'linuxnamespaces/atlocation.py')
-rw-r--r--linuxnamespaces/atlocation.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/linuxnamespaces/atlocation.py b/linuxnamespaces/atlocation.py
index 20d402a..a4255a6 100644
--- a/linuxnamespaces/atlocation.py
+++ b/linuxnamespaces/atlocation.py
@@ -7,6 +7,7 @@ to work with a location described in this way and this module provides support
code for doing so.
"""
+import contextlib
import enum
import errno
import os
@@ -218,7 +219,12 @@ class AtLocation:
"chdir on AtLocation only supports flag AT_EMPTY_PATH"
)
assert self.location
- return os.chdir(self.location)
+ if self.fd == AT_FDCWD:
+ return os.chdir(self.location)
+ with contextlib.closing(
+ FileDescriptor(self.open(flags=os.O_PATH | os.O_CLOEXEC))
+ ) as dirfd:
+ return os.fchdir(dirfd)
def chmod(self, mode: int) -> None:
"""Wrapper for os.chmod or os.fchmod."""