Skip to content

Commit

Permalink
Allow watching workspaces at /tmp/some-dir (#4632)
Browse files Browse the repository at this point in the history
* fix(watchman): allow watching workspaces at /tmp/some-dir

Fixes #4616

* Fix test of fileSystemWatcher.test.ts

---------

Co-authored-by: Qiming zhao <chemzqm@gmail.com>
  • Loading branch information
oxalica and chemzqm committed Aug 31, 2023
1 parent 34f5d96 commit 1038082
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/__tests__/core/fileSystemWatcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})

Expand Down Expand Up @@ -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(() => {
Expand Down
6 changes: 2 additions & 4 deletions src/core/watchman.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 1038082

Please sign in to comment.