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

Allow watching workspaces at /tmp/some-dir #4632

Merged
merged 2 commits into from
Aug 31, 2023
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
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
}
Loading