Upgrade jshint
This commit is contained in:
parent
b7e5f28104
commit
d5c9b29942
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"esversion": 6,
|
||||
"esversion": 8,
|
||||
"globalstrict": true,
|
||||
"sub": true,
|
||||
"expr": true,
|
||||
|
|
14
lib/9p.js
14
lib/9p.js
|
@ -250,7 +250,7 @@ Virtio9p.prototype.SendReply = function (bufchain) {
|
|||
this.virtqueue.flush_replies();
|
||||
};
|
||||
|
||||
Virtio9p.prototype.ReceiveRequest = async function (bufchain) { // jshint ignore:line
|
||||
Virtio9p.prototype.ReceiveRequest = async function (bufchain) {
|
||||
// TODO: split into header + data blobs to avoid unnecessary copying.
|
||||
const buffer = new Uint8Array(bufchain.length_readable);
|
||||
bufchain.get_next_blob(buffer);
|
||||
|
@ -553,7 +553,7 @@ Virtio9p.prototype.ReceiveRequest = async function (bufchain) { // jshint ignore
|
|||
inode.mtime = req[8];
|
||||
}
|
||||
if (req[1] & P9_SETATTR_SIZE) {
|
||||
await this.fs.ChangeSize(this.fids[fid].inodeid, req[5]); // jshint ignore:line
|
||||
await this.fs.ChangeSize(this.fids[fid].inodeid, req[5]);
|
||||
}
|
||||
this.BuildReply(id, tag, 0);
|
||||
this.SendReply(bufchain);
|
||||
|
@ -608,7 +608,7 @@ Virtio9p.prototype.ReceiveRequest = async function (bufchain) { // jshint ignore
|
|||
|
||||
this.bus.send("9p-read-start", [this.fids[fid].dbg_name]);
|
||||
|
||||
const data = await this.fs.Read(inodeid, offset, count); // jshint ignore:line
|
||||
const data = await this.fs.Read(inodeid, offset, count);
|
||||
|
||||
this.bus.send("9p-read-end", [this.fids[fid].dbg_name, count]);
|
||||
|
||||
|
@ -639,7 +639,7 @@ Virtio9p.prototype.ReceiveRequest = async function (bufchain) { // jshint ignore
|
|||
else
|
||||
{
|
||||
// XXX: Size of the subarray is unchecked
|
||||
await this.fs.Write(this.fids[fid].inodeid, offset, count, buffer.subarray(state.offset)); // jshint ignore:line
|
||||
await this.fs.Write(this.fids[fid].inodeid, offset, count, buffer.subarray(state.offset));
|
||||
}
|
||||
|
||||
this.bus.send("9p-write-end", [filename, count]);
|
||||
|
@ -656,7 +656,7 @@ Virtio9p.prototype.ReceiveRequest = async function (bufchain) { // jshint ignore
|
|||
var newdirfid = req[2];
|
||||
var newname = req[3];
|
||||
message.Debug("[renameat]: oldname=" + oldname + " newname=" + newname);
|
||||
var ret = await this.fs.Rename(this.fids[olddirfid].inodeid, oldname, this.fids[newdirfid].inodeid, newname); // jshint ignore:line
|
||||
var ret = await this.fs.Rename(this.fids[olddirfid].inodeid, oldname, this.fids[newdirfid].inodeid, newname);
|
||||
if (ret < 0) {
|
||||
let error_message = "";
|
||||
if(ret === -ENOENT) error_message = "No such file or directory";
|
||||
|
@ -789,7 +789,7 @@ Virtio9p.prototype.ReceiveRequest = async function (bufchain) { // jshint ignore
|
|||
var req = marshall.Unmarshall(["w"], buffer, state);
|
||||
message.Debug("[clunk]: fid=" + req[0]);
|
||||
if (this.fids[req[0]] && this.fids[req[0]].inodeid >= 0) {
|
||||
await this.fs.CloseInode(this.fids[req[0]].inodeid); // jshint ignore:line
|
||||
await this.fs.CloseInode(this.fids[req[0]].inodeid);
|
||||
this.fids[req[0]].inodeid = -1;
|
||||
this.fids[req[0]].type = FID_NONE;
|
||||
}
|
||||
|
@ -849,4 +849,4 @@ Virtio9p.prototype.ReceiveRequest = async function (bufchain) { // jshint ignore
|
|||
|
||||
//consistency checks if there are problems with the filesystem
|
||||
//this.fs.Check();
|
||||
}; // jshint ignore:line
|
||||
};
|
||||
|
|
|
@ -628,12 +628,12 @@ FS.prototype.CreateSymlink = function(filename, parentid, symlink) {
|
|||
return this.inodes.length-1;
|
||||
};
|
||||
|
||||
FS.prototype.CreateTextFile = async function(filename, parentid, str) { // jshint ignore:line
|
||||
FS.prototype.CreateTextFile = async function(filename, parentid, str) {
|
||||
const parent_inode = this.inodes[parentid];
|
||||
if(this.is_forwarder(parent_inode))
|
||||
{
|
||||
const foreign_parentid = parent_inode.foreign_id;
|
||||
const foreign_id = await // jshint ignore:line
|
||||
const foreign_id = await
|
||||
this.follow_fs(parent_inode).CreateTextFile(filename, foreign_parentid, str);
|
||||
return this.create_forwarder(parent_inode.mount_id, foreign_id);
|
||||
}
|
||||
|
@ -645,19 +645,19 @@ FS.prototype.CreateTextFile = async function(filename, parentid, str) { // jshin
|
|||
for (var j = 0; j < str.length; j++) {
|
||||
data[j] = str.charCodeAt(j);
|
||||
}
|
||||
await this.set_data(id, data); // jshint ignore:line
|
||||
await this.set_data(id, data);
|
||||
return id;
|
||||
}; // jshint ignore:line
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Uint8Array} buffer
|
||||
*/
|
||||
FS.prototype.CreateBinaryFile = async function(filename, parentid, buffer) { // jshint ignore:line
|
||||
FS.prototype.CreateBinaryFile = async function(filename, parentid, buffer) {
|
||||
const parent_inode = this.inodes[parentid];
|
||||
if(this.is_forwarder(parent_inode))
|
||||
{
|
||||
const foreign_parentid = parent_inode.foreign_id;
|
||||
const foreign_id = await // jshint ignore:line
|
||||
const foreign_id = await
|
||||
this.follow_fs(parent_inode).CreateBinaryFile(filename, foreign_parentid, buffer);
|
||||
return this.create_forwarder(parent_inode.mount_id, foreign_id);
|
||||
}
|
||||
|
@ -666,10 +666,10 @@ FS.prototype.CreateBinaryFile = async function(filename, parentid, buffer) { //
|
|||
var data = new Uint8Array(buffer.length);
|
||||
x.dirty = true;
|
||||
data.set(buffer);
|
||||
await this.set_data(id, data); // jshint ignore:line
|
||||
await this.set_data(id, data);
|
||||
x.size = buffer.length;
|
||||
return id;
|
||||
}; // jshint ignore:line
|
||||
};
|
||||
|
||||
|
||||
FS.prototype.OpenInode = function(id, mode) {
|
||||
|
@ -694,12 +694,12 @@ FS.prototype.OpenInode = function(id, mode) {
|
|||
return true;
|
||||
};
|
||||
|
||||
FS.prototype.CloseInode = async function(id) { // jshint ignore:line
|
||||
FS.prototype.CloseInode = async function(id) {
|
||||
//message.Debug("close: " + this.GetFullPath(id));
|
||||
var inode = this.inodes[id];
|
||||
if(this.is_forwarder(inode))
|
||||
{
|
||||
return await this.follow_fs(inode).CloseInode(inode.foreign_id); // jshint ignore:line
|
||||
return await this.follow_fs(inode).CloseInode(inode.foreign_id);
|
||||
}
|
||||
if(inode.status === STATUS_ON_STORAGE)
|
||||
{
|
||||
|
@ -708,14 +708,14 @@ FS.prototype.CloseInode = async function(id) { // jshint ignore:line
|
|||
if (inode.status == STATUS_UNLINKED) {
|
||||
//message.Debug("Filesystem: Delete unlinked file");
|
||||
inode.status = STATUS_INVALID;
|
||||
await this.DeleteData(id); // jshint ignore:line
|
||||
await this.DeleteData(id);
|
||||
}
|
||||
}; // jshint ignore:line
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {!Promise<number>} 0 if success, or -errno if failured.
|
||||
*/
|
||||
FS.prototype.Rename = async function(olddirid, oldname, newdirid, newname) { // jshint ignore:line
|
||||
FS.prototype.Rename = async function(olddirid, oldname, newdirid, newname) {
|
||||
// message.Debug("Rename " + oldname + " to " + newname);
|
||||
if ((olddirid == newdirid) && (oldname == newname)) {
|
||||
return 0;
|
||||
|
@ -753,7 +753,7 @@ FS.prototype.Rename = async function(olddirid, oldname, newdirid, newname) { //
|
|||
{
|
||||
// Move inode within the same child filesystem.
|
||||
|
||||
const ret = await // jshint ignore:line
|
||||
const ret = await
|
||||
this.follow_fs(olddir).Rename(olddir.foreign_id, oldname, newdir.foreign_id, newname);
|
||||
|
||||
if(ret < 0) return ret;
|
||||
|
@ -781,7 +781,7 @@ FS.prototype.Rename = async function(olddirid, oldname, newdirid, newname) { //
|
|||
const diverted_old_idx = this.divert(olddirid, oldname);
|
||||
const old_real_inode = this.GetInode(idx);
|
||||
|
||||
const data = await this.Read(diverted_old_idx, 0, old_real_inode.size); // jshint ignore:line
|
||||
const data = await this.Read(diverted_old_idx, 0, old_real_inode.size);
|
||||
|
||||
if(this.is_forwarder(newdir))
|
||||
{
|
||||
|
@ -808,10 +808,10 @@ FS.prototype.Rename = async function(olddirid, oldname, newdirid, newname) { //
|
|||
}
|
||||
|
||||
// Rewrite data to newly created destination.
|
||||
await this.ChangeSize(idx, old_real_inode.size); // jshint ignore:line
|
||||
await this.ChangeSize(idx, old_real_inode.size);
|
||||
if(data && data.length)
|
||||
{
|
||||
await this.Write(idx, 0, data.length, data); // jshint ignore:line
|
||||
await this.Write(idx, 0, data.length, data);
|
||||
}
|
||||
|
||||
// Move children to newly created destination.
|
||||
|
@ -819,13 +819,13 @@ FS.prototype.Rename = async function(olddirid, oldname, newdirid, newname) { //
|
|||
{
|
||||
for(const child_filename of this.GetChildren(diverted_old_idx))
|
||||
{
|
||||
const ret = await this.Rename(diverted_old_idx, child_filename, idx, child_filename); // jshint ignore:line
|
||||
const ret = await this.Rename(diverted_old_idx, child_filename, idx, child_filename);
|
||||
if(ret < 0) return ret;
|
||||
}
|
||||
}
|
||||
|
||||
// Perform destructive changes only after migration succeeded.
|
||||
await this.DeleteData(diverted_old_idx); // jshint ignore:line
|
||||
await this.DeleteData(diverted_old_idx);
|
||||
const ret = this.Unlink(olddirid, oldname);
|
||||
if(ret < 0) return ret;
|
||||
}
|
||||
|
@ -833,26 +833,26 @@ FS.prototype.Rename = async function(olddirid, oldname, newdirid, newname) { //
|
|||
this.NotifyListeners(idx, "rename", {oldpath: oldpath});
|
||||
|
||||
return 0;
|
||||
}; // jshint ignore:line
|
||||
};
|
||||
|
||||
FS.prototype.Write = async function(id, offset, count, buffer) { // jshint ignore:line
|
||||
FS.prototype.Write = async function(id, offset, count, buffer) {
|
||||
this.NotifyListeners(id, 'write');
|
||||
var inode = this.inodes[id];
|
||||
|
||||
if(this.is_forwarder(inode))
|
||||
{
|
||||
const foreign_id = inode.foreign_id;
|
||||
await this.follow_fs(inode).Write(foreign_id, offset, count, buffer); // jshint ignore:line
|
||||
await this.follow_fs(inode).Write(foreign_id, offset, count, buffer);
|
||||
return;
|
||||
}
|
||||
|
||||
inode.dirty = true;
|
||||
var data = await this.get_buffer(id); // jshint ignore:line
|
||||
var data = await this.get_buffer(id);
|
||||
|
||||
if (!data || data.length < (offset+count)) {
|
||||
await this.ChangeSize(id, Math.floor(((offset+count)*3)/2)); // jshint ignore:line
|
||||
await this.ChangeSize(id, Math.floor(((offset+count)*3)/2));
|
||||
inode.size = offset + count;
|
||||
data = await this.get_buffer(id); // jshint ignore:line
|
||||
data = await this.get_buffer(id);
|
||||
} else
|
||||
if (inode.size < (offset+count)) {
|
||||
inode.size = offset + count;
|
||||
|
@ -861,20 +861,20 @@ FS.prototype.Write = async function(id, offset, count, buffer) { // jshint ignor
|
|||
{
|
||||
data.set(buffer.subarray(0, count), offset);
|
||||
}
|
||||
await this.set_data(id, data); // jshint ignore:line
|
||||
}; // jshint ignore:line
|
||||
await this.set_data(id, data);
|
||||
};
|
||||
|
||||
FS.prototype.Read = async function(inodeid, offset, count) // jshint ignore:line
|
||||
FS.prototype.Read = async function(inodeid, offset, count)
|
||||
{
|
||||
const inode = this.inodes[inodeid];
|
||||
if(this.is_forwarder(inode))
|
||||
{
|
||||
const foreign_id = inode.foreign_id;
|
||||
return await this.follow_fs(inode).Read(foreign_id, offset, count); // jshint ignore:line
|
||||
return await this.follow_fs(inode).Read(foreign_id, offset, count);
|
||||
}
|
||||
|
||||
return await this.get_data(inodeid, offset, count); // jshint ignore:line
|
||||
}; // jshint ignore:line
|
||||
return await this.get_data(inodeid, offset, count);
|
||||
};
|
||||
|
||||
FS.prototype.Search = function(parentid, name) {
|
||||
const parent_inode = this.inodes[parentid];
|
||||
|
@ -1050,17 +1050,17 @@ FS.prototype.Unlink = function(parentid, name) {
|
|||
return 0;
|
||||
};
|
||||
|
||||
FS.prototype.DeleteData = async function(idx) // jshint ignore:line
|
||||
FS.prototype.DeleteData = async function(idx)
|
||||
{
|
||||
const inode = this.inodes[idx];
|
||||
if(this.is_forwarder(inode))
|
||||
{
|
||||
await this.follow_fs(inode).DeleteData(inode.foreign_id); // jshint ignore:line
|
||||
await this.follow_fs(inode).DeleteData(inode.foreign_id);
|
||||
return;
|
||||
}
|
||||
inode.size = 0;
|
||||
delete this.inodedata[idx];
|
||||
}; // jshint ignore:line
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
|
@ -1069,7 +1069,7 @@ FS.prototype.DeleteData = async function(idx) // jshint ignore:line
|
|||
* than the data itself. To ensure that any modifications done to this buffer is reflected
|
||||
* to the file, call set_data with the modified buffer.
|
||||
*/
|
||||
FS.prototype.get_buffer = async function(idx) // jshint ignore:line
|
||||
FS.prototype.get_buffer = async function(idx)
|
||||
{
|
||||
const inode = this.inodes[idx];
|
||||
dbg_assert(inode, `Filesystem get_buffer: idx ${idx} does not point to an inode`);
|
||||
|
@ -1081,13 +1081,13 @@ FS.prototype.get_buffer = async function(idx) // jshint ignore:line
|
|||
else if(inode.status === STATUS_ON_STORAGE)
|
||||
{
|
||||
dbg_assert(inode.sha256sum, "Filesystem get_data: found inode on server without sha256sum");
|
||||
return await this.storage.read(inode.sha256sum, 0, inode.size); // jshint ignore:line
|
||||
return await this.storage.read(inode.sha256sum, 0, inode.size);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}; // jshint ignore:line
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
|
@ -1096,7 +1096,7 @@ FS.prototype.get_buffer = async function(idx) // jshint ignore:line
|
|||
* @param {number} count
|
||||
* @return {!Promise<Uint8Array>}
|
||||
*/
|
||||
FS.prototype.get_data = async function(idx, offset, count) // jshint ignore:line
|
||||
FS.prototype.get_data = async function(idx, offset, count)
|
||||
{
|
||||
const inode = this.inodes[idx];
|
||||
dbg_assert(inode, `Filesystem get_data: idx ${idx} does not point to an inode`);
|
||||
|
@ -1108,20 +1108,20 @@ FS.prototype.get_data = async function(idx, offset, count) // jshint ignore:line
|
|||
else if(inode.status === STATUS_ON_STORAGE)
|
||||
{
|
||||
dbg_assert(inode.sha256sum, "Filesystem get_data: found inode on server without sha256sum");
|
||||
return await this.storage.read(inode.sha256sum, offset, count); // jshint ignore:line
|
||||
return await this.storage.read(inode.sha256sum, offset, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}; // jshint ignore:line
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {number} idx
|
||||
* @param {Uint8Array} buffer
|
||||
*/
|
||||
FS.prototype.set_data = async function(idx, buffer) // jshint ignore:line
|
||||
FS.prototype.set_data = async function(idx, buffer)
|
||||
{
|
||||
// Current scheme: Save all modified buffers into local inodedata.
|
||||
this.inodedata[idx] = buffer;
|
||||
|
@ -1130,7 +1130,7 @@ FS.prototype.set_data = async function(idx, buffer) // jshint ignore:line
|
|||
this.inodes[idx].status = STATUS_OK;
|
||||
this.storage.uncache(this.inodes[idx].sha256sum);
|
||||
}
|
||||
}; // jshint ignore:line
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {number} idx
|
||||
|
@ -1150,10 +1150,10 @@ FS.prototype.GetInode = function(idx)
|
|||
return inode;
|
||||
};
|
||||
|
||||
FS.prototype.ChangeSize = async function(idx, newsize) // jshint ignore:line
|
||||
FS.prototype.ChangeSize = async function(idx, newsize)
|
||||
{
|
||||
var inode = this.GetInode(idx);
|
||||
var temp = await this.get_data(idx, 0, inode.size); // jshint ignore:line
|
||||
var temp = await this.get_data(idx, 0, inode.size);
|
||||
inode.dirty = true;
|
||||
//message.Debug("change size to: " + newsize);
|
||||
if (newsize == inode.size) return;
|
||||
|
@ -1164,8 +1164,8 @@ FS.prototype.ChangeSize = async function(idx, newsize) // jshint ignore:line
|
|||
var size = Math.min(temp.length, inode.size);
|
||||
data.set(temp.subarray(0, size), 0);
|
||||
}
|
||||
await this.set_data(idx, data); // jshint ignore:line
|
||||
}; // jshint ignore:line
|
||||
await this.set_data(idx, data);
|
||||
};
|
||||
|
||||
FS.prototype.SearchPath = function(path) {
|
||||
//path = path.replace(/\/\//g, "/");
|
||||
|
|
|
@ -55,7 +55,7 @@ function MemoryFileStorage()
|
|||
* @param {number} count
|
||||
* @return {!Promise<Uint8Array>} null if file does not exist.
|
||||
*/
|
||||
MemoryFileStorage.prototype.read = async function(sha256sum, offset, count) // jshint ignore:line
|
||||
MemoryFileStorage.prototype.read = async function(sha256sum, offset, count)
|
||||
{
|
||||
dbg_assert(sha256sum, "MemoryFileStorage read: sha256sum should be a non-empty string");
|
||||
const data = this.filedata.get(sha256sum);
|
||||
|
@ -66,19 +66,19 @@ MemoryFileStorage.prototype.read = async function(sha256sum, offset, count) // j
|
|||
}
|
||||
|
||||
return data.subarray(offset, offset + count);
|
||||
}; // jshint ignore:line
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} sha256sum
|
||||
* @param {!Uint8Array} data
|
||||
*/
|
||||
MemoryFileStorage.prototype.set = async function(sha256sum, data) // jshint ignore:line
|
||||
MemoryFileStorage.prototype.set = async function(sha256sum, data)
|
||||
{
|
||||
dbg_assert(sha256sum, "MemoryFileStorage set: sha256sum should be a non-empty string");
|
||||
dbg_assert(!this.filedata.has(sha256sum), "MemoryFileStorage set: Storage should be read-only");
|
||||
|
||||
this.filedata.set(sha256sum, data);
|
||||
}; // jshint ignore:line
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} sha256sum
|
||||
|
@ -100,16 +100,16 @@ function IndexedDBFileStorage(db)
|
|||
this.db = db;
|
||||
}
|
||||
|
||||
IndexedDBFileStorage.try_create = async function() // jshint ignore:line
|
||||
IndexedDBFileStorage.try_create = async function()
|
||||
{
|
||||
if(typeof window === "undefined" || !window.indexedDB)
|
||||
{
|
||||
throw new Error("IndexedDB is not available");
|
||||
}
|
||||
const db = await IndexedDBFileStorage.init_db(); // jshint ignore:line
|
||||
const db = await IndexedDBFileStorage.init_db();
|
||||
const file_storage = new IndexedDBFileStorage(db);
|
||||
return file_storage;
|
||||
}; // jshint ignore:line
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {!Promise<!IDBDatabase>}
|
||||
|
@ -223,7 +223,7 @@ IndexedDBFileStorage.prototype.read = function(sha256sum, offset, count)
|
|||
|
||||
const block_key = INDEXEDDB_STORAGE_GET_BLOCK_KEY(sha256sum, 0);
|
||||
const block_request = store.get(block_key);
|
||||
block_request.onsuccess = async event => // jshint ignore:line
|
||||
block_request.onsuccess = async event =>
|
||||
{
|
||||
const block_entry = block_request.result;
|
||||
if(!block_entry)
|
||||
|
@ -245,16 +245,16 @@ IndexedDBFileStorage.prototype.read = function(sha256sum, offset, count)
|
|||
const block_offset = block_number_start * INDEXEDDB_STORAGE_BLOCKSIZE;
|
||||
const block_key = INDEXEDDB_STORAGE_GET_BLOCK_KEY(sha256sum, block_number_start);
|
||||
const block_request = store.get(block_key);
|
||||
block_request.onsuccess = async event => // jshint ignore:line
|
||||
block_request.onsuccess = async event =>
|
||||
{
|
||||
const block_entry = block_request.result;
|
||||
if(!block_entry)
|
||||
{
|
||||
if(!await this.db_has_file(store, sha256sum)) // jshint ignore:line
|
||||
if(!await this.db_has_file(store, sha256sum))
|
||||
{
|
||||
resolve(null);
|
||||
}
|
||||
else // jshint ignore:line
|
||||
else
|
||||
{
|
||||
resolve(new Uint8Array(0));
|
||||
}
|
||||
|
@ -280,7 +280,7 @@ IndexedDBFileStorage.prototype.read = function(sha256sum, offset, count)
|
|||
const block_offset = block_number * INDEXEDDB_STORAGE_BLOCKSIZE;
|
||||
const block_key = INDEXEDDB_STORAGE_GET_BLOCK_KEY(sha256sum, block_number);
|
||||
const block_request = store.get(block_key);
|
||||
block_request.onsuccess = async event => // jshint ignore:line
|
||||
block_request.onsuccess = async event =>
|
||||
{
|
||||
const block_entry = block_request.result;
|
||||
|
||||
|
@ -290,7 +290,7 @@ IndexedDBFileStorage.prototype.read = function(sha256sum, offset, count)
|
|||
// cannot exist.
|
||||
if(block_number === block_number_start)
|
||||
{
|
||||
if(!await this.db_has_file(store, sha256sum)) // jshint ignore:line
|
||||
if(!await this.db_has_file(store, sha256sum))
|
||||
{
|
||||
// Not aborting transaction here because:
|
||||
// - Abort is treated like an error,
|
||||
|
@ -404,25 +404,25 @@ ServerFileStorageWrapper.prototype.load_from_server = function(sha256sum)
|
|||
* @param {number} count
|
||||
* @return {!Promise<Uint8Array>}
|
||||
*/
|
||||
ServerFileStorageWrapper.prototype.read = async function(sha256sum, offset, count) // jshint ignore:line
|
||||
ServerFileStorageWrapper.prototype.read = async function(sha256sum, offset, count)
|
||||
{
|
||||
const data = await this.storage.read(sha256sum, offset, count); // jshint ignore:line
|
||||
const data = await this.storage.read(sha256sum, offset, count);
|
||||
if(!data)
|
||||
{
|
||||
const full_file = await this.load_from_server(sha256sum); // jshint ignore:line
|
||||
const full_file = await this.load_from_server(sha256sum);
|
||||
return full_file.subarray(offset, offset + count);
|
||||
}
|
||||
return data;
|
||||
}; // jshint ignore:line
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} sha256sum
|
||||
* @param {!Uint8Array} data
|
||||
*/
|
||||
ServerFileStorageWrapper.prototype.set = async function(sha256sum, data) // jshint ignore:line
|
||||
ServerFileStorageWrapper.prototype.set = async function(sha256sum, data)
|
||||
{
|
||||
return await this.storage.set(sha256sum, data); // jshint ignore:line
|
||||
}; // jshint ignore:line
|
||||
return await this.storage.set(sha256sum, data);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} sha256sum
|
||||
|
|
|
@ -215,7 +215,7 @@ function V86Starter(options)
|
|||
});
|
||||
}
|
||||
|
||||
V86Starter.prototype.continue_init = async function(emulator, options) // jshint ignore:line
|
||||
V86Starter.prototype.continue_init = async function(emulator, options)
|
||||
{
|
||||
this.bus.register("emulator-stopped", function()
|
||||
{
|
||||
|
@ -447,7 +447,7 @@ V86Starter.prototype.continue_init = async function(emulator, options) // jshint
|
|||
|
||||
let file_storage = typeof window === "undefined" || !window.indexedDB ?
|
||||
new MemoryFileStorage() :
|
||||
await IndexedDBFileStorage.try_create(); // jshint ignore:line
|
||||
await IndexedDBFileStorage.try_create();
|
||||
if(base_url)
|
||||
{
|
||||
file_storage = new ServerFileStorageWrapper(file_storage, base_url);
|
||||
|
@ -605,7 +605,7 @@ V86Starter.prototype.continue_init = async function(emulator, options) // jshint
|
|||
this.emulator_bus.send("emulator-loaded");
|
||||
}
|
||||
}
|
||||
}; // jshint ignore:line
|
||||
};
|
||||
|
||||
V86Starter.prototype.get_bzimage_initrd_from_filesystem = function(filesystem)
|
||||
{
|
||||
|
@ -1046,11 +1046,11 @@ V86Starter.prototype.serial0_send = function(data)
|
|||
* @param {function(Object)=} callback
|
||||
* @export
|
||||
*/
|
||||
V86Starter.prototype.mount_fs = async function(path, baseurl, basefs, callback) // jshint ignore:line
|
||||
V86Starter.prototype.mount_fs = async function(path, baseurl, basefs, callback)
|
||||
{
|
||||
let file_storage = typeof window === "undefined" || !window.indexedDB ?
|
||||
new MemoryFileStorage() :
|
||||
await IndexedDBFileStorage.try_create(); // jshint ignore:line
|
||||
await IndexedDBFileStorage.try_create();
|
||||
if(baseurl)
|
||||
{
|
||||
file_storage = new ServerFileStorageWrapper(file_storage, baseurl);
|
||||
|
@ -1090,7 +1090,7 @@ V86Starter.prototype.mount_fs = async function(path, baseurl, basefs, callback)
|
|||
{
|
||||
mount();
|
||||
}
|
||||
}; // jshint ignore:line
|
||||
};
|
||||
|
||||
/**
|
||||
* Write to a file in the 9p filesystem. Nothing happens if no filesystem has
|
||||
|
|
|
@ -155,20 +155,20 @@ function mock_indexeddb()
|
|||
};
|
||||
}
|
||||
|
||||
async function test_read(oracle, iut, key, offset, count) // jshint ignore:line
|
||||
async function test_read(oracle, iut, key, offset, count)
|
||||
{
|
||||
const expected = await oracle.read(key, offset, count); // jshint ignore:line
|
||||
const actual = await iut.read(key, offset, count); // jshint ignore:line
|
||||
const expected = await oracle.read(key, offset, count);
|
||||
const actual = await iut.read(key, offset, count);
|
||||
return assert_uint8array_equal(actual, expected);
|
||||
}
|
||||
|
||||
async function test_with_file(oracle, iut, key, file_data) // jshint ignore:line
|
||||
async function test_with_file(oracle, iut, key, file_data)
|
||||
{
|
||||
if(file_data)
|
||||
{
|
||||
console.log("Testing file with size: %d", file_data.length);
|
||||
await oracle.set(key, file_data); // jshint ignore:line
|
||||
await iut.set(key, file_data); // jshint ignore:line
|
||||
await oracle.set(key, file_data);
|
||||
await iut.set(key, file_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -176,22 +176,22 @@ async function test_with_file(oracle, iut, key, file_data) // jshint ignore:line
|
|||
}
|
||||
|
||||
// Some boundary values.
|
||||
if(!await test_read(oracle, iut, key, 0, 0)) return false; // jshint ignore:line
|
||||
if(!await test_read(oracle, iut, key, 0, 1)) return false; // jshint ignore:line
|
||||
if(!await test_read(oracle, iut, key, 0, 4096)) return false; // jshint ignore:line
|
||||
if(!await test_read(oracle, iut, key, 0, 4097)) return false; // jshint ignore:line
|
||||
if(!await test_read(oracle, iut, key, 4095, 2)) return false; // jshint ignore:line
|
||||
if(!await test_read(oracle, iut, key, 4096, 1)) return false; // jshint ignore:line
|
||||
if(!await test_read(oracle, iut, key, 4096, 4096)) return false; // jshint ignore:line
|
||||
if(!await test_read(oracle, iut, key, 4097, 1)) return false; // jshint ignore:line
|
||||
if(!await test_read(oracle, iut, key, 4097, 4095)) return false; // jshint ignore:line
|
||||
if(!await test_read(oracle, iut, key, 0, 0)) return false;
|
||||
if(!await test_read(oracle, iut, key, 0, 1)) return false;
|
||||
if(!await test_read(oracle, iut, key, 0, 4096)) return false;
|
||||
if(!await test_read(oracle, iut, key, 0, 4097)) return false;
|
||||
if(!await test_read(oracle, iut, key, 4095, 2)) return false;
|
||||
if(!await test_read(oracle, iut, key, 4096, 1)) return false;
|
||||
if(!await test_read(oracle, iut, key, 4096, 4096)) return false;
|
||||
if(!await test_read(oracle, iut, key, 4097, 1)) return false;
|
||||
if(!await test_read(oracle, iut, key, 4097, 4095)) return false;
|
||||
|
||||
// Random ranges.
|
||||
for(let i = 0; i < NUMBER_OF_TESTREADS; i++)
|
||||
{
|
||||
const offset = Math.floor(Math.random() * MAX_TESTFILE_SIZE);
|
||||
const count = Math.floor(Math.random() * MAX_TESTFILE_SIZE);
|
||||
const pass = await test_read(oracle, iut, key, offset, count); // jshint ignore:line
|
||||
const pass = await test_read(oracle, iut, key, offset, count);
|
||||
if(!pass)
|
||||
{
|
||||
log_fail("Test case offset=%d, count=%d", offset, count);
|
||||
|
@ -211,7 +211,7 @@ function on_unexpected_exit(exit_code)
|
|||
}
|
||||
}
|
||||
|
||||
async function test_start() // jshint ignore:line
|
||||
async function test_start()
|
||||
{
|
||||
process.on("exit", on_unexpected_exit);
|
||||
|
||||
|
@ -221,16 +221,16 @@ async function test_start() // jshint ignore:line
|
|||
// Implementation under test with chunking.
|
||||
const iut = new IndexedDBFileStorage(mock_indexeddb());
|
||||
|
||||
if(!await test_with_file(oracle, iut, "nonexistent")) return false; // jshint ignore:line
|
||||
if(!await test_with_file(oracle, iut, "empty", new Uint8Array(0))) return false; // jshint ignore:line
|
||||
if(!await test_with_file(oracle, iut, "single", new Uint8Array(1).map(v => Math.random() * 0xFF))) return false; // jshint ignore:line
|
||||
if(!await test_with_file(oracle, iut, "1block", new Uint8Array(4096).map(v => Math.random() * 0xFF))) return false; // jshint ignore:line
|
||||
if(!await test_with_file(oracle, iut, "nonexistent")) return false;
|
||||
if(!await test_with_file(oracle, iut, "empty", new Uint8Array(0))) return false;
|
||||
if(!await test_with_file(oracle, iut, "single", new Uint8Array(1).map(v => Math.random() * 0xFF))) return false;
|
||||
if(!await test_with_file(oracle, iut, "1block", new Uint8Array(4096).map(v => Math.random() * 0xFF))) return false;
|
||||
|
||||
for(let i = 0; i < NUMBER_OF_TESTFILES; i++)
|
||||
{
|
||||
const size = Math.floor(Math.random() * MAX_TESTFILE_SIZE);
|
||||
const file_data = new Uint8Array(size).map(v => Math.random() * 0xFF);
|
||||
const pass = await test_with_file(oracle, iut, i.toString(), file_data); // jshint ignore:line
|
||||
const pass = await test_with_file(oracle, iut, i.toString(), file_data);
|
||||
if(!pass) return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue