MCPcopy Index your code
hub / github.com/sshuttle/sshuttle / read_host_cache

Function read_host_cache

sshuttle/hostwatch.py:64–90  ·  view source on GitHub ↗

If possible, read the cache file from disk to populate hosts that were found in a previous sshuttle run.

()

Source from the content-addressed store, hash-verified

62
63
64def read_host_cache():
65 """If possible, read the cache file from disk to populate hosts that
66 were found in a previous sshuttle run."""
67 try:
68 f = open(CACHEFILE)
69 except (OSError, IOError):
70 _, e = sys.exc_info()[:2]
71 if e.errno == errno.ENOENT:
72 return
73 else:
74 log("Failed to read existing host cache file %s on remote host"
75 % CACHEFILE)
76 return
77 for line in f:
78 words = line.strip().split(',')
79 if len(words) == 2:
80 (name, ip) = words
81 name = re.sub(r'[^-\w\.]', '-', name).strip()
82 # Remove characters that shouldn't be in IP
83 ip = re.sub(r'[^0-9.]', '', ip).strip()
84 if name and ip:
85 found_host(name, ip)
86 f.close()
87 global SHOULD_WRITE_CACHE
88 if SHOULD_WRITE_CACHE:
89 write_host_cache()
90 SHOULD_WRITE_CACHE = False
91
92
93def found_host(name, ip):

Callers 1

hw_mainFunction · 0.85

Calls 4

logFunction · 0.90
found_hostFunction · 0.85
write_host_cacheFunction · 0.85
closeMethod · 0.80

Tested by

no test coverage detected