ensure creation succeeds before setting stat.isDir

This commit is contained in:
Myk Melez 2014-09-27 02:21:48 -07:00
Родитель d70a4e79e7
Коммит ec2a93bce8
3 изменённых файлов: 41 добавлений и 5 удалений

Просмотреть файл

@ -281,17 +281,25 @@ var fs = (function() {
function create(path, blob, cb) {
createInternal(path, blob, function(created) {
setStat(path, { mtime: Date.now(), isDir: false }, function() {
if (created) {
setStat(path, { mtime: Date.now(), isDir: false }, function() {
cb(created);
});
} else {
cb(created);
});
}
});
}
function mkdir(path, cb) {
createInternal(path, [], function(created) {
setStat(path, { mtime: Date.now(), isDir: true }, function() {
if (created) {
setStat(path, { mtime: Date.now(), isDir: true }, function() {
cb(created);
});
} else {
cb(created);
});
}
});
}

Просмотреть файл

@ -54,7 +54,7 @@ casper.test.begin("unit tests", 5 + gfxTests.length, function(test) {
casper
.thenOpen("http://localhost:8000/tests/fstests.html")
.waitForText("DONE", function() {
test.assertTextExists("DONE: 121 PASS, 0 FAIL", "run fs.js unit tests");
test.assertTextExists("DONE: 125 PASS, 0 FAIL", "run fs.js unit tests");
});
casper

Просмотреть файл

@ -107,6 +107,13 @@ tests.push(function() {
});
});
tests.push(function() {
fs.stat("/tmp", function(stat) {
ok(stat.isDir, "/tmp is a directory");
next();
});
});
tests.push(function() {
fs.create("/tmp", new Blob(), function(created) {
is(created, false, "can't create a file with the same path of an already existing directory");
@ -114,6 +121,13 @@ tests.push(function() {
});
});
tests.push(function() {
fs.stat("/tmp", function(stat) {
ok(stat.isDir, "/tmp is still a directory");
next();
});
});
tests.push(function() {
fs.mkdir("/tmp", function(created) {
is(created, false, "can't create a directory with the same path of an already existing directory");
@ -128,6 +142,13 @@ tests.push(function() {
});
});
tests.push(function() {
fs.stat("/tmp/tmp.txt", function(stat) {
ok(!stat.isDir, "/tmp/tmp.txt is not a directory");
next();
});
});
tests.push(function() {
fs.mkdir("/tmp/tmp.txt", function(created) {
is(created, false, "can't create a directory with the same path of an already existing file");
@ -135,6 +156,13 @@ tests.push(function() {
});
});
tests.push(function() {
fs.stat("/tmp/tmp.txt", function(stat) {
ok(!stat.isDir, "/tmp/tmp.txt is still not a directory");
next();
});
});
tests.push(function() {
fs.size("/tmp/tmp.txt", function(size) {
is(size, 0, "newly created file's size is 0");