diff --git a/src/filesystem/implementation.js b/src/filesystem/implementation.js index 794760f..c1f5b3e 100644 --- a/src/filesystem/implementation.js +++ b/src/filesystem/implementation.js @@ -1662,7 +1662,7 @@ function fstat(fs, context, fd, callback) { if(error) { callback(error); } else { - var stats = new Stats(fd.path, result, fs.name); + var stats = new Stats(ofd.path, result, fs.name); callback(null, stats); } } diff --git a/tests/spec/fs.stats.spec.js b/tests/spec/fs.stats.spec.js index 6094e98..b2fc77c 100644 --- a/tests/spec/fs.stats.spec.js +++ b/tests/spec/fs.stats.spec.js @@ -1,4 +1,5 @@ var Filer = require('../..'); +var Path = Filer.Path; var util = require('../lib/test-utils.js'); var expect = require('chai').expect; @@ -256,4 +257,41 @@ describe('fs.stats', function() { }); }); }); + + describe('generated name property', function() { + beforeEach(util.setup); + afterEach(util.cleanup); + + it('should correct return name for a file', function(done) { + var fs = util.fs(); + var filepath = '/a'; + + fs.writeFile(filepath, 'data', function(err) { + if(err) throw err; + + fs.stat(filepath, function(err, stats) { + if(err) throw err; + + expect(stats.name).to.equal(Path.basename(filepath)); + done(); + }); + }) + }); + + it('should correct return name for an fd', function(done) { + var fs = util.fs(); + var filepath = '/a'; + + fs.open(filepath, 'w', function(err, fd) { + if(err) throw err; + + fs.fstat(fd, function(err, stats) { + if(err) throw err; + + expect(stats.name).to.equal(Path.basename(filepath)); + done(); + }); + }) + }); + }) });