MCPcopy
hub / github.com/borgbackup/borg / _create_lock

Method _create_lock

src/borg/storelocking.py:98–110  ·  view source on GitHub ↗
(self, *, exclusive=None, update_last_refresh=False)

Source from the content-addressed store, hash-verified

96 return f"<{self.__class__.__name__}: {self.id!r}>"
97
98 def _create_lock(self, *, exclusive=None, update_last_refresh=False):
99 assert exclusive is not None
100 now = datetime.datetime.now(datetime.timezone.utc)
101 timestamp = now.isoformat(timespec="milliseconds")
102 lock = dict(exclusive=exclusive, hostid=self.id[0], processid=self.id[1], threadid=self.id[2], time=timestamp)
103 value = json.dumps(lock).encode("utf-8")
104 key = xxh64(value).hexdigest()
105 logger.debug(f"LOCK-CREATE: creating lock in store. key: {key}, lock: {lock}.")
106 self.store.store(f"locks/{key}", value)
107 if update_last_refresh:
108 # we parse the timestamp string to get *precisely* the datetime in the lock:
109 self.last_refresh_dt = datetime.datetime.fromisoformat(timestamp)
110 return key
111
112 def _delete_lock(self, key, *, ignore_not_found=False, update_last_refresh=False):
113 logger.debug(f"LOCK-DELETE: deleting lock from store. key: {key}.")

Callers 3

acquireMethod · 0.95
migrate_lockMethod · 0.95
refreshMethod · 0.95

Calls 3

isoformatMethod · 0.80
hexdigestMethod · 0.80
debugMethod · 0.80

Tested by

no test coverage detected