If possible, read the cache file from disk to populate hosts that were found in a previous sshuttle run.
()
| 62 | |
| 63 | |
| 64 | def 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 | |
| 93 | def found_host(name, ip): |
no test coverage detected