Filesystem: Load files via their sha256

This commit is contained in:
Fabian 2018-08-16 15:10:30 -05:00
parent e29e1ef9f4
commit 28ac891dc3
4 changed files with 8 additions and 3 deletions

View file

@ -32,7 +32,7 @@ var STATUS_UNLINKED = 0x4;
var STATUS_FORWARDING = 0x5;
/** @const */ var JSONFS_VERSION = 2;
/** @const */ var JSONFS_VERSION = 3;
/** @const */ var JSONFS_IDX_NAME = 0;
@ -42,6 +42,7 @@ var STATUS_FORWARDING = 0x5;
/** @const */ var JSONFS_IDX_UID = 4;
/** @const */ var JSONFS_IDX_GID = 5;
/** @const */ var JSONFS_IDX_TARGET = 6;
/** @const */ var JSONFS_IDX_SHA256 = 6;
/**
@ -255,6 +256,7 @@ FS.prototype.LoadRecursive = function(data, parentid)
else if(ifmt === S_IFREG)
{
inode.status = STATUS_ON_SERVER;
inode.sha256sum = data[JSONFS_IDX_SHA256];
this.PushInode(inode);
}
else if(ifmt === S_IFLNK)
@ -317,7 +319,7 @@ FS.prototype.LoadFile = function(idx) {
if(this.baseurl)
{
LoadBinaryResource(this.baseurl + this.GetFullPath(inode.fid),
LoadBinaryResource(this.baseurl + inode.sha256sum,
function(buffer){
var data = this.inodedata[idx] = new Uint8Array(buffer);
inode.size = data.length; // correct size if the previous was wrong.
@ -434,6 +436,7 @@ function Inode(qidnumber)
this.caps = undefined;
this.nlinks = 1;
this.dirty = false; // has this file changed?
this.sha256sum = "";
// For forwarders:
this.mount_id = -1; // which fs in this.mounts does this inode forward to?
@ -472,6 +475,7 @@ Inode.prototype.get_state = function()
state[22] = this.dirty;
state[23] = this.mount_id;
state[24] = this.foreign_id;
state[25] = this.sha256sum;
return state;
};
@ -502,6 +506,7 @@ Inode.prototype.set_state = function(state)
this.dirty = state[22];
this.mount_id = state[23];
this.foreign_id = state[24];
this.sha256sum = state[25];
};
/**

View file

@ -1 +1 @@
{"fsroot":[["foo",4,1531432001,33188,1000,1000],["dir",4096,1532940393,16877,1000,1000,[["bar",7,1532940393,33188,1000,1000]]]],"version":2,"size":4107}
{"fsroot":[["foo",4,1531432001,33188,1000,1000,"7d865e959b2466918c9863afca942d0fb89d7c9ac0c99bafc3749504ded97730"],["dir",4096,1532940393,16877,1000,1000,[["bar",7,1532940393,33188,1000,1000,"5d70f436aa013f4f1d5af4a5e8149b479c813ab4ceea0bcf8b01f78eac84fd25"]]]],"version":3,"size":4107}