Skip to content

Commit fe9f347

Browse files
authored
Merge pull request #9 from apify/fix/exdev-cross-device-rename
fix: avoid EXDEV error when writing temp files on Linux
2 parents da6e7f3 + e7788c8 commit fe9f347

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/lib/auth/profiles.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

77
import { readFile, writeFile, rename, unlink } from 'fs/promises';
8-
import { tmpdir } from 'os';
98
import { join } from 'path';
109
import type { AuthProfile, AuthProfilesStorage } from '../types.js';
1110
import {
@@ -64,7 +63,9 @@ async function saveAuthProfilesInternal(storage: AuthProfilesStorage): Promise<v
6463
await ensureDir(getMcpcHome());
6564

6665
// Write to a temp file first (atomic operation)
67-
const tempFile = join(tmpdir(), `mcpc-auth-profiles-${Date.now()}-${process.pid}.json`);
66+
// Write temp file in the same directory as the target to avoid EXDEV on Linux
67+
// (rename() fails across filesystem boundaries, e.g. /tmp vs ~/.mcpc)
68+
const tempFile = join(getMcpcHome(), `.profiles-${Date.now()}-${process.pid}.tmp`);
6869

6970
try {
7071
const content = JSON.stringify(storage, null, 2);

src/lib/sessions.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

77
import { readFile, writeFile, rename, unlink } from 'fs/promises';
8-
import { tmpdir } from 'os';
98
import { join } from 'path';
109
import type { SessionData, SessionsStorage } from './types.js';
1110
import {
@@ -62,7 +61,9 @@ async function saveSessionsInternal(storage: SessionsStorage): Promise<void> {
6261
await ensureDir(getMcpcHome());
6362

6463
// Write to a temp file first (atomic operation)
65-
const tempFile = join(tmpdir(), `mcpc-sessions-${Date.now()}-${process.pid}.json`);
64+
// Write temp file in the same directory as the target to avoid EXDEV on Linux
65+
// (rename() fails across filesystem boundaries, e.g. /tmp vs ~/.mcpc)
66+
const tempFile = join(getMcpcHome(), `.sessions-${Date.now()}-${process.pid}.tmp`);
6667

6768
try {
6869
const content = JSON.stringify(storage, null, 2);

0 commit comments

Comments
 (0)