Skip to content

Commit ffc8110

Browse files
committed
Workaround: A/V software prevents folder rename
1 parent 3ebbdc6 commit ffc8110

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

deps/npm/lib/utils/tar.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ function unpack_ ( tarball, unpackTarget, dMode, fMode, uid, gid, cb ) {
144144
rm(unpackTarget, function (er) {
145145
if (er) return cb(er)
146146
log.verbose(unpackTarget, "rm'ed")
147-
fs.rename(folder, unpackTarget, function (er) {
147+
148+
moveIntoPlace(folder, unpackTarget, function (er) {
148149
if (er) return cb(er)
149150
log.verbose([folder, unpackTarget], "renamed")
150151
// curse you, nfs! It will lie and tell you that the
@@ -161,6 +162,24 @@ function unpack_ ( tarball, unpackTarget, dMode, fMode, uid, gid, cb ) {
161162
})
162163
}
163164

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+
164183
function gunzTarPerm (tarball, tmp, dMode, fMode, uid, gid, cb) {
165184
if (!dMode) dMode = npm.modes.exec
166185
if (!fMode) fMode = npm.modes.file

0 commit comments

Comments
 (0)