filePath() — astro Function Reference
Architecture documentation for the filePath() function in mutable-data-store.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD effd8772_74ef_ad7d_4e58_038798d1ffa2["filePath()"] ecb98618_124a_e276_dd98_561beaedc6ea["MutableDataStore"] effd8772_74ef_ad7d_4e58_038798d1ffa2 -->|defined in| ecb98618_124a_e276_dd98_561beaedc6ea b5e836b4_e486_8e7c_a9a7_0b1cd24656c6["toString()"] effd8772_74ef_ad7d_4e58_038798d1ffa2 -->|calls| b5e836b4_e486_8e7c_a9a7_0b1cd24656c6 style effd8772_74ef_ad7d_4e58_038798d1ffa2 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/src/content/mutable-data-store.ts lines 249–285
async #writeFileAtomic(filePath: PathLike, data: string, depth = 0) {
if (depth > MAX_DEPTH) {
// If we hit the max depth, we skip a write to prevent the stack from growing too large
// In theory this means we may miss the latest data, but in practice this will only happen when the file is being written to very frequently
// so it will be saved on the next write. This is unlikely to ever happen in practice, as the writes are debounced. It requires lots of writes to very large files.
return;
}
const fileKey = filePath.toString();
// If we are already writing this file, instead of writing now, flag it as pending and write it when we're done.
if (this.#writing.has(fileKey)) {
this.#pending.add(fileKey);
return;
}
// Prevent concurrent writes to this file by flagging it as being written
this.#writing.add(fileKey);
const tempFile = filePath instanceof URL ? new URL(`${filePath.href}.tmp`) : `${filePath}.tmp`;
try {
const oldData = await fs.readFile(filePath, 'utf-8').catch(() => '');
if (oldData === data) {
// If the data hasn't changed, we can skip the write
return;
}
// Write it to a temporary file first and then move it to prevent partial reads.
await fs.writeFile(tempFile, data);
await fs.rename(tempFile, filePath);
} finally {
// We're done writing. Unflag the file and check if there are any pending writes for this file.
this.#writing.delete(fileKey);
// If there are pending writes, we need to write again to ensure we flush the latest data.
if (this.#pending.has(fileKey)) {
this.#pending.delete(fileKey);
// Call ourself recursively to write the file again
await this.#writeFileAtomic(filePath, data, depth + 1);
}
}
}
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does filePath() do?
filePath() is a function in the astro codebase, defined in packages/astro/src/content/mutable-data-store.ts.
Where is filePath() defined?
filePath() is defined in packages/astro/src/content/mutable-data-store.ts at line 249.
What does filePath() call?
filePath() calls 1 function(s): toString.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free