objectstore: record creation time in Object
When an new Object is created, save the creation time in a new metadata entry called `info`. A new property called `created` is added to inspect the creation date.
This commit is contained in:
parent
39d38d33fd
commit
b3c53e7275
1 changed files with 19 additions and 0 deletions
|
|
@ -4,6 +4,7 @@ import json
|
|||
import os
|
||||
import subprocess
|
||||
import tempfile
|
||||
import time
|
||||
from typing import Any, Optional, Set, Union
|
||||
|
||||
from osbuild.util import jsoncomm
|
||||
|
|
@ -140,6 +141,11 @@ class Object:
|
|||
wrapped = PathAdapter(self, "_path")
|
||||
self._meta = self.Metadata(wrapped, folder="meta")
|
||||
|
||||
if self.mode == Object.Mode.WRITE:
|
||||
self.meta.set("info", {
|
||||
"created": int(time.time()),
|
||||
})
|
||||
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_value, exc_tb):
|
||||
|
|
@ -177,6 +183,19 @@ class Object:
|
|||
assert self._meta
|
||||
return self._meta
|
||||
|
||||
@property
|
||||
def created(self) -> int:
|
||||
"""When was the object created
|
||||
|
||||
It is stored as `created` in the `info` metadata entry,
|
||||
and thus will also get overwritten if the metadata gets
|
||||
overwritten via `init()`.
|
||||
NB: only valid to access when the object is active.
|
||||
"""
|
||||
info = self.meta.get("info")
|
||||
assert info, "info metadata missing"
|
||||
return info["created"]
|
||||
|
||||
def finalize(self):
|
||||
if self.mode != Object.Mode.WRITE:
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue