MCPcopy Index your code
hub / github.com/RustPython/RustPython / _commit

Method _commit

Lib/dbm/dumb.py:114–138  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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

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