fixed bugs where atime and mtime weren't updated on the node and where mtime was valid it would error. Also added more tests

This commit is contained in:
Barry Tulchinsky 2013-12-15 02:54:51 -05:00
parent d5b5c55fe1
commit e84d639210
2 changed files with 149 additions and 7 deletions

View File

@ -1038,24 +1038,34 @@ define(function(require) {
path = normalize(path); path = normalize(path);
function update_times (error, node) { function update_times (error, node) {
//Note: Going by node.js' implementation, utimes works on directories
if (error) { if (error) {
callback(error); callback(error);
} }
else { else {
console.log(node);
node.atime = atime; node.atime = atime;
node.mtime = mtime; node.mtime = mtime;
console.log('updated times atime=' + node.atime + 'and mtime=' + node.mtime);
_stat (context, 'test', path, function (error, stat) {
if (error) console.log('error');
else console.log(stat);
});
// callback(null);
context.put(node.id, node, callback);
} }
} }
//check if atime and mtime are integers and >= 0 //check if atime and mtime are integers and >= 0
if (typeof atime != 'number' || typeof mtime == 'number') { if (typeof atime != 'number' || typeof mtime != 'number') {
callback(new EInvalid('Invalid DateTime values')); callback(new EInvalid('Invalid DateTime values'));
} }
else if (atime < 0 || mtime < 0) { else if (atime < 0 || mtime < 0) {
callback(new EInvalid('DateTime values cannot be negative')) callback(new EInvalid('DateTime values cannot be negative'));
} }
else { else {
find_node(context, path, update_times) find_node(context, path, update_times);
} }
} }
@ -1068,6 +1078,7 @@ define(function(require) {
else { else {
node.atime = atime; node.atime = atime;
node.mtime = mtime; node.mtime = mtime;
context.put(node.id, node, callback);
} }
} }
@ -1076,10 +1087,10 @@ define(function(require) {
callback(new EInvalid('Invalid DateTime values')); callback(new EInvalid('Invalid DateTime values'));
} }
else if (atime < 0 || mtime < 0) { else if (atime < 0 || mtime < 0) {
callback(new EInvalid('DateTime values cannot be negative')) callback(new EInvalid('DateTime values cannot be negative'));
} }
else { else {
context.get(ofd.id, path, update_times) context.get(ofd.id, path, update_times);
} }
} }

View File

@ -14,8 +14,139 @@ define(["IDBFS"], function(IDBFS) {
delete this.fs; delete this.fs;
}); });
it('should be a function', function() { // it('should be a function', function() {
expect(typeof this.fs.utimes).toEqual('function'); // expect(typeof this.fs.utimes).toEqual('function');
// });
// it('should error when atime is negative', function () {
// var complete = false;
// var _error;
// var that = this;
// that.fs.writeFile('/testfile', '', function(error) {
// if (error) throw error;
// that.fs.utimes('/testfile', -1, Date.now(), function (error) {
// _error = error;
// complete = true;
// });
// });
// waitsFor(function () {
// return complete;
// }, 'test to complete', DEFAULT_TIMEOUT);
// runs(function () {
// expect(_error).toBeDefined();
// });
// });
// it('should error when mtime is negative', function () {
// var complete = false;
// var _error;
// var that = this;
// that.fs.writeFile('/testfile', '', function(error) {
// if (error) throw error;
// that.fs.utimes('/testfile', Date.now(), -1, function (error) {
// _error = error;
// complete = true;
// });
// });
// waitsFor(function () {
// return complete;
// }, 'test to complete', DEFAULT_TIMEOUT);
// runs(function () {
// expect(_error).toBeDefined();
// });
// });
// it('should error when atime is as invalid Datetime', function () {
// var complete = false;
// var _error;
// var that = this;
// that.fs.writeFile('/testfile', '', function (error) {
// if (error) throw error;
// that.fs.utimes('/testfile', 'invalid datetime', Date.now(), function (error) {
// _error = error;
// complete = true;
// });
// });
// waitsFor(function () {
// return complete;
// }, 'test to complete', DEFAULT_TIMEOUT);
// runs(function () {
// expect(_error).toBeDefined();
// });
// });
// it('should error when mtime is as invalid Datetime', function () {
// var complete = false;
// var _error;
// var that = this;
// that.fs.writeFile('/testfile', '', function (error) {
// if (error) throw error;
// that.fs.utimes('/testfile', Date.now(), 'invalid datetime', function (error) {
// _error = error;
// complete = true;
// });
// });
// waitsFor(function () {
// return complete;
// }, 'test to complete', DEFAULT_TIMEOUT);
// runs(function () {
// expect(_error).toBeDefined();
// });
// });
it('should change atime and mtime of a file path)', function () {
var complete = false;
var _error;
var that = this;
var stat;
var atime = Date.parse('1 Oct 2000 15:33:22');
var mtime = Date.parse('30 Sep 2000 06:43:54');
that.fs.writeFile('/testfile', '', function (error) {
if (error) throw error;
console.log('created file');
that.fs.utimes('/testfile', atime, mtime, function (error) {
_error = error;
console.log('getting stats');
that.fs.stat('/testfile', function (error, rstat) {
if (error) throw error;
console.log('got stats');
stat = rstat;
complete = true;
});
});
});
waitsFor(function() {
return complete;
}, 'test to complete', DEFAULT_TIMEOUT);
runs(function() {
expect(_error).toEqual(null);
expect(stat.atime).toEqual(atime);
expect(stat.mtime).toEqual(mtime);
});
}); });
}); });
}); });