MCPcopy Index your code
hub / github.com/sqlmapproject/sqlmap / flush

Method flush

lib/utils/hashdb.py:136–177  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

134 self.flush()
135
136 def flush(self):
137 with self._cache_lock:
138 if not self._write_cache:
139 return
140
141 flush_cache = self._write_cache
142 self._write_cache = {}
143 self._last_flush_time = time.time()
144
145 try:
146 self.beginTransaction()
147 for hash_, value in flush_cache.items():
148 retries = 0
149 while True:
150 try:
151 try:
152 self.cursor.execute("INSERT INTO storage VALUES (?, ?)", (hash_, value,))
153 except sqlite3.IntegrityError:
154 self.cursor.execute("UPDATE storage SET value=? WHERE id=?", (value, hash_,))
155 except (UnicodeError, OverflowError): # e.g. surrogates not allowed (Issue #3851)
156 break
157 except sqlite3.DatabaseError as ex:
158 if not os.path.exists(self.filepath):
159 debugMsg = "session file '%s' does not exist" % self.filepath
160 logger.debug(debugMsg)
161 break
162
163 # NOTE: skipping the retries == 0 for graceful resolution of multi-threaded runs
164 if retries == 1:
165 warnMsg = "there has been a problem while writing to "
166 warnMsg += "the session file ('%s')" % getSafeExString(ex)
167 logger.warning(warnMsg)
168
169 if retries >= HASHDB_FLUSH_RETRIES:
170 return
171 else:
172 retries += 1
173 time.sleep(1)
174 else:
175 break
176 finally:
177 self.endTransaction()
178
179 def beginTransaction(self):
180 threadData = getCurrentThreadData()

Callers 1

writeMethod · 0.95

Calls 6

beginTransactionMethod · 0.95
endTransactionMethod · 0.95
getSafeExStringFunction · 0.90
itemsMethod · 0.80
debugMethod · 0.80
executeMethod · 0.45

Tested by

no test coverage detected