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

Function truncatePath

packages/computerd/src/fuse/driver.ts:390–438  ·  view source on GitHub ↗
(path: string, size: number, cb: StatusCallback)

Source from the content-addressed store, hash-verified

388 };
389
390 const truncatePath = (path: string, size: number, cb: StatusCallback): void => {
391 if (!exists(path)) {
392 cb(ERRNO.ENOENT);
393 return;
394 }
395 let entry = files.get(path);
396 if (entry === undefined) {
397 if (hasDirectWrites) {
398 if (size > MAX_FILE_BYTES) {
399 cb(ERRNO.EFBIG);
400 return;
401 }
402 try {
403 directWriteVfs.truncateFileSync?.(toVfs(path), size);
404 cb(0);
405 } catch (error) {
406 cb(toErrno(error));
407 }
408 return;
409 }
410 try {
411 const data = vfs.readFileSync(toVfs(path));
412 entry = {
413 buf: data,
414 size: data.length,
415 dirty: false,
416 dirtyRanges: [],
417 pendingCreate: false,
418 mode: modeFromVfs(path),
419 pendingMtime: new Date(),
420 };
421 files.set(path, entry);
422 } catch (error) {
423 cb(toErrno(error));
424 return;
425 }
426 }
427 if (size > entry.size) {
428 if (!ensureCapacity(entry, size)) {
429 cb(ERRNO.EFBIG);
430 return;
431 }
432 entry.buf.fill(0, entry.size, size);
433 }
434 const previousSize = entry.size;
435 entry.size = size;
436 markDirty(entry, Math.min(previousSize, size), Math.max(previousSize, size));
437 cb(0);
438 };
439
440 const warnedOperations = new Set<string>();
441 const notImplemented = (operation: string): NotImplementedOperation => {

Callers 2

truncateFunction · 0.85
ftruncateFunction · 0.85

Calls 10

toVfsFunction · 0.85
toErrnoFunction · 0.85
modeFromVfsFunction · 0.85
markDirtyFunction · 0.85
readFileSyncMethod · 0.80
existsFunction · 0.70
ensureCapacityFunction · 0.70
getMethod · 0.65
truncateFileSyncMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected