Skip to content

Commit

Permalink
apps: create cache directory when caching app names
Browse files Browse the repository at this point in the history
fix #45
  • Loading branch information
rossengeorgiev committed Dec 22, 2021
1 parent 0b37e20 commit ddc084a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion steamctl/commands/apps/gcmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def init_client(args):
s.disconnect()

def get_app_names():
papps = SqliteDict(UserCacheFile("app_names.sqlite3").path)
papps = SqliteDict(UserCacheFile("app_names.sqlite3"))

try:
last = int(papps[-7]) # use a key that will never be used
Expand Down
9 changes: 8 additions & 1 deletion steamctl/utils/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,17 @@ def __repr__(self):
def exists(self):
return os.path.exists(self.path)

def mkdir(self):
ensure_dir(self.path, 0o700)

def older_than(seconds=0, minutes=0, hours=0, days=0):
delta = seconds + (minutes*60) + (hours*3600) + (days*86400)
ts = os.path.getmtime(self.path)
return ts + delta > time()

def open(self, mode):
_LOG.debug("Opening file (%s): %s", mode, self.path)
ensure_dir(self.path, 0o700)
self.mkdir()
return open(self.path, mode)

def read_text(self):
Expand Down Expand Up @@ -164,6 +167,10 @@ class UserCacheDirectory(DirectoryBase):

class SqliteDict(UserDict):
def __init__(self, path=':memory:'):
if isinstance(path, FileBase):
path.mkdir()
path = path.path

self._db = sqlite3.connect(path)
self._db.execute('CREATE TABLE IF NOT EXISTS kv (key INTEGER PRIMARY KEY, value TEXT)')
self._db.commit()
Expand Down

0 comments on commit ddc084a

Please sign in to comment.