Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 87 - Added fs.fsync() as a no-op, and added tests. Modified docume... #176

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/filesystem/implementation.js
Expand Up @@ -1528,6 +1528,15 @@ define(function(require) {
unlink_node(context, path, standard_check_result_cb(callback));
}

function fsync(fs, context, fd, callback) {
var ofd = fs.openFiles[fd];
if(!ofd) {
callback(new Errors.EBADF());
} else {
callback();
}
}

function read(fs, context, fd, buffer, offset, length, position, callback) {
// Follow how node.js does this
function wrapped_cb(err, bytesRead) {
Expand Down Expand Up @@ -1898,6 +1907,7 @@ define(function(require) {
stat: stat,
fstat: fstat,
link: link,
fsync: fsync,
read: read,
readFile: readFile,
write: write,
Expand Down
1 change: 1 addition & 0 deletions src/filesystem/interface.js
Expand Up @@ -222,6 +222,7 @@ define(function(require) {
'fstat',
'link',
'unlink',
'fsync',
'read',
'readFile',
'write',
Expand Down
33 changes: 33 additions & 0 deletions tests/spec/fs.fsync.spec.js
@@ -0,0 +1,33 @@
define(["Filer", "util"], function(Filer, util) {

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 invalid', function() {
var fs = util.fs();
fs.fsync(1, function(error){
expect(error).to.exist;
});
});

it('should not error if the fd is valid', function(done) {
var fs = util.fs();
fs.writeFile('/myfile', 'the 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;
done();
});
});
});
});
});
});
1 change: 1 addition & 0 deletions tests/test-manifest.js
Expand Up @@ -17,6 +17,7 @@ define([
"spec/fs.readdir.spec",
"spec/fs.rmdir.spec",
"spec/fs.open.spec",
"spec/fs.fsync.spec",
"spec/fs.write.spec",
"spec/fs.writeFile-readFile.spec",
"spec/fs.appendFile.spec",
Expand Down