зеркало из https://github.com/mozilla/pluotsorbet.git
ensure creation succeeds before setting stat.isDir
This commit is contained in:
Родитель
d70a4e79e7
Коммит
ec2a93bce8
16
libs/fs.js
16
libs/fs.js
|
@ -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");
|
||||
|
|
Загрузка…
Ссылка в новой задаче