Skip to content

Commit e02d236

Browse files
committed
fail softly saving backup data and allow the feature to be turned off
1 parent 2e8867c commit e02d236

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/pyff/resource.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ def errors(self):
296296
return []
297297

298298
def load_backup(self):
299+
if config.local_copy_dir is None:
300+
return None
301+
299302
try:
300303
return resource_string(self.local_copy_fn)
301304
log.warn("Got status={:d} while getting {}. Fallback to local copy.".format(r.status_code, self.url))
@@ -307,6 +310,13 @@ def load_backup(self):
307310
)
308311
return None
309312

313+
def save_backup(self):
314+
if config.local_copy_dir is not None:
315+
try:
316+
safe_write(self.local_copy_fn, data, True)
317+
except IOError as ex:
318+
log.warn("unable to save backup copy of {}: {}".format(self.url, ex))
319+
310320
def load_resource(self, getter):
311321
data: Optional[str] = None
312322
status: Optional[int] = None
@@ -363,7 +373,7 @@ def parse(self, getter):
363373

364374
if status != 218: # write backup unless we just loaded from backup
365375
self.last_seen = utc_now().replace(microsecond=0)
366-
safe_write(self.local_copy_fn, data, True)
376+
self.save_backup()
367377

368378
info['State'] = 'Parsed'
369379
if self.t is not None:

0 commit comments

Comments
 (0)