Skip to content

Commit

Permalink
fix(gatsby): Use moveSync over renameSync to fix cross mount cases (
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdz committed Apr 11, 2020
1 parent 2fcb978 commit 96f8d4b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/gatsby/src/redux/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
6 changes: 3 additions & 3 deletions packages/gatsby/src/redux/persist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -131,7 +131,7 @@ function safelyRenameToBak(reduxCacheFolder: string): string {
++suffixCounter
bakName = reduxCacheFolder + tmpSuffix + suffixCounter
}
renameSync(reduxCacheFolder, bakName)
moveSync(reduxCacheFolder, bakName)

return bakName
}
Expand All @@ -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 {
Expand Down

0 comments on commit 96f8d4b

Please sign in to comment.