diff --git a/dist/pinned-python.js b/dist/pinned-python.js index c6177eaf56295780ef2edba47ca8bee02cdcdbf2..f6f361974d48f8f4abd3f1e47f1fdb10bc3f2f77 100644 --- a/dist/pinned-python.js +++ b/dist/pinned-python.js @@ -93,6 +93,12 @@ def write_all(fd, data): if written <= 0: raise OSError(errno.EIO, "short write") view = view[written:] +def fsync_best_effort(fd): + try: + os.fsync(fd) + except OSError as error: + if error.errno != errno.EPERM: + raise def link_unsupported(exc): unsupported = (errno.EPERM, errno.EOPNOTSUPP, getattr(errno, "ENOTSUP", errno.EOPNOTSUPP)) return getattr(exc, "errno", None) in unsupported @@ -298,13 +304,13 @@ def write_path(root_fd, payload): temp_name, temp_fd = create_temp_file(parent_fd, basename, mode) os.fchmod(temp_fd, mode) write_all(temp_fd, data) - os.fsync(temp_fd) + fsync_best_effort(temp_fd) temp_stat = os.fstat(temp_fd) os.close(temp_fd) temp_fd = None result_stat = commit_temp_file(parent_fd, temp_name, basename, overwrite, mode, temp_stat) temp_name = None - os.fsync(parent_fd) + fsync_best_effort(parent_fd) return {"dev": result_stat.st_dev, "ino": result_stat.st_ino} finally: if temp_fd is not None: diff --git a/dist/pinned-write.js b/dist/pinned-write.js index 77d0ddfa5a1df2de0449c806d19781daaed4910b..09dd77aef95659865b93ce29e15f26e874dd0c25 100644 --- a/dist/pinned-write.js +++ b/dist/pinned-write.js @@ -31,6 +31,16 @@ function assertWithinMaxBytes(bytes, maxBytes) { throw new FsSafeError("too-large", `file exceeds limit of ${maxBytes} bytes (got at least ${bytes})`); } } +async function syncFileBestEffort(handle) { + try { + await handle.sync(); + } + catch (error) { + if (error?.code !== "EPERM") { + throw error; + } + } +} async function writeStreamToHandle(stream, handle, maxBytes) { let bytes = 0; for await (const chunk of stream) { @@ -192,7 +202,7 @@ async function runPinnedWriteFallback(params) { else { await writeStreamToHandle(params.input.stream, handle, params.maxBytes); } - await handle.sync(); + await syncFileBestEffort(handle); const stat = await handle.stat(); await handle.close().catch(() => undefined); await syncDirectoryBestEffort(parentPath); @@ -237,7 +247,7 @@ async function runPinnedWriteFallback(params) { throw new FsSafeError("path-mismatch", "fallback temp path changed during write"); } const expectedTempStat = tempStat; - await handle.sync(); + await syncFileBestEffort(handle); await handle.close().catch(() => undefined); handle = undefined; await withAsyncDirectoryGuards([parentGuard], async () => {