本文整理汇总了Python中os.O_DIRECTORY属性的典型用法代码示例。如果您正苦于以下问题:Python os.O_DIRECTORY属性的具体用法?Python os.O_DIRECTORY怎么用?Python os.O_DIRECTORY使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类os
的用法示例。
在下文中一共展示了os.O_DIRECTORY属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: close
# 需要导入模块: import os [as 别名]
# 或者: from os import O_DIRECTORY [as 别名]
def close(self):
if self.state == 2:
if dry_run:
logger.info("dry run config transaction can be found in {}".format(self.temp_path))
else:
logger.info("closing config transaction")
shutil.move(self.temp_path, self.path)
# sync
dirfd = os.open(self.dir, os.O_DIRECTORY)
os.fsync(dirfd)
os.close(dirfd)
os.system('sync')
else:
logger.warn("closing config transaction with no edits")
self.set_state_idle()
示例2: fsync_dir
# 需要导入模块: import os [as 别名]
# 或者: from os import O_DIRECTORY [as 别名]
def fsync_dir(dir_path):
"""
Execute fsync on a directory ensuring it is synced to disk
:param str dir_path: The directory to sync
:raise OSError: If fail opening the directory
"""
dir_fd = os.open(dir_path, os.O_DIRECTORY)
try:
os.fsync(dir_fd)
except OSError as e:
# On some filesystem doing a fsync on a directory
# raises an EINVAL error. Ignoring it is usually safe.
if e.errno != errno.EINVAL:
raise
finally:
os.close(dir_fd)
示例3: device
# 需要导入模块: import os [as 别名]
# 或者: from os import O_DIRECTORY [as 别名]
def device(self, filename, offset=None, sizelimit=None):
req = {}
fds = []
fd = os.open(filename, os.O_RDWR)
dir_fd = os.open("/dev", os.O_DIRECTORY)
fds.append(fd)
req["fd"] = 0
fds.append(dir_fd)
req["dir_fd"] = 1
if offset:
req["offset"] = offset
if sizelimit:
req["sizelimit"] = sizelimit
self.client.send(req, fds=fds)
os.close(dir_fd)
os.close(fd)
payload, _, _ = self.client.recv()
path = os.path.join("/dev", payload["devname"])
try:
yield path
finally:
os.unlink(path)
示例4: __init__
# 需要导入模块: import os [as 别名]
# 或者: from os import O_DIRECTORY [as 别名]
def __init__(self, minor, dir_fd=None):
"""
Parameters
----------
minor
the minor number of the underlying device
dir_fd : int, optional
A directory file descriptor to a filesystem containing the
underlying device node, or None to use /dev (default is None)
Raises
------
UnexpectedDevice
If the file in the expected device node location is not the
expected device node
"""
self.devname = f"loop{minor}"
self.minor = minor
with contextlib.ExitStack() as stack:
if not dir_fd:
dir_fd = os.open("/dev", os.O_DIRECTORY)
stack.callback(lambda: os.close(dir_fd))
self.fd = os.open(self.devname, os.O_RDWR, dir_fd=dir_fd)
info = os.stat(self.fd)
if ((not stat.S_ISBLK(info.st_mode)) or
(not os.major(info.st_rdev) == self.LOOP_MAJOR) or
(not os.minor(info.st_rdev) == minor)):
raise UnexpectedDevice(minor, info.st_rdev, info.st_mode)
示例5: _open
# 需要导入模块: import os [as 别名]
# 或者: from os import O_DIRECTORY [as 别名]
def _open(self):
"""Open the directory and return the file descriptor"""
with self.read() as path:
fd = os.open(path, os.O_DIRECTORY)
try:
yield fd
finally:
os.close(fd)
示例6: test_helpers_readlink_dirfd
# 需要导入模块: import os [as 别名]
# 或者: from os import O_DIRECTORY [as 别名]
def test_helpers_readlink_dirfd(tmp_path):
origin = tmp_path / 'parent' / 'original.txt'
origin.parent.mkdir(parents=True, exist_ok=True)
with origin.open('w') as f:
f.write("Original")
slink = tmp_path / "target" / "link"
slink.parent.mkdir(parents=True, exist_ok=True)
target = pathlib.Path('../parent/original.txt')
slink.symlink_to(target, False)
dirfd = os.open(str(origin.parent), os.O_RDONLY | os.O_DIRECTORY)
assert py7zr.helpers.readlink(slink, dir_fd=dirfd) == target
os.close(dirfd)
示例7: _open_directory
# 需要导入模块: import os [as 别名]
# 或者: from os import O_DIRECTORY [as 别名]
def _open_directory(self, path):
return self.exitstack.enter_context(
FileDescriptor(path, os.O_PATH | os.O_DIRECTORY | os.O_CLOEXEC))
示例8: __init__
# 需要导入模块: import os [as 别名]
# 或者: from os import O_DIRECTORY [as 别名]
def __init__(self, mountpoint):
self.fd = os.open(mountpoint, os.O_DIRECTORY)