Skip to content

Commit

Permalink
fix(gatsby): fix eperm when cache getting cleared (#35154)
Browse files Browse the repository at this point in the history
  • Loading branch information
wardpeet authored Mar 22, 2022
1 parent ae999cf commit 6684c60
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 35 deletions.
2 changes: 1 addition & 1 deletion packages/gatsby/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
"date-fns": "^2.25.0",
"debug": "^3.2.7",
"deepmerge": "^4.2.2",
"del": "^5.1.0",
"detect-port": "^1.3.0",
"devcert": "^1.2.0",
"dotenv": "^8.6.0",
Expand Down Expand Up @@ -93,6 +92,7 @@
"gatsby-telemetry": "^3.11.0-next.1",
"gatsby-worker": "^1.11.0-next.0",
"glob": "^7.2.0",
"globby": "^11.1.0",
"got": "^11.8.2",
"graphql": "^15.7.2",
"graphql-compose": "^9.0.7",
Expand Down
44 changes: 26 additions & 18 deletions packages/gatsby/src/services/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import * as fs from "fs-extra"
import { releaseAllMutexes } from "gatsby-core-utils/mutex"
import md5File from "md5-file"
import crypto from "crypto"
import del from "del"
import path from "path"
import telemetry from "gatsby-telemetry"
import glob from "globby"

import apiRunnerNode from "../utils/api-runner-node"
import { getBrowsersList } from "../utils/browserslist"
Expand Down Expand Up @@ -284,12 +284,18 @@ export async function initialize({
}
)
activity.start()
await del([
`public/**/*.{html,css}`,
`!public/page-data/**/*`,
`!public/static`,
`!public/static/**/*.{html,css}`,
])
const files = await glob(
[
`public/**/*.{html,css}`,
`!public/page-data/**/*`,
`!public/static`,
`!public/static/**/*.{html,css}`,
],
{
cwd: program.directory,
}
)
await Promise.all(files.map(file => fs.remove(file)))
activity.end()
}

Expand Down Expand Up @@ -429,28 +435,30 @@ export async function initialize({

const deleteGlobs = [
// By default delete all files & subdirectories
`${cacheDirectory}/**`,
`!${cacheDirectory}/data`,
`${cacheDirectory}/data/**`,
`!${cacheDirectory}/data/gatsby-core-utils/`,
`!${cacheDirectory}/data/gatsby-core-utils/**`,
`!${cacheDirectory}/compiled`,
`.cache/**`,
`.cache/data/**`,
`!.cache/data/gatsby-core-utils/**`,
`!.cache/compiled`,
]

if (process.env.GATSBY_EXPERIMENTAL_PRESERVE_FILE_DOWNLOAD_CACHE) {
// Stop the caches directory from being deleted, add all sub directories,
// but remove gatsby-source-filesystem
deleteGlobs.push(`!${cacheDirectory}/caches`)
deleteGlobs.push(`${cacheDirectory}/caches/*`)
deleteGlobs.push(`!${cacheDirectory}/caches/gatsby-source-filesystem`)
deleteGlobs.push(`!.cache/caches`)
deleteGlobs.push(`.cache/caches/*`)
deleteGlobs.push(`!.cache/caches/gatsby-source-filesystem`)
}

if (process.env.GATSBY_EXPERIMENTAL_PRESERVE_WEBPACK_CACHE) {
// Add webpack
deleteGlobs.push(`!${cacheDirectory}/webpack`)
deleteGlobs.push(`!.cache/webpack`)
}

await del(deleteGlobs)
const files = await glob(deleteGlobs, {
cwd: program.directory,
})

await Promise.all(files.map(file => fs.remove(file)))
} catch (e) {
reporter.error(`Failed to remove .cache files.`, e)
}
Expand Down
32 changes: 16 additions & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10579,7 +10579,7 @@ fast-glob@^2.2.6:
merge2 "^1.2.3"
micromatch "^3.1.10"

fast-glob@^3.0.3, fast-glob@^3.1.1, fast-glob@^3.2.11, fast-glob@^3.2.4:
fast-glob@^3.0.3, fast-glob@^3.1.1, fast-glob@^3.2.11, fast-glob@^3.2.4, fast-glob@^3.2.9:
version "3.2.11"
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.11.tgz#a1172ad95ceb8a16e20caa5c5e56480e5129c1d9"
integrity sha512-xrO3+1bxSo3ZVHAnqzyuewYT6aMFHRAd4Kcs92MAonjwQZLsK9d0SF1IyQ3k5PoirxTW0Oe/RqFgMQ6TcNE5Ew==
Expand Down Expand Up @@ -11677,16 +11677,16 @@ globby@^10.0.1:
merge2 "^1.2.3"
slash "^3.0.0"

globby@^11.0.1, globby@^11.0.3, globby@^11.0.4:
version "11.0.4"
resolved "https://registry.yarnpkg.com/globby/-/globby-11.0.4.tgz#2cbaff77c2f2a62e71e9b2813a67b97a3a3001a5"
integrity sha512-9O4MVG9ioZJ08ffbcyVYyLOJLk5JQ688pJ4eMGLpdWLHq/Wr1D9BlriLQyL0E+jbkuePVZXYFj47QM/v093wHg==
globby@^11.0.1, globby@^11.0.3, globby@^11.0.4, globby@^11.1.0:
version "11.1.0"
resolved "https://registry.yarnpkg.com/globby/-/globby-11.1.0.tgz#bd4be98bb042f83d796f7e3811991fbe82a0d34b"
integrity sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==
dependencies:
array-union "^2.1.0"
dir-glob "^3.0.1"
fast-glob "^3.1.1"
ignore "^5.1.4"
merge2 "^1.3.0"
fast-glob "^3.2.9"
ignore "^5.2.0"
merge2 "^1.4.1"
slash "^3.0.0"

globby@^6.1.0:
Expand Down Expand Up @@ -12718,10 +12718,10 @@ ignore@^4.0.3, ignore@^4.0.6:
version "4.0.6"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-4.0.6.tgz#750e3db5862087b4737ebac8207ffd1ef27b25fc"

ignore@^5.0.0, ignore@^5.1.1, ignore@^5.1.4, ignore@^5.1.8:
version "5.1.8"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.1.8.tgz#f150a8b50a34289b33e22f5889abd4d8016f0e57"
integrity sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw==
ignore@^5.0.0, ignore@^5.1.1, ignore@^5.1.4, ignore@^5.1.8, ignore@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.2.0.tgz#6d3bac8fa7fe0d45d9f9be7bac2fc279577e345a"
integrity sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==

image-q@^1.1.1:
version "1.1.1"
Expand Down Expand Up @@ -16152,10 +16152,10 @@ merge-stream@^2.0.0:
resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60"
integrity sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==

merge2@^1.2.3, merge2@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.3.0.tgz#5b366ee83b2f1582c48f87e47cf1a9352103ca81"
integrity sha512-2j4DAdlBOkiSZIsaXk4mTE3sRS02yBHAtfy127xRV3bQUFqXkjHCHLW6Scv7DwNRbIWNHH8zpnz9zMaKXIdvYw==
merge2@^1.2.3, merge2@^1.3.0, merge2@^1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.4.1.tgz#4368892f885e907455a6fd7dc55c0c9d404990ae"
integrity sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==

meros@^1.1.2:
version "1.1.4"
Expand Down

0 comments on commit 6684c60

Please sign in to comment.