| 249 | os.close(fd) |
| 250 | |
| 251 | def write(self, relative, data): |
| 252 | self.check() |
| 253 | parent, name = os.path.split(relative) |
| 254 | fd = _directory(os.path.join(self.path, parent)) |
| 255 | try: |
| 256 | target = os.open(name, os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_NOFOLLOW, |
| 257 | 0o600, dir_fd=fd) |
| 258 | try: |
| 259 | with os.fdopen(target, "wb") as stream: |
| 260 | stream.write(data) |
| 261 | stream.flush() |
| 262 | os.fsync(stream.fileno()) |
| 263 | except BaseException: |
| 264 | # Partial evidence remains; no marker is created on this path. |
| 265 | raise |
| 266 | finally: |
| 267 | os.close(fd) |
| 268 | return os.path.join(self.path, relative) |
| 269 | |
| 270 | def json(self, relative, value): |
| 271 | data = (json.dumps(value, sort_keys=True, indent=2, |