@@ -1927,16 +1927,28 @@ class TextBuffer {
19271927 try {
19281928 await this . buffer . save ( destination , this . getEncoding ( ) )
19291929 } catch ( error ) {
1930- const canEscalate = process . platform === 'darwin' || process . platform === 'linux'
1931- if ( error . code === 'EACCES' && destination === filePath && canEscalate ) {
1930+ if ( error . code !== 'EACCES' || destination !== filePath ) throw error
1931+
1932+ const isWindows = process . platform === 'win32'
1933+ if ( isWindows ) {
1934+ const winattr = getPromisifiedWinattr ( )
1935+ const attrs = await winattr . get ( filePath )
1936+ if ( ! attrs . hidden ) throw error
1937+
1938+ try {
1939+ await winattr . set ( filePath , { hidden : false } )
1940+ await this . buffer . save ( filePath , this . getEncoding ( ) )
1941+ await winattr . set ( filePath , { hidden : true } )
1942+ } catch ( _ ) {
1943+ throw error
1944+ }
1945+ } else {
19321946 const fsAdmin = require ( 'fs-admin' )
19331947 try {
19341948 await this . buffer . save ( fsAdmin . createWriteStream ( filePath ) , this . getEncoding ( ) )
19351949 } catch ( _ ) {
19361950 throw error
19371951 }
1938- } else {
1939- throw error
19401952 }
19411953 }
19421954 } finally {
@@ -2601,4 +2613,18 @@ class SearchCallbackArgument {
26012613 }
26022614}
26032615
2616+ let _winattr = null
2617+ const getPromisifiedWinattr = function ( ) {
2618+ if ( _winattr === null ) {
2619+ const { promisify } = require ( 'util' )
2620+ const winattr = require ( 'winattr' )
2621+ _winattr = {
2622+ set : promisify ( winattr . set ) ,
2623+ get : promisify ( winattr . get )
2624+ }
2625+ }
2626+
2627+ return _winattr
2628+ }
2629+
26042630module . exports = TextBuffer
0 commit comments