Create and hold a capability to a directory.
(self, basename)
| 1051 | return rproc |
| 1052 | |
| 1053 | def open_dir_background(self, basename): |
| 1054 | """ |
| 1055 | Create and hold a capability to a directory. |
| 1056 | """ |
| 1057 | assert(self.is_mounted()) |
| 1058 | |
| 1059 | path = os.path.join(self.hostfs_mntpt, basename) |
| 1060 | |
| 1061 | pyscript = dedent(""" |
| 1062 | import fcntl |
| 1063 | import sys |
| 1064 | import time |
| 1065 | import os |
| 1066 | |
| 1067 | fcntl.fcntl(sys.stdin, fcntl.F_SETFL, fcntl.fcntl(sys.stdin, fcntl.F_GETFL) | os.O_NONBLOCK) |
| 1068 | |
| 1069 | os.mkdir("{path}") |
| 1070 | fd = os.open("{path}", os.O_RDONLY) |
| 1071 | while True: |
| 1072 | print("open_dir_background: keeping dir open", file=sys.stderr) |
| 1073 | try: |
| 1074 | if os.read(0, 4096) == b"": |
| 1075 | break |
| 1076 | except BlockingIOError: |
| 1077 | pass |
| 1078 | time.sleep(2) |
| 1079 | """).format(path=path) |
| 1080 | |
| 1081 | rproc = self._run_python(pyscript) |
| 1082 | self.background_procs.append(rproc) |
| 1083 | |
| 1084 | self.wait_for_visible(basename) |
| 1085 | |
| 1086 | return rproc |
| 1087 | |
| 1088 | def wait_for_dir_empty(self, dirname, timeout=30): |
| 1089 | dirpath = os.path.join(self.hostfs_mntpt, dirname) |