From 350818f6c72063060354d1f8bec490842c7a8955 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Fri, 12 Aug 2016 07:05:41 +0200 Subject: [PATCH] Failed to save 'thefilename': A system error occured (ENOTSUP: operation not supported on socket, fdatasync) (fixes #10408) --- src/vs/base/node/extfs.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/vs/base/node/extfs.ts b/src/vs/base/node/extfs.ts index 623afce3aa9..2158db2564f 100644 --- a/src/vs/base/node/extfs.ts +++ b/src/vs/base/node/extfs.ts @@ -319,7 +319,12 @@ export function mv(source: string, target: string, callback: (error: Error) => v // not in some cache. // // See https://github.com/nodejs/node/blob/v5.10.0/lib/fs.js#L1194 +let canFlush = true; export function writeFileAndFlush(path: string, data: string | NodeBuffer, options: { encoding?: string; mode?: number; flag?: string; }, callback: (error: Error) => void): void { + if (!canFlush) { + return fs.writeFile(path, data, options, callback); + } + if (!options) { options = { encoding: 'utf8', mode: 0o666, flag: 'w' }; } else if (typeof options === 'string') { @@ -340,7 +345,15 @@ export function writeFileAndFlush(path: string, data: string | NodeBuffer, optio // Flush contents (not metadata) of the file to disk fs.fdatasync(fd, (syncError) => { - return fs.close(fd, (closeError) => callback(syncError || closeError)); // make sure to carry over the fdatasync error if any! + + // In some exotic setups it is well possible that node fails to sync + // In that case we disable flushing and warn to the console + if (syncError) { + console.warn('[node.js fs] fdatasync is now disabled for this session because it failed: ', syncError); + canFlush = false; + } + + return fs.close(fd, (closeError) => callback(closeError)); }); }); }); -- GitLab