From 5d610028e43f49ebbf5c96c35ca9cf4c9e5c5332 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Tue, 9 Aug 2016 12:35:23 -0700 Subject: [PATCH] Watch directory and watch resolved symlinks if they exist --- src/vs/base/node/userSettings.ts | 38 ++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/vs/base/node/userSettings.ts b/src/vs/base/node/userSettings.ts index 6cf667958af..24a38a7660a 100644 --- a/src/vs/base/node/userSettings.ts +++ b/src/vs/base/node/userSettings.ts @@ -96,22 +96,28 @@ export class UserSettings { self.watcher.on('change', (eventType: string, fileName: string) => self.onSettingsFileChange(eventType, fileName)); } - let settingsDir = path.dirname(this.appSettingsPath); - let settingsPath = path.join(settingsDir, 'settings.json'); - fs.lstat(settingsPath, function(err, stats) { - if (err) { - // Attach to the directory if the file doesn't exist - attachSettingsChangeWatcher(settingsDir); - } else if (stats.isSymbolicLink()) { - fs.readlink(self.appSettingsPath, function(err, realPath) { - if (err) { - attachSettingsChangeWatcher(self.appSettingsPath); - } - attachSettingsChangeWatcher(realPath); - }); - } else { - attachSettingsChangeWatcher(self.appSettingsPath); - } + // Attach a watcher to the settings directory + attachSettingsChangeWatcher(path.dirname(this.appSettingsPath)); + + // Follow symlinks for settings and keybindings and attach watchers if they resolve + let followSymlinkPaths = [ + this.appSettingsPath, + this.appKeybindingsPath + ]; + followSymlinkPaths.forEach((path) => { + fs.lstat(path, function(err, stats) { + if (err) { + return; + } + if (stats.isSymbolicLink()) { + fs.readlink(path, function(err, realPath) { + if (err) { + return; + } + attachSettingsChangeWatcher(realPath); + }); + } + }); }); } -- GitLab