added/fixed tests and futimes bug

This commit is contained in:
Barry Tulchinsky 2013-12-15 21:22:36 -05:00
parent b5b2367959
commit 23ace603c9
4 changed files with 194 additions and 105 deletions

View File

@ -1,3 +1,4 @@
Alan K <ack@modeswitch.org> (blog.modeswitch.org) Alan K <ack@modeswitch.org> (blog.modeswitch.org)
David Humphrey <david.humphrey@senecacollege.ca> (@humphd) David Humphrey <david.humphrey@senecacollege.ca> (@humphd)
Abir Viqar <abiviq@hushmail.com> Abir Viqar <abiviq@hushmail.com>
Barry Tulchinsky <barry.tulchinsky@gmail.com> (@btulchinsky)

View File

@ -336,3 +336,11 @@ Asynchronous truncate(2). Callback gets no additional arguments.
#### fs.ftruncate(fd, length, callback) #### fs.ftruncate(fd, length, callback)
Asynchronous ftruncate(2). Callback gets no additional arguments. Asynchronous ftruncate(2). Callback gets no additional arguments.
#### fs.utimes(path, atime, mtime, callback)
Asynchronous utimes(3). Callback gets no additional arguments.
#### fs.futimes(fd, atime, mtime, callback)
Asynchronous futimes(3). Callback gets no additional arguments.

View File

@ -1075,14 +1075,14 @@ define(function(require) {
} }
//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 {
context.get(ofd.id, path, update_times); context.get(ofd.id, update_times);
} }
} }
@ -1590,7 +1590,7 @@ define(function(require) {
utimes_file(context, path, atime, mtime, check_result) utimes_file(context, path, atime, mtime, check_result)
} }
function _futimes(context, fd, atime, mtime, callback) { function _futimes(fs, context, fd, atime, mtime, callback) {
function check_result(error) { function check_result(error) {
if (error) { if (error) {
callback(error); callback(error);
@ -1966,7 +1966,7 @@ define(function(require) {
var error = fs.queueOrRun( var error = fs.queueOrRun(
function () { function () {
var context = fs.provider.getReadWriteContext(); var context = fs.provider.getReadWriteContext();
_futimes(context, fd, atime, mtime, callback); _futimes(fs, context, fd, atime, mtime, callback);
} }
); );
}; };

View File

@ -14,108 +14,108 @@ 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 () { 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 complete = false;
var _error; var _error;
var that = this; var that = this;
var stat; 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 atime = Date.parse('1 Oct 2000 15:33:22');
var mtime = Date.parse('30 Sep 2000 06:43:54'); var mtime = Date.parse('30 Sep 2000 06:43:54');
@ -126,10 +126,10 @@ define(["IDBFS"], function(IDBFS) {
that.fs.utimes('/testfile', atime, mtime, function (error) { that.fs.utimes('/testfile', atime, mtime, function (error) {
_error = error; _error = error;
that.fs.stat('/testfile', function (error, rstat) { that.fs.stat('/testfile', function (error, stat) {
if (error) throw error; if (error) throw error;
stat = rstat; _stat = stat;
complete = true; complete = true;
}); });
}); });
@ -141,8 +141,88 @@ define(["IDBFS"], function(IDBFS) {
runs(function() { runs(function() {
expect(_error).toEqual(null); expect(_error).toEqual(null);
expect(stat.atime).toEqual(atime); expect(_stat.atime).toEqual(atime);
expect(stat.mtime).toEqual(mtime); expect(_stat.mtime).toEqual(mtime);
});
});
it ('should change atime and mtime for a valid file descriptor', function (error) {
var complete = false;
var _error;
var that = this;
var ofd;
var _stat;
var atime = Date.parse('1 Oct 2000 15:33:22');
var mtime = Date.parse('30 Sep 2000 06:43:54');
that.fs.open('/testfile', 'w', function (error, result) {
if (error) throw error;
ofd = result;
that.fs.futimes(ofd, atime, mtime, function (error) {
_error = error;
that.fs.fstat(ofd, function (error, stat) {
if (error) throw error;
_stat = stat;
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);
});
});
it ('should update atime and mtime of directory path', function (error) {
var complete = false
var _error;
//Note: required as the filesystem somehow gets removed from the Jasmine object
var fs = this.fs;
var _stat;
var atime = Date.parse('1 Oct 2000 15:33:22');
var mtime = Date.parse('30 Sep 2000 06:43:54');
fs.mkdir('/testdir', function (error) {
if (error) throw error;
fs.utimes('/testdir', atime, mtime, function (error) {
_error = error;
fs.stat('/testdir', function (error, stat) {
if (error) {
throw error;
}
_stat = stat;
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);
delete fs;
}); });
}); });
}); });