From e84d6392109fd9e7f2f0698be2f05afaaf485104 Mon Sep 17 00:00:00 2001 From: Barry Tulchinsky Date: Sun, 15 Dec 2013 02:54:51 -0500 Subject: [PATCH] fixed bugs where atime and mtime weren't updated on the node and where mtime was valid it would error. Also added more tests --- src/fs.js | 21 ++++-- tests/spec/fs.utimes.spec.js | 135 ++++++++++++++++++++++++++++++++++- 2 files changed, 149 insertions(+), 7 deletions(-) diff --git a/src/fs.js b/src/fs.js index a0b265a..76a587d 100644 --- a/src/fs.js +++ b/src/fs.js @@ -1038,24 +1038,34 @@ define(function(require) { path = normalize(path); function update_times (error, node) { + //Note: Going by node.js' implementation, utimes works on directories if (error) { callback(error); } else { + console.log(node); node.atime = atime; 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 - if (typeof atime != 'number' || typeof mtime == 'number') { + if (typeof atime != 'number' || typeof mtime != 'number') { callback(new EInvalid('Invalid DateTime values')); } else if (atime < 0 || mtime < 0) { - callback(new EInvalid('DateTime values cannot be negative')) + callback(new EInvalid('DateTime values cannot be negative')); } else { - find_node(context, path, update_times) + find_node(context, path, update_times); } } @@ -1068,6 +1078,7 @@ define(function(require) { else { node.atime = atime; node.mtime = mtime; + context.put(node.id, node, callback); } } @@ -1076,10 +1087,10 @@ define(function(require) { callback(new EInvalid('Invalid DateTime values')); } else if (atime < 0 || mtime < 0) { - callback(new EInvalid('DateTime values cannot be negative')) + callback(new EInvalid('DateTime values cannot be negative')); } else { - context.get(ofd.id, path, update_times) + context.get(ofd.id, path, update_times); } } diff --git a/tests/spec/fs.utimes.spec.js b/tests/spec/fs.utimes.spec.js index 11b500f..1156a8c 100644 --- a/tests/spec/fs.utimes.spec.js +++ b/tests/spec/fs.utimes.spec.js @@ -14,8 +14,139 @@ define(["IDBFS"], function(IDBFS) { delete this.fs; }); - it('should be a function', function() { - expect(typeof this.fs.utimes).toEqual('function'); + // it('should be a function', 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); + }); }); }); }); \ No newline at end of file