From 96f8d4b28c47e6833a057e1bcce41ceb5e54ca45 Mon Sep 17 00:00:00 2001 From: Peter van der Zee <209817+pvdz@users.noreply.github.com> Date: Sat, 11 Apr 2020 14:33:10 +0200 Subject: [PATCH] fix(gatsby): Use `moveSync` over `renameSync` to fix cross mount cases (#23029) --- packages/gatsby/src/redux/__tests__/index.js | 2 +- packages/gatsby/src/redux/persist.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/gatsby/src/redux/__tests__/index.js b/packages/gatsby/src/redux/__tests__/index.js index e90eb1742765f..addc4d52aaf4f 100644 --- a/packages/gatsby/src/redux/__tests__/index.js +++ b/packages/gatsby/src/redux/__tests__/index.js @@ -16,7 +16,7 @@ jest.mock(`fs-extra`, () => { mockWrittenContent.set(file, content) ), readFileSync: jest.fn(file => mockWrittenContent.get(file)), - renameSync: jest.fn((from, to) => { + moveSync: jest.fn((from, to) => { // This will only work for folders if they are always the full prefix // of the file... (that goes for both input dirs). That's the case here. if (mockWrittenContent.has(to)) { diff --git a/packages/gatsby/src/redux/persist.ts b/packages/gatsby/src/redux/persist.ts index c7a5d45bb8a37..68a049a0b7fdb 100644 --- a/packages/gatsby/src/redux/persist.ts +++ b/packages/gatsby/src/redux/persist.ts @@ -4,9 +4,9 @@ import v8 from "v8" import { existsSync, mkdtempSync, + moveSync, // Note: moveSync over renameSync because /tmp may be on other mount readFileSync, removeSync, - renameSync, writeFileSync, } from "fs-extra" import { IGatsbyNode, ICachedReduxState } from "./types" @@ -131,7 +131,7 @@ function safelyRenameToBak(reduxCacheFolder: string): string { ++suffixCounter bakName = reduxCacheFolder + tmpSuffix + suffixCounter } - renameSync(reduxCacheFolder, bakName) + moveSync(reduxCacheFolder, bakName) return bakName } @@ -157,7 +157,7 @@ export function writeToCache(contents: ICachedReduxState): void { } // The redux cache folder should now not exist so we can rename our tmp to it - renameSync(tmpDir, reduxCacheFolder) + moveSync(tmpDir, reduxCacheFolder) // Now try to yolorimraf the old cache folder try {