summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2013-04-29 16:54:34 -0300
committerdrebs <drebs@leap.se>2013-04-29 16:54:34 -0300
commitdf2ab40939dac3051371e44e4c66312ec693be15 (patch)
treeec770013cfd2ff2231ce4b42f2b998026c2c09d5 /src
parent7d01d932a6cc3ae4e673bc8facacc4c2f2953864 (diff)
Add checks, exceptions and warnings for directory creation.
Diffstat (limited to 'src')
-rw-r--r--src/leap/soledad/__init__.py28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/leap/soledad/__init__.py b/src/leap/soledad/__init__.py
index 31b3a41b..fe85bab9 100644
--- a/src/leap/soledad/__init__.py
+++ b/src/leap/soledad/__init__.py
@@ -32,6 +32,7 @@ import hashlib
import configparser
import re
import binascii
+import logging
try:
import simplejson as json
except ImportError:
@@ -53,6 +54,13 @@ from leap.soledad.shared_db import SoledadSharedDatabase
from leap.soledad.crypto import SoledadCrypto
+logger = logging.getLogger(name=__name__)
+
+
+#
+# Exceptions
+#
+
class KeyDoesNotExist(Exception):
"""
Soledad attempted to find a key that does not exist locally.
@@ -65,9 +73,15 @@ class KeyAlreadyExists(Exception):
"""
-#-----------------------------------------------------------------------------
+class NotADirectory(Exception):
+ """
+ Expected a path for a directory but got some other thing.
+ """
+
+
+#
# Soledad: local encrypted storage and remote encrypted sync.
-#-----------------------------------------------------------------------------
+#
class Soledad(object):
"""
@@ -235,8 +249,14 @@ class Soledad(object):
lambda x: os.path.dirname(x),
[self._config.get_local_db_path(), self._config.get_secret_path()])
for path in paths:
- if not os.path.isdir(path):
- os.makedirs(path)
+ if not os.path.isfile(path):
+ if not os.path.isdir(path):
+ logger.info('Creating directory: %s.' % path)
+ os.makedirs(path)
+ else:
+ logger.warning('Using existent directory: %s.' % path)
+ else:
+ raise NotADirectory(path)
def _init_keys(self):
"""