Skip to content

Commit

Permalink
Put tmp alongside the target
Browse files Browse the repository at this point in the history
  • Loading branch information
ascorbic committed Dec 11, 2024
1 parent 8e9ecf0 commit 565f40f
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions packages/astro/src/content/mutable-data-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,14 @@ import { AstroError, AstroErrorData } from '../core/errors/index.js';
import { IMAGE_IMPORT_PREFIX } from './consts.js';
import { type DataEntry, ImmutableDataStore } from './data-store.js';
import { contentModuleToId } from './utils.js';
import { tmpdir } from 'node:os';
import { join } from 'node:path';

const SAVE_DEBOUNCE_MS = 500;

// Write a file atomically, without triggering the file watcher
// Write a file atomically
async function writeFileAtomic(filePath: PathLike, data: string) {
const dir = await fs.mkdtemp(tmpdir() + '/astro-');
const tempFile = join(dir, 'temp');
const tempFile = filePath instanceof URL ? new URL(`${filePath.href}.tmp`) : `${filePath}.tmp`;
await fs.writeFile(tempFile, data);
try {
await fs.rename(tempFile, filePath);
} finally {
await fs.rmdir(dir).catch(() => {});
}
await fs.rename(tempFile, filePath);
}

/**
Expand Down

0 comments on commit 565f40f

Please sign in to comment.