Merge pull request #9382 from Microsoft/tyriar/8547_support_symlink_settings
Follow and watch settings.json single-level symlinks
This commit is contained in:
commit
4d5810c720
1 changed files with 30 additions and 3 deletions
|
@ -90,11 +90,38 @@ export class UserSettings {
|
||||||
}
|
}
|
||||||
|
|
||||||
private registerWatchers(): void {
|
private registerWatchers(): void {
|
||||||
this.watcher = fs.watch(path.dirname(this.appSettingsPath));
|
let self = this;
|
||||||
this.watcher.on('change', (eventType: string, fileName: string) => this.onSettingsFileChange(eventType, fileName));
|
function attachSettingsChangeWatcher(watchPath: string): void {
|
||||||
|
self.watcher = fs.watch(watchPath);
|
||||||
|
self.watcher.on('change', () => self.onSettingsFileChange());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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() && !stats.isDirectory()) {
|
||||||
|
fs.readlink(path, function(err, realPath) {
|
||||||
|
if (err) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
attachSettingsChangeWatcher(realPath);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private onSettingsFileChange(eventType: string, fileName: string): void {
|
private onSettingsFileChange(): void {
|
||||||
|
|
||||||
// we can get multiple change events for one change, so we buffer through a timeout
|
// we can get multiple change events for one change, so we buffer through a timeout
|
||||||
if (this.timeoutHandle) {
|
if (this.timeoutHandle) {
|
||||||
|
|
Loading…
Reference in a new issue