@@ -144,7 +144,8 @@ function unpack_ ( tarball, unpackTarget, dMode, fMode, uid, gid, cb ) {
144
144
rm ( unpackTarget , function ( er ) {
145
145
if ( er ) return cb ( er )
146
146
log . verbose ( unpackTarget , "rm'ed" )
147
- fs . rename ( folder , unpackTarget , function ( er ) {
147
+
148
+ moveIntoPlace ( folder , unpackTarget , function ( er ) {
148
149
if ( er ) return cb ( er )
149
150
log . verbose ( [ folder , unpackTarget ] , "renamed" )
150
151
// curse you, nfs! It will lie and tell you that the
@@ -161,6 +162,24 @@ function unpack_ ( tarball, unpackTarget, dMode, fMode, uid, gid, cb ) {
161
162
} )
162
163
}
163
164
165
+ // on Windows, A/V software can lock the directory, causing this
166
+ // to fail with an EACCES. Try again on failure, for up to 1 second.
167
+ // XXX Fix this by not unpacking into a temp directory, instead just
168
+ // renaming things on the way out of the tarball.
169
+ function moveIntoPlace ( folder , unpackTarget , cb ) {
170
+ var start = Date . now ( )
171
+ fs . rename ( folder , unpackTarget , function CB ( er ) {
172
+ if ( er
173
+ && process . platform === "win32"
174
+ && er . code === "EACCES"
175
+ && Date . now ( ) - start < 1000 ) {
176
+ return fs . rename ( folder , unpackTarget , CB )
177
+ }
178
+ cb ( er )
179
+ } )
180
+ }
181
+
182
+
164
183
function gunzTarPerm ( tarball , tmp , dMode , fMode , uid , gid , cb ) {
165
184
if ( ! dMode ) dMode = npm . modes . exec
166
185
if ( ! fMode ) fMode = npm . modes . file
0 commit comments