MCPcopy Create free account
hub / github.com/cloudflare/computer / openSync

Method openSync

packages/dofs/src/provider.ts:141–172  ·  view source on GitHub ↗
(path: string, flags: string = "r", _mode?: number)

Source from the content-addressed store, hash-verified

139 }
140
141 openSync(path: string, flags: string = "r", _mode?: number): number {
142 const { read, write, truncate, append, create, exclusive } = parseFlags(flags);
143 const existing = resolveInode(this.db, path);
144
145 if (existing === null) {
146 if (!create) {
147 throw createWorkspaceError("ENOENT", `no such file: ${path}`, path);
148 }
149 writeFileSyncImpl(this.db, path, new Uint8Array(), {}, this.now);
150 } else {
151 if (existing.type !== "file") {
152 throw createWorkspaceError("EISDIR", `path is a directory: ${path}`, path);
153 }
154 if (exclusive) {
155 throw createWorkspaceError("EEXIST", `path exists: ${path}`, path);
156 }
157 if (truncate) {
158 writeFileSyncImpl(this.db, path, new Uint8Array(), {}, this.now);
159 }
160 }
161
162 const stat = statImpl(this.db, path);
163 const fd = this.#nextFd++;
164 this.#fds.set(fd, {
165 path,
166 position: append ? stat.size : 0,
167 readable: read,
168 writable: write,
169 append,
170 });
171 return fd;
172 }
173
174 stat(path: string, options?: { bigint?: boolean }): Promise<VirtualStatsLike> {
175 return Promise.resolve(this.statSync(path, options));

Callers 4

openMethod · 0.95
wire.test.tsFile · 0.80

Calls 4

resolveInodeFunction · 0.85
parseFlagsFunction · 0.70
createWorkspaceErrorFunction · 0.70
setMethod · 0.65

Tested by

no test coverage detected