Skip to content

Commit

Permalink
Merge pull request #67 from runk/fix-fs-rename-across-devices
Browse files Browse the repository at this point in the history
Fix tmp files mv across physical devices
  • Loading branch information
runk authored Mar 26, 2018
2 parents f4ab221 + cfaec14 commit c59868f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 16 deletions.
10 changes: 6 additions & 4 deletions lib/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ var path = require('path'),
fs = require('fs'),
os = require('os'),
crypto = require('crypto'),
mkdirp = require('mkdirp');
mkdirp = require('mkdirp'),
mv = require('mv');

function Cache(opts) {
this.opts = opts || {};
Expand Down Expand Up @@ -85,9 +86,10 @@ function Cache(opts) {

// Release the lock, move data file to final destination.
delete (locks[key]);
fs.renameSync(tmpPath, pathInfo.full);

self.meta(key, cb);
mv(tmpPath, pathInfo.full, function(err) {
if (err) { return cb(err); }
self.meta(key, cb);
});
});
};

Expand Down
53 changes: 41 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"commander": "^2.15.1",
"log4js": "^0.6.26",
"mkdirp": "^0.5.1",
"mv": "^2.1.1",
"request": "^2.81.0"
},
"description": "HTTP/HTTPS caching proxy for work with `npm` utility / registry",
Expand Down

0 comments on commit c59868f

Please sign in to comment.