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
|
||||
|
||||
def _applyAtom(self, atom: Atom) -> None:
|
||||
## TODO:
|
||||
pass
|
||||
if atom.name in self.inodes:
|
||||
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:
|
||||
self.append(atom.dump())
|
||||
@ -264,11 +269,8 @@ class TangleFileTreeElement(TangleBlob):
|
||||
self._requireFetched()
|
||||
if name in self.getNameList():
|
||||
return False
|
||||
atom = Atom()
|
||||
atom.type="file"
|
||||
atom.name = name
|
||||
atom.token = self.genToken()
|
||||
atom.size = 0
|
||||
file = Inode(name, self.iotaApi, self, "file")
|
||||
atom = file.change(size=0, milestoneIndex=0, hash=b'NULL')
|
||||
self._newAtom(atom)
|
||||
self._applyAtom(atom)
|
||||
return True
|
||||
@ -340,11 +342,12 @@ class Inode():
|
||||
|
||||
def change(self, size: int=None, hash: int=None, milestoneIndex: int=None) -> Atom:
|
||||
delta = {}
|
||||
delta[b't'] = (self.type=="file")
|
||||
if size!=None:
|
||||
self.size = size
|
||||
delta[b's'] = size
|
||||
if size!=None:
|
||||
self.size = hash
|
||||
if hash!=None:
|
||||
self.hash = hash
|
||||
delta[b'h'] = hash
|
||||
if milestoneIndex!=None:
|
||||
self.milestoneIndex = milestoneIndex
|
||||
@ -359,6 +362,8 @@ class Inode():
|
||||
if self.name in stones:
|
||||
self.applyAtom(Atom(False, stones[self.name], self.name))
|
||||
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
|
||||
if b's' in delta:
|
||||
self.size = delta[b's']
|
||||
@ -376,9 +381,9 @@ class Inode():
|
||||
return None
|
||||
if not self.ref:
|
||||
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":
|
||||
self.ref = TangleFile(self.name, self, self.api)
|
||||
self.ref = TangleFile(self.name, self, self.iotaApi)
|
||||
else:
|
||||
raise Exception("Cannot get reference of an inode of type "+self.type)
|
||||
return self.ref
|
||||
|
Loading…
Reference in New Issue
Block a user