Issue 87 - Added fs.fsync() as a no-op, and added tests. Modified documentation.
Made requested changes to tests, functionality; reverted doc changes
This commit is contained in:
parent
a107fe21d7
commit
6a5d9073f3
|
@ -1761,6 +1761,16 @@ function read(fs, context, fd, buffer, offset, length, position, callback) {
|
|||
}
|
||||
}
|
||||
|
||||
function fsync(fs, context, fd, callback) {
|
||||
if(validateInteger(fd, callback) !== fd) return;
|
||||
var ofd = fs.openFiles[fd];
|
||||
if(!ofd) {
|
||||
callback(new Errors.EBADF());
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
function readFile(fs, context, path, options, callback) {
|
||||
callback = arguments[arguments.length - 1];
|
||||
options = validate_file_options(options, null, 'r');
|
||||
|
@ -2413,6 +2423,7 @@ module.exports = {
|
|||
stat: stat,
|
||||
fstat: fstat,
|
||||
link: link,
|
||||
fsync: fsync,
|
||||
read: read,
|
||||
readFile: readFile,
|
||||
write: write,
|
||||
|
|
|
@ -282,6 +282,7 @@ function FileSystem(options, callback) {
|
|||
{ name: 'rmdir', promises: true },
|
||||
{ name: 'stat', promises: true },
|
||||
{ name: 'fstat' },
|
||||
{ name: 'fsync' },
|
||||
{ name: 'link', promises: true },
|
||||
{ name: 'unlink', promises: true },
|
||||
{ name: 'read' },
|
||||
|
|
|
@ -24,6 +24,7 @@ require('./spec/fs.writeFile-readFile.spec');
|
|||
require('./spec/fs.appendFile.spec');
|
||||
require('./spec/fs.read.spec');
|
||||
require('./spec/fs.close.spec');
|
||||
require('./spec/fs.fsync.spec');
|
||||
require('./spec/fs.link.spec');
|
||||
require('./spec/fs.unlink.spec');
|
||||
require('./spec/fs.rename.spec');
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
var util = require('../lib/test-utils.js');
|
||||
var expect = require('chai').expect;
|
||||
|
||||
describe('fs.fsync', function() {
|
||||
beforeEach(util.setup);
|
||||
afterEach(util.cleanup);
|
||||
|
||||
it('should be a function', function() {
|
||||
var fs = util.fs();
|
||||
expect(fs.fsync).to.be.a('function');
|
||||
});
|
||||
|
||||
it('should return error when fd is not a number', function(done) {
|
||||
var fs = util.fs();
|
||||
fs.fsync('1', function(error) {
|
||||
expect(error).to.exist;
|
||||
expect(error.code).to.equal('EINVAL');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return error when fd is invalid', function(done) {
|
||||
var fs = util.fs();
|
||||
fs.fsync(1, function(error) {
|
||||
expect(error).to.exist;
|
||||
expect(error.code).to.equal('EBADF');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should not error if the fd is valid', function(done) {
|
||||
var fs = util.fs();
|
||||
|
||||
fs.writeFile('/myfile', 'contents', function(error) {
|
||||
if(error) throw error;
|
||||
|
||||
fs.open('/myfile', 'r', function(error, fd) {
|
||||
if(error) throw error;
|
||||
|
||||
fs.fsync(fd, function(error) {
|
||||
expect(error).to.not.exist;
|
||||
fs.close(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue