From 1038082aaaab22fcb552d60e0e40589ec49b2c11 Mon Sep 17 00:00:00 2001 From: oxalica Date: Thu, 31 Aug 2023 17:27:19 +0800 Subject: [PATCH] Allow watching workspaces at /tmp/some-dir (#4632) * fix(watchman): allow watching workspaces at /tmp/some-dir Fixes #4616 * Fix test of fileSystemWatcher.test.ts --------- Co-authored-by: Qiming zhao --- src/__tests__/core/fileSystemWatcher.test.ts | 5 +++-- src/core/watchman.ts | 6 ++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/__tests__/core/fileSystemWatcher.test.ts b/src/__tests__/core/fileSystemWatcher.test.ts index 988d7ba2b3a..b209897ffe0 100644 --- a/src/__tests__/core/fileSystemWatcher.test.ts +++ b/src/__tests__/core/fileSystemWatcher.test.ts @@ -246,8 +246,9 @@ describe('isValidWatchRoot()', () => { it('should check valid root', async () => { expect(isValidWatchRoot('/')).toBe(false) expect(isValidWatchRoot(os.homedir())).toBe(false) - expect(isValidWatchRoot('/tmp/a/b/c')).toBe(false) expect(isValidWatchRoot(os.tmpdir())).toBe(false) + expect(isValidWatchRoot('/tmp/a')).toBe(true) + expect(isValidWatchRoot('/tmp/a/b/c')).toBe(true) }) }) @@ -307,7 +308,7 @@ describe('fileSystemWatcher', () => { it('should use relative pattern #3', async () => { let called = false - let root = path.join(os.tmpdir(), 'not_exists') + let root = path.join(process.cwd(), 'not_exists') let pattern = new RelativePattern(root, '**/*') let watcher = createWatcher(pattern, false, true, true) watcher.onDidCreate(() => { diff --git a/src/core/watchman.ts b/src/core/watchman.ts index 1a9f1eb0cda..6eac0e925ec 100644 --- a/src/core/watchman.ts +++ b/src/core/watchman.ts @@ -171,13 +171,11 @@ export default class Watchman { } /** - * Exclude user's home, driver, tmpdir + * Exclude root, user's home, driver and tmpdir, but allow sub-directories under them. */ export function isValidWatchRoot(root: string): boolean { - if (root == '/' || root == '/tmp' || root == '/private/tmp') return false + if (root == '/' || root == '/tmp' || root == '/private/tmp' || root == os.tmpdir()) return false if (isParentFolder(root, os.homedir(), true)) return false if (path.parse(root).base == root) return false - if (root.startsWith('/tmp/') || root.startsWith('/private/tmp/')) return false - if (isParentFolder(os.tmpdir(), root, true)) return false return true }