Fix appending in storage.filesystem for python3

This commit is contained in:
Lee Miller 2023-09-21 03:06:24 +03:00
parent 8af1a13e10
commit a629c15f7d
Signed by untrusted user: lee.miller
GPG Key ID: 4F97A5EA88F4AB63

View File

@ -2,7 +2,6 @@
Module for using filesystem (directory with files) for inventory storage Module for using filesystem (directory with files) for inventory storage
""" """
import logging import logging
import string
import time import time
from binascii import hexlify, unhexlify from binascii import hexlify, unhexlify
from os import listdir, makedirs, path, remove, rmdir from os import listdir, makedirs, path, remove, rmdir
@ -71,7 +70,7 @@ class FilesystemInventory(InventoryStorage):
makedirs(path.join( makedirs(path.join(
self.baseDir, self.baseDir,
FilesystemInventory.objectDir, FilesystemInventory.objectDir,
hexlify(hashval))) hexlify(hashval).decode()))
except OSError: except OSError:
pass pass
try: try:
@ -79,7 +78,7 @@ class FilesystemInventory(InventoryStorage):
path.join( path.join(
self.baseDir, self.baseDir,
FilesystemInventory.objectDir, FilesystemInventory.objectDir,
hexlify(hashval), hexlify(hashval).decode(),
FilesystemInventory.metadataFilename, FilesystemInventory.metadataFilename,
), ),
"w", "w",
@ -88,15 +87,15 @@ class FilesystemInventory(InventoryStorage):
value.type, value.type,
value.stream, value.stream,
value.expires, value.expires,
hexlify(value.tag))) hexlify(value.tag).decode()))
with open( with open(
path.join( path.join(
self.baseDir, self.baseDir,
FilesystemInventory.objectDir, FilesystemInventory.objectDir,
hexlify(hashval), hexlify(hashval).decode(),
FilesystemInventory.dataFilename, FilesystemInventory.dataFilename,
), ),
"w", "wb",
) as f: ) as f:
f.write(value.payload) f.write(value.payload)
except IOError: except IOError:
@ -120,7 +119,7 @@ class FilesystemInventory(InventoryStorage):
path.join( path.join(
self.baseDir, self.baseDir,
FilesystemInventory.objectDir, FilesystemInventory.objectDir,
hexlify(hashval), hexlify(hashval).decode(),
FilesystemInventory.metadataFilename)) FilesystemInventory.metadataFilename))
except IOError: except IOError:
pass pass
@ -129,7 +128,7 @@ class FilesystemInventory(InventoryStorage):
path.join( path.join(
self.baseDir, self.baseDir,
FilesystemInventory.objectDir, FilesystemInventory.objectDir,
hexlify(hashval), hexlify(hashval).decode(),
FilesystemInventory.dataFilename)) FilesystemInventory.dataFilename))
except IOError: except IOError:
pass pass
@ -137,7 +136,7 @@ class FilesystemInventory(InventoryStorage):
rmdir(path.join( rmdir(path.join(
self.baseDir, self.baseDir,
FilesystemInventory.objectDir, FilesystemInventory.objectDir,
hexlify(hashval))) hexlify(hashval).decode()))
except IOError: except IOError:
pass pass
@ -189,7 +188,7 @@ class FilesystemInventory(InventoryStorage):
path.join( path.join(
self.baseDir, self.baseDir,
FilesystemInventory.objectDir, FilesystemInventory.objectDir,
hexlify(hashId), hexlify(hashId).decode(),
FilesystemInventory.dataFilename, FilesystemInventory.dataFilename,
), ),
"r", "r",
@ -205,13 +204,13 @@ class FilesystemInventory(InventoryStorage):
path.join( path.join(
self.baseDir, self.baseDir,
FilesystemInventory.objectDir, FilesystemInventory.objectDir,
hexlify(hashId), hexlify(hashId).decode(),
FilesystemInventory.metadataFilename, FilesystemInventory.metadataFilename,
), ),
"r", "r",
) as f: ) as f:
objectType, streamNumber, expiresTime, tag = string.split( objectType, streamNumber, expiresTime, tag = f.read().split(
f.read(), ",", 4)[:4] ",", 4)[:4]
return [ return [
int(objectType), int(objectType),
int(streamNumber), int(streamNumber),