@@ -71,13 +71,13 @@ function patch (fs) {
71
71
fs . lstatSync = statFixSync ( fs . lstatSync )
72
72
73
73
// if lchmod/lchown do not exist, then make them no-ops
74
- if ( ! fs . lchmod ) {
74
+ if ( fs . chmod && ! fs . lchmod ) {
75
75
fs . lchmod = function ( path , mode , cb ) {
76
76
if ( cb ) process . nextTick ( cb )
77
77
}
78
78
fs . lchmodSync = function ( ) { }
79
79
}
80
- if ( ! fs . lchown ) {
80
+ if ( fs . chown && ! fs . lchown ) {
81
81
fs . lchown = function ( path , uid , gid , cb ) {
82
82
if ( cb ) process . nextTick ( cb )
83
83
}
@@ -94,32 +94,38 @@ function patch (fs) {
94
94
// CPU to a busy looping process, which can cause the program causing the lock
95
95
// contention to be starved of CPU by node, so the contention doesn't resolve.
96
96
if ( platform === "win32" ) {
97
- fs . rename = ( function ( fs$rename ) { return function ( from , to , cb ) {
98
- var start = Date . now ( )
99
- var backoff = 0 ;
100
- fs$rename ( from , to , function CB ( er ) {
101
- if ( er
102
- && ( er . code === "EACCES" || er . code === "EPERM" )
103
- && Date . now ( ) - start < 60000 ) {
104
- setTimeout ( function ( ) {
105
- fs . stat ( to , function ( stater , st ) {
106
- if ( stater && stater . code === "ENOENT" )
107
- fs$rename ( from , to , CB ) ;
108
- else
109
- cb ( er )
110
- } )
111
- } , backoff )
112
- if ( backoff < 100 )
113
- backoff += 10 ;
114
- return ;
115
- }
116
- if ( cb ) cb ( er )
117
- } )
118
- } } ) ( fs . rename )
97
+ fs . rename = typeof fs . rename !== 'function' ? fs . rename
98
+ : ( function ( fs$rename ) {
99
+ function rename ( from , to , cb ) {
100
+ var start = Date . now ( )
101
+ var backoff = 0 ;
102
+ fs$rename ( from , to , function CB ( er ) {
103
+ if ( er
104
+ && ( er . code === "EACCES" || er . code === "EPERM" )
105
+ && Date . now ( ) - start < 60000 ) {
106
+ setTimeout ( function ( ) {
107
+ fs . stat ( to , function ( stater , st ) {
108
+ if ( stater && stater . code === "ENOENT" )
109
+ fs$rename ( from , to , CB ) ;
110
+ else
111
+ cb ( er )
112
+ } )
113
+ } , backoff )
114
+ if ( backoff < 100 )
115
+ backoff += 10 ;
116
+ return ;
117
+ }
118
+ if ( cb ) cb ( er )
119
+ } )
120
+ }
121
+ if ( Object . setPrototypeOf ) Object . setPrototypeOf ( rename , fs$rename )
122
+ return rename
123
+ } ) ( fs . rename )
119
124
}
120
125
121
126
// if read() returns EAGAIN, then just try it again.
122
- fs . read = ( function ( fs$read ) {
127
+ fs . read = typeof fs . read !== 'function' ? fs . read
128
+ : ( function ( fs$read ) {
123
129
function read ( fd , buffer , offset , length , position , callback_ ) {
124
130
var callback
125
131
if ( callback_ && typeof callback_ === 'function' ) {
@@ -140,7 +146,8 @@ function patch (fs) {
140
146
return read
141
147
} ) ( fs . read )
142
148
143
- fs . readSync = ( function ( fs$readSync ) { return function ( fd , buffer , offset , length , position ) {
149
+ fs . readSync = typeof fs . readSync !== 'function' ? fs . readSync
150
+ : ( function ( fs$readSync ) { return function ( fd , buffer , offset , length , position ) {
144
151
var eagCounter = 0
145
152
while ( true ) {
146
153
try {
@@ -199,7 +206,7 @@ function patch (fs) {
199
206
}
200
207
201
208
function patchLutimes ( fs ) {
202
- if ( constants . hasOwnProperty ( "O_SYMLINK" ) ) {
209
+ if ( constants . hasOwnProperty ( "O_SYMLINK" ) && fs . futimes ) {
203
210
fs . lutimes = function ( path , at , mt , cb ) {
204
211
fs . open ( path , constants . O_SYMLINK , function ( er , fd ) {
205
212
if ( er ) {
@@ -233,7 +240,7 @@ function patch (fs) {
233
240
return ret
234
241
}
235
242
236
- } else {
243
+ } else if ( fs . futimes ) {
237
244
fs . lutimes = function ( _a , _b , _c , cb ) { if ( cb ) process . nextTick ( cb ) }
238
245
fs . lutimesSync = function ( ) { }
239
246
}
0 commit comments