(path: string, size: number, cb: StatusCallback)
| 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 => { |
no test coverage detected