Skip to content

Commit ef1e0e2

Browse files
committed
Also look for caches.json in /etc/stashcache and /usr/share/stashcache
1 parent 40efc9a commit ef1e0e2

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

bin/stashcp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -374,19 +374,19 @@ def get_ips(name):
374374
return ipv4s + ipv6s
375375

376376
def get_best_stashcache():
377-
378-
# First, check for caches.json file in this file's directory:
379-
dir_path = os.path.dirname(os.path.realpath(__file__))
380-
cache_file = os.path.join(dir_path, 'caches.json')
381-
if not os.path.isfile(cache_file):
382-
logging.error("Unable to find caches.json in %s", dir_path)
377+
cache_files = [os.path.join(os.path.dirname(os.path.realpath(__file__)), "caches.json"),
378+
"/etc/stashcache/caches.json",
379+
"/usr/share/stashcache/caches.json"]
380+
for cache_file in cache_files:
381+
if os.path.isfile(cache_file):
382+
with open(cache_file, 'r') as f:
383+
caches_list = json.loads(f.read())
384+
logging.debug("Loaded caches list from %s", cache_file)
385+
break
386+
else:
387+
logging.error("Unable to find caches.json in %r", cache_files)
383388
return None
384-
385-
# Get all the caches from the json file
386-
f = open(cache_file, 'r')
387-
caches_list = json.loads(f.read())
388-
f.close()
389-
389+
390390
# Format the caches for the GeoIP query
391391
caches_string = ""
392392
usable_caches = []

0 commit comments

Comments
 (0)