Skip to content

Commit 04c1e35

Browse files
committed
fix: Create storage dir if none found
1 parent 0e00f00 commit 04c1e35

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
from abi.services.cache.CacheService import CacheService
22
from abi.services.cache.adapters.secondary.CacheFSAdapter import CacheFSAdapter
33

4-
from abi.utils.Storage import find_storage_folder
4+
from abi.utils.Storage import find_storage_folder, NoStorageFolderFound
55
import os
66

77
class CacheFactory:
88
@staticmethod
99
def CacheFS_find_storage(subpath: str = "cache", needle: str = "storage") -> CacheService:
1010
if not subpath.startswith("cache"):
1111
subpath = os.path.join("cache", subpath)
12-
return CacheService(CacheFSAdapter(os.path.join(find_storage_folder(os.getcwd(), needle), subpath)))
12+
13+
try:
14+
return CacheService(CacheFSAdapter(os.path.join(find_storage_folder(os.getcwd(), needle), subpath)))
15+
except NoStorageFolderFound as _:
16+
# Create a "storage" folder for the cache
17+
os.makedirs(os.path.join(os.getcwd(), "storage"), exist_ok=True)
18+
return CacheService(CacheFSAdapter(os.path.join(find_storage_folder(os.getcwd(), needle), subpath)))

lib/abi/utils/Storage.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import os
22

3+
class NoStorageFolderFound(Exception):
4+
pass
35

46
# Look for a "storage" folder until we reach /
57
def find_storage_folder(base_path: str, needle: str = "storage") -> str:
68
if os.path.exists(os.path.join(base_path, needle)):
79
return os.path.join(base_path, needle)
810

911
if base_path == "/":
10-
raise Exception("No storage folder found")
12+
raise NoStorageFolderFound("No storage folder found")
1113

1214
return find_storage_folder(os.path.dirname(base_path))
1315

0 commit comments

Comments
 (0)