Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gatsby): Use moveSync over renameSync to fix cross mount cases #23029

Merged
merged 1 commit into from
Apr 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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