objectstore: extract method to open a TreeObject
Extract the opening a TreeObject out of the treesum property so that the latter is easier to read.
This commit is contained in:
parent
6f4d286ff4
commit
5a61d8c869
1 changed files with 9 additions and 4 deletions
|
|
@ -40,16 +40,21 @@ class TreeObject:
|
|||
@property
|
||||
def treesum(self) -> str:
|
||||
"""Calculate the treesum of the tree"""
|
||||
fd = os.open(self.path, os.O_DIRECTORY)
|
||||
try:
|
||||
with self.open() as fd:
|
||||
m = hashlib.sha256()
|
||||
treesum.treesum(m, fd)
|
||||
treesum_hash = m.hexdigest()
|
||||
return treesum_hash
|
||||
|
||||
@contextlib.contextmanager
|
||||
def open(self):
|
||||
"""Open the directory and return the file descriptor"""
|
||||
try:
|
||||
fd = os.open(self.path, os.O_DIRECTORY)
|
||||
yield fd
|
||||
finally:
|
||||
os.close(fd)
|
||||
|
||||
return treesum_hash
|
||||
|
||||
def move(self, destination: str):
|
||||
"""Move the tree to destination
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue