When I said it works, I lied... But now it works a little bit more
This commit is contained in:
parent
c0e3c81231
commit
085e503dec
27
next.py
27
next.py
@ -236,8 +236,13 @@ class TangleFileTreeElement(TangleBlob):
|
|||||||
self.inodes[atom.name] = atom
|
self.inodes[atom.name] = atom
|
||||||
|
|
||||||
def _applyAtom(self, atom: Atom) -> None:
|
def _applyAtom(self, atom: Atom) -> None:
|
||||||
## TODO:
|
if atom.name in self.inodes:
|
||||||
pass
|
self.inodes[atom.name].applyAtom(atom)
|
||||||
|
else:
|
||||||
|
cont = atom.cont
|
||||||
|
type = ["dir","file"][cont[b't']]
|
||||||
|
inode = Inode(atom.name, self.iotaApi, self, type)
|
||||||
|
self.inodes[atom.name] = inode
|
||||||
|
|
||||||
def _newAtom(self, atom: Atom) -> None:
|
def _newAtom(self, atom: Atom) -> None:
|
||||||
self.append(atom.dump())
|
self.append(atom.dump())
|
||||||
@ -264,11 +269,8 @@ class TangleFileTreeElement(TangleBlob):
|
|||||||
self._requireFetched()
|
self._requireFetched()
|
||||||
if name in self.getNameList():
|
if name in self.getNameList():
|
||||||
return False
|
return False
|
||||||
atom = Atom()
|
file = Inode(name, self.iotaApi, self, "file")
|
||||||
atom.type="file"
|
atom = file.change(size=0, milestoneIndex=0, hash=b'NULL')
|
||||||
atom.name = name
|
|
||||||
atom.token = self.genToken()
|
|
||||||
atom.size = 0
|
|
||||||
self._newAtom(atom)
|
self._newAtom(atom)
|
||||||
self._applyAtom(atom)
|
self._applyAtom(atom)
|
||||||
return True
|
return True
|
||||||
@ -340,11 +342,12 @@ class Inode():
|
|||||||
|
|
||||||
def change(self, size: int=None, hash: int=None, milestoneIndex: int=None) -> Atom:
|
def change(self, size: int=None, hash: int=None, milestoneIndex: int=None) -> Atom:
|
||||||
delta = {}
|
delta = {}
|
||||||
|
delta[b't'] = (self.type=="file")
|
||||||
if size!=None:
|
if size!=None:
|
||||||
self.size = size
|
self.size = size
|
||||||
delta[b's'] = size
|
delta[b's'] = size
|
||||||
if size!=None:
|
if hash!=None:
|
||||||
self.size = hash
|
self.hash = hash
|
||||||
delta[b'h'] = hash
|
delta[b'h'] = hash
|
||||||
if milestoneIndex!=None:
|
if milestoneIndex!=None:
|
||||||
self.milestoneIndex = milestoneIndex
|
self.milestoneIndex = milestoneIndex
|
||||||
@ -359,6 +362,8 @@ class Inode():
|
|||||||
if self.name in stones:
|
if self.name in stones:
|
||||||
self.applyAtom(Atom(False, stones[self.name], self.name))
|
self.applyAtom(Atom(False, stones[self.name], self.name))
|
||||||
else:
|
else:
|
||||||
|
if (self.type=="file") != atom.cont[b't']:
|
||||||
|
raise Exception("I am a "+self.type+"; this atom is for the other thing")
|
||||||
delta = atom.cont
|
delta = atom.cont
|
||||||
if b's' in delta:
|
if b's' in delta:
|
||||||
self.size = delta[b's']
|
self.size = delta[b's']
|
||||||
@ -376,9 +381,9 @@ class Inode():
|
|||||||
return None
|
return None
|
||||||
if not self.ref:
|
if not self.ref:
|
||||||
if self.type=="dir":
|
if self.type=="dir":
|
||||||
self.elem = TangleFileTreeElement(self.name, self.milestoneIndex, self.parent, self.iotaApi)
|
self.ref = TangleFileTreeElement(self.name, self.milestoneIndex, self.parent, self.iotaApi)
|
||||||
elif self.type=="file":
|
elif self.type=="file":
|
||||||
self.ref = TangleFile(self.name, self, self.api)
|
self.ref = TangleFile(self.name, self, self.iotaApi)
|
||||||
else:
|
else:
|
||||||
raise Exception("Cannot get reference of an inode of type "+self.type)
|
raise Exception("Cannot get reference of an inode of type "+self.type)
|
||||||
return self.ref
|
return self.ref
|
||||||
|
Loading…
Reference in New Issue
Block a user