MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _commit

Method _commit

tools/python-3.11.9-amd64/Lib/dbm/dumb.py:113–136  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

111 # file (if any) is renamed with a .bak extension first. If a .bak
112 # file currently exists, it's deleted.
113 def _commit(self):
114 # CAUTION: It's vital that _commit() succeed, and _commit() can
115 # be called from __del__(). Therefore we must never reference a
116 # global in this routine.
117 if self._index is None or not self._modified:
118 return # nothing to do
119
120 try:
121 self._os.unlink(self._bakfile)
122 except OSError:
123 pass
124
125 try:
126 self._os.rename(self._dirfile, self._bakfile)
127 except OSError:
128 pass
129
130 with self._io.open(self._dirfile, 'w', encoding="Latin-1") as f:
131 self._chmod(self._dirfile)
132 for key, pos_and_siz_pair in self._index.items():
133 # Use Latin-1 since it has no qualms with any value in any
134 # position; UTF-8, though, does care sometimes.
135 entry = "%r, %r\n" % (key.decode('Latin-1'), pos_and_siz_pair)
136 f.write(entry)
137
138 sync = _commit
139

Callers 2

__delitem__Method · 0.95
closeMethod · 0.95

Calls 7

_chmodMethod · 0.95
unlinkMethod · 0.45
renameMethod · 0.45
openMethod · 0.45
itemsMethod · 0.45
decodeMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected