Skip to content

Deno's fs.openSync fails with O_RDONLY | O_CREAT #26235

@sbc100

Description

@sbc100

The following program works find under node and bun:

import { openSync, closeSync, constants } from "node:fs";

// Create or open a file for writing, creates if it doesn't exist
const fd = openSync("./log.txt", constants.O_WRONLY | constants.O_CREAT);
// ... operations
closeSync(fd);

But not under deno:

$ ~/.deno/bin/deno -A test.mjs
error: Uncaught (in promise) TypeError: creating or truncating a file requires write or append access
const fd = openSync("missing.txt", constants.O_RDONLY | constants.O_CREAT);
           ^
    at openSync (ext:deno_node/_fs/_fs_open.ts:43:12)
    at file:///usr/local/google/home/sbc/dev/wasm/emscripten/test.mjs:3:12

The C equivalent also seem to work fine, so I think maybe deno is wrong here?

#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>

int main() {
  int fd = open("missing.txt", O_RDONLY|O_CREAT, 0x777);
  printf("%d\n", fd);
  return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions