def ar_mkdir(root, path, mode, exists_is_ok=False): """A function similar to os.mkdir() that ensures that the path we're opening resides within a specified directory subtree. For all other parameters, refer to the 'ar_open' function for an explanation of their usage and effects.""" # all paths must be absolute assert os.path.isabs(root) # make target into a relative path if os.path.isabs(path): path = __path_abs_to_relative(path) path_dir = os.path.dirname(path) path_file = os.path.basename(path) path_dir_fd = ar_open(root, path_dir, os.O_RDONLY) try: sat.mkdirat(path_dir_fd, path_file, mode) except OSError as e: os.close(path_dir_fd) if exists_is_ok and e.errno == errno.EEXIST: return raise e os.close(path_dir_fd) return
def ar_mkdir(root, path, mode): """A function similar to os.mkdir() that ensures that the path we're opening resides within a specified directory subtree. For all other parameters, refer to the 'ar_open' function for an explanation of their usage and effects.""" # all paths must be absolute assert os.path.isabs(root) # make target into a relative path if os.path.isabs(path): path = __path_abs_to_relative(path) path_dir = os.path.dirname(path) path_file = os.path.basename(path) path_dir_fd = ar_open(root, path_dir, os.O_RDONLY) try: sat.mkdirat(path_dir_fd, path_file, mode) except OSError, e: os.close(path_dir_fd) raise e