Skip to content

Commit

Permalink
🐛 Enable usePolling on Windows to fix file-lock (#1523)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAfroOfDoom committed Jul 30, 2024
1 parent cfa7321 commit db02249
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
3 changes: 2 additions & 1 deletion docs/user/config.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ There's no support for multiple config files or inheriting/overriding config fil
"language": "Default",
"permissionLevel": 2,
"plugins": [],
"mcmetaSummaryOverrides": {}
"mcmetaSummaryOverrides": {},
useFilePolling: false
},
"format": {
"blockStateBracketSpacing": { "inside": 0 },
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/common/externals/NodeJsExternals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@ export const NodeJsExternals: Externals = {
unlink(location) {
return fsp.unlink(toFsPathLike(location))
},
watch(locations) {
return new ChokidarWatcherWrapper(chokidar.watch(locations.map(toPath)))
watch(locations, { usePolling = false } = {}) {
return new ChokidarWatcherWrapper(
chokidar.watch(locations.map(toPath), { usePolling }),
)
},
writeFile(location, data, options) {
return fsp.writeFile(toFsPathLike(location), data, options)
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/common/externals/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export interface ExternalFileSystem {
showFile(path: FsLocation): Promise<void>
stat(location: FsLocation): Promise<{ isDirectory(): boolean; isFile(): boolean }>
unlink(location: FsLocation): Promise<void>
watch(locations: FsLocation[]): FsWatcher
watch(locations: FsLocation[], options: { usePolling?: boolean }): FsWatcher
/**
* @param options `mode` - File mode bit mask (e.g. `0o775`).
*/
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/service/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ export interface EnvConfig {
>
permissionLevel: 1 | 2 | 3 | 4
plugins: string[]
/**
* Makes the file-watcher use polling to watch for file changes.
* Comes at a performance cost for very large datapacks.
*
* On Windows, enabling this can fix file-lock issues when Spyglass is running.
* See: https://github.com/SpyglassMC/Spyglass/issues/1414
*
* **You should only consider enabling this for Windows machines.**
*/
useFilePolling: boolean
}

export type LinterSeverity = 'hint' | 'information' | 'warning' | 'error'
Expand Down Expand Up @@ -352,6 +362,7 @@ export const VanillaConfig: Config = {
permissionLevel: 2,
plugins: [],
mcmetaSummaryOverrides: {},
useFilePolling: false,
},
format: {
blockStateBracketSpacing: { inside: 0 },
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/service/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,9 @@ export class Project implements ExternalEventEmitter {
}
this.#watchedFiles.clear()
this.#watcherReady = false
this.#watcher = this.externals.fs.watch(this.projectRoots).once('ready', () => {
this.#watcher = this.externals.fs.watch(this.projectRoots, {
usePolling: this.config.env.useFilePolling,
}).once('ready', () => {
this.#watcherReady = true
resolve()
}).on('add', (uri) => {
Expand Down

0 comments on commit db02249

Please sign in to comment.