1 | "use strict";
|
2 |
|
3 | const fs = require('fs');
|
4 | const promisify = require('../function/promisify');
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | let rename = fs.rename;
|
13 |
|
14 |
|
15 | if(process.platform === "win32") {
|
16 |
|
17 | rename = function(from, to, cb) {
|
18 |
|
19 | var start = Date.now();
|
20 | var backoff = 0;
|
21 |
|
22 | fs.rename(from, to, function CB(err) {
|
23 |
|
24 | if(err
|
25 | && (err.code === "EACCES" || err.code === "EPERM")
|
26 | && Date.now() - start < 60 * 1000) {
|
27 |
|
28 | setTimeout(function() {
|
29 | fs.rename(from, to, CB);
|
30 | }, backoff);
|
31 |
|
32 | if(backoff < 100)
|
33 | backoff += 10;
|
34 | return;
|
35 | }
|
36 | if(cb)
|
37 | cb(err);
|
38 | });
|
39 | };
|
40 |
|
41 | }
|
42 |
|
43 | module.exports = promisify(rename);
|