2014-01-21 21:25:09 +00:00
|
|
|
define(["Filer", "util"], function(Filer, util) {
|
2013-11-27 17:18:09 +00:00
|
|
|
|
|
|
|
describe('fs.link', function() {
|
2014-01-21 21:25:09 +00:00
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
2013-11-27 17:18:09 +00:00
|
|
|
|
|
|
|
it('should be a function', function() {
|
2014-01-21 21:25:09 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
expect(fs.link).to.be.a('function');
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
it('should create a link to an existing file', function(done) {
|
|
|
|
var fs = util.fs();
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.open('/myfile', 'w+', function(error, fd) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.close(fd, function(error) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.link('/myfile', '/myotherfile', function(error) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.stat('/myfile', function(error, result) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
var _oldstats = result;
|
|
|
|
fs.stat('/myotherfile', function(error, result) {
|
|
|
|
expect(error).not.to.exist;
|
|
|
|
expect(result.nlinks).to.equal(2);
|
|
|
|
expect(result).to.deep.equal(_oldstats);
|
|
|
|
done();
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
it('should not follow symbolic links', function(done) {
|
|
|
|
var fs = util.fs();
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.stat('/', function (error, result) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if (error) throw error;
|
2014-01-21 21:25:09 +00:00
|
|
|
var _oldstats = result;
|
|
|
|
fs.symlink('/', '/myfileLink', function (error) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if (error) throw error;
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.link('/myfileLink', '/myotherfile', function (error) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if (error) throw error;
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.lstat('/myfileLink', function (error, result) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if (error) throw error;
|
2014-01-21 21:25:09 +00:00
|
|
|
var _linkstats = result;
|
|
|
|
fs.lstat('/myotherfile', function (error, result) {
|
|
|
|
expect(error).not.to.exist;
|
|
|
|
expect(result).to.deep.equal(_linkstats);
|
|
|
|
expect(result.nlinks).to.equal(2);
|
|
|
|
done();
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|