This commit is contained in:
Myk Melez 2014-09-16 15:11:39 -07:00
Родитель aca9c3e09c
Коммит e063f8b254
2 изменённых файлов: 63 добавлений и 0 удалений

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

@ -157,6 +157,11 @@ var fs = (function() {
buffer.array.set(data, from);
openedFiles[fd].position = from + data.byteLength;
var stat = {
mtime: Date.now(),
};
asyncStorage.setItem("!" + openedFiles[fd].path, stat);
}
function getpos(fd) {
@ -267,6 +272,11 @@ var fs = (function() {
files.push(name);
asyncStorage.setItem(dir, files, function() {
asyncStorage.setItem(path, data, function() {
var stat = {
mtime: Date.now(),
};
asyncStorage.setItem("!" + path, stat);
cb(true);
});
});
@ -372,6 +382,29 @@ var fs = (function() {
});
}
function stat(path, cb) {
path = normalizePath(path);
exists(path, function(exists) {
if (exists) {
asyncStorage.getItem("!" + path, function(stat) {
// If we don't have a stat for this file, make one up.
if (stat == null) {
stat = {
mtime: Date.now(),
};
asyncStorage.setItem("!" + path, stat);
}
cb(stat);
});
} else {
// The file doesn't exist, so it can't have a stat.
cb(null);
}
});
}
return {
dirname: dirname,
init: init,
@ -393,5 +426,6 @@ var fs = (function() {
mkdirp: mkdirp,
size: size,
rename: rename,
stat: stat,
};
})();

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

@ -603,6 +603,35 @@ tests.push(function() {
});
});
tests.push(function() {
var startTime = Date.now(), beforeCreate, afterCreate, afterWrite, afterClose;
fs.stat("/tmp/stat.txt", function(stat) {
beforeCreate = stat;
fs.create("/tmp/stat.txt", new Blob(), function(created) {
fs.stat("/tmp/stat.txt", function(stat) {
afterCreate = stat;
fs.open("/tmp/stat.txt", function(fd) {
fs.write(fd, new TextEncoder().encode("misc"));
fs.stat("/tmp/stat.txt", function(stat) {
afterWrite = stat;
fs.close(fd);
fs.stat("/tmp/stat.txt", function(stat) {
afterClose = stat;
is(beforeCreate, null, "no stat for nonexistent file");
ok(afterCreate.mtime >= startTime, "file creation updates modification time");
ok(afterWrite.mtime >= afterCreate.mtime, "file write updates modification time");
ok(afterClose.mtime == afterWrite.mtime, "file close doesn't update modification time");
});
});
});
});
});
});
});
asyncStorage.clear(function() {
fs.init(function() {
next();