Index: samesite.py ================================================================== --- samesite.py +++ samesite.py @@ -45,11 +45,11 @@ 'Date', 'Expires', 'Referer', 'Server', 'Via', - 'X-Cache', 'X-Cache-Lookup', 'X-Livetool', 'X-Powered-By', + 'X-CCC', 'X-CID', 'X-Cache', 'X-Cache-Lookup', 'X-Livetool', 'X-Powered-By', ]) block_size = 8192 import bsddb3.dbshelve, copy, datetime, http.server, spacemap, urllib.request, urllib.error @@ -298,10 +298,11 @@ os.renames(empty_name, temp_name) temp_file = open(temp_name, 'r+b') if requested_ranges == None and needed == None: needed = new_record['_parts'] needed.rewind() + countdown = 16 while True: # XXX can make this implicit - one request per range (start, end) = needed.pop() if start == None: break @@ -318,12 +319,15 @@ assert stream_pos <= end, 'Received more data then requested: pos:{} start:{} end:{}.'.format(stream_pos, start, end) temp_file.seek(stream_last) temp_file.write(buffer) x = new_record['_parts'] - spacemap.SpaceMap({stream_last: stream_pos}) new_record['_parts'] = new_record['_parts'] - spacemap.SpaceMap({stream_last: stream_pos}) - index[my_path_b] = old_record - index.sync() + countdown -= 1 + if countdown == 0: + index[my_path_b] = old_record + index.sync() + countdown = 16 old_record = copy.copy(new_record) stream_last = stream_pos if end - stream_last < block_size: req_block_size = end - stream_last buffer = source.read(req_block_size) @@ -340,11 +344,11 @@ self.send_response(error.code) self.end_headers() print(error, repr(my_headers)) return - print(index[my_path_b]) + #print(index[my_path_b]) if not os.access(file_name, os.R_OK) and os.access(temp_name, os.R_OK) and '_parts' in index[my_path_b] and index[my_path_b]['_parts'] == spacemap.SpaceMap(): # just moving # drop old dirs XXX print('Moving temporary file to new destination.')