Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions graceful-fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,21 @@ function patch (fs) {
}
}

var fs$copyFile = fs.copyFile
if (fs$copyFile)
fs.copyFile = copyFile
function copyFile (src, dest, cb) {
return fs$copyFile(src, dest, function (err) {
if (err && (err.code === 'EMFILE' || err.code === 'ENFILE'))
enqueue([fs$copyFile, [src, dest, cb]])
else {
if (typeof cb === 'function')
cb.apply(this, arguments)
retry()
}
})
}

var fs$readdir = fs.readdir
fs.readdir = readdir
function readdir (path, options, cb) {
Expand Down
27 changes: 21 additions & 6 deletions test/write-then-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,32 @@ test('make files', function (t) {
t.end();
})

test('read files', function (t) {
// now read them
t.plan(num)
test('copy files', function (t) {
for (var i = 0; i < num; ++i) {
fs.readFile(paths[i], 'ascii', function(err, data) {
paths[i] = 'files/file-' + i;
fs.copyFile(paths[i], paths[i] + '.copy', function(err) {
if (err)
throw err;

t.equal(data, 'content')
});
}

t.end();
})

test('read files', function (t) {
function expectContent(err, data) {
if (err)
throw err;

t.equal(data, 'content')
}

// now read them
t.plan(num * 2)
for (var i = 0; i < num; ++i) {
fs.readFile(paths[i], 'ascii', expectContent);
fs.readFile(paths[i] + '.copy', 'ascii', expectContent);
}
});

test('cleanup', function (t) {
Expand Down