Skip to content

Commit c2fcd96

Browse files
author
Benjamin Pasero
committed
💄
1 parent cc9d8fc commit c2fcd96

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/vs/workbench/services/files/node/fileService.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,17 +348,21 @@ export class FileService implements IFileService {
348348

349349
// 3.) check to add UTF BOM
350350
return addBomPromise.then(addBom => {
351+
351352
// 4.) set contents and resolve
352353
return this.doSetContentsAndResolve(resource, absolutePath, value, addBom, encodingToWrite, { mode: 0o666, flag: 'w' }).then(undefined, error => {
353-
// Can't use 'w' for hidden files on Windows (see https://github.com/Microsoft/vscode/issues/931)
354354
if (!exists || error.code !== 'EPERM' || !isWindows) {
355355
return TPromise.wrapError(error);
356356
}
357357

358-
// 'r+' always works for existing files, but we need to truncate manually
358+
// On Windows and if the file exists with an EPERM error, we try a different strategy of saving the file
359+
// by first truncating the file and then writing with r+ mode. This helps to save hidden files on Windows
360+
// (see https://github.com/Microsoft/vscode/issues/931)
361+
359362
// 5.) truncate
360363
return pfs.truncate(absolutePath, 0).then(() => {
361-
// 6.) set contents and resolve again
364+
365+
// 6.) set contents (this time with r+ mode) and resolve again
362366
return this.doSetContentsAndResolve(resource, absolutePath, value, addBom, encodingToWrite, { mode: 0o666, flag: 'r+' });
363367
});
364368
});

0 commit comments

Comments
 (0)