From 0eb3504e9ad67cea4cd808fd7edb7f4ec862264d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20H=C3=A4hnke?= Date: Mon, 21 Oct 2019 19:54:24 -0500 Subject: [PATCH] Enable SQLite database creation in current directory Fixes #155 --- pastepwn/database/sqlitedb.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pastepwn/database/sqlitedb.py b/pastepwn/database/sqlitedb.py index 178e2bd..ef4861a 100644 --- a/pastepwn/database/sqlitedb.py +++ b/pastepwn/database/sqlitedb.py @@ -15,10 +15,14 @@ def __init__(self, dbpath="pastepwn"): self.logger.debug("Initializing SQLite - {0}".format(dbpath)) # Check if the folder path exists - if not os.path.exists(os.path.dirname(dbpath)): + if not os.path.exists(dbpath): # If not, create the path and the file - os.mkdir(os.path.dirname(dbpath)) + dbdir = os.path.dirname(dbpath) + if dbdir != '': + os.mkdir(dbdir) open(self.dbpath, "a").close() + elif os.path.isdir(dbpath): + raise ValueError('\'{0}\' is a directory. Use different path/name for database.'.format(dbpath)) try: self.db = sqlite3.connect(dbpath, check_same_thread=False)