Index: samesite.py ================================================================== --- samesite.py +++ samesite.py @@ -229,11 +229,11 @@ # everything else is just the headers index = shelve.open(config['dir'] + os.sep + '.index') desc_fields = const_desc_fields.copy() ignore_fields = const_ignore_fields.copy() - if not config['noetag']: + if config['noetag'] == 'no': desc_fields.add('ETag') else: ignore_fields.add('ETag') proxy_ignored = set([ @@ -279,21 +279,22 @@ info += '\nThis one is new.' reload = True record = {} else: # forcibly checking file if no file present + record = index[my_path] if os.access(file_name, os.R_OK): info += '\nFull file found.' file_stat = os.stat(file_name) elif '_parts' in index[my_path] and os.access(temp_name, os.R_OK): info += '\nPartial file found.' file_stat = os.stat(temp_name) + recheck = True else: info += '\nFile not found or inaccessible.' - index[my_path]['_parts'] = None + record['_parts'] = None reload = True - record = index[my_path] if not '_parts' in record: record['_parts'] = None if record['_parts'] == None: @@ -326,15 +327,15 @@ if header in self.headers: my_headers[header] = self.headers[header] needed = None if '_parts' in record and record['_parts'] != None: - if config['noparts'] or requested_ranges == None: + if config['noparts'] != 'no' or requested_ranges == None or requested_ranges == spacemap.SpaceMap(): needed = record['_parts'] else: needed = record['_parts'] | requested_ranges - elif not config['noparts']: + elif config['noparts'] =='no' and requested_ranges != None and requested_ranges != spacemap.SpaceMap(): needed = requested_ranges ranges = () print('Missing ranges: {}, requested ranges: {}, needed ranges: {}.'.format(record['_parts'], requested_ranges, needed)) if needed != None and len(needed) > 0: needed.rewind() @@ -451,18 +452,19 @@ buffer = source.read(req_block_size) length = len(buffer) # moving downloaded data to real file temp_file.close() - print(new_record) index[my_path] = new_record index.sync() except urllib.error.HTTPError as error: # in case of error we don't need to do anything actually, # if file download stalls or fails the file would not be moved to it's location print(error) + + print(index[my_path]) if not os.access(file_name, os.R_OK) and os.access(temp_name, os.R_OK) and '_parts' in index[my_path] and index[my_path]['_parts'] == spacemap.SpaceMap(): # just moving # drop old dirs XXX print('Moving temporary file to new destination.')