INNER CODE UNIT · Python
write_disk_cache
opentimestamps/opentimestamps-server · otsserver/backup.py:137
def write_disk_cache(self, chunk, bytes):
chunk_str = "{0:0>6}".format(chunk)
chunk_path = chunk_str[0:3]
cache_path = self.cache_path + '/' + chunk_path
os.makedirs(cache_path, exist_ok=True)
cache_file = cache_path + '/' + chunk_str
temp_file = NamedTemporaryFile(delete=False, dir=cache_path)
temp_file.write(bytes)
temp_file.close()
os.rename(temp_file.name, cache_file) # rename is atomic
# The following is a shrunk version of the standard calendar http server, it only support the '/timestamp' endpoint
# This way the backup server could serve request in place of the calendar serve which is backupping
class RPCRequestHandler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
if self.path.startswith('/timestamp/'):
self.get_timestamp()