Skip to content

Commit d77f29a

Browse files
committed
Merge pull request #46 from univ-of-utah-marriott-library-apple/dev
Rewrote path-creation system
2 parents 65e20dd + e396449 commit d77f29a

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

privacy_services_management/tcc_services.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -361,16 +361,38 @@ def __create(self, path):
361361

362362
self.logger.info("TCC.db file was expected at '{}' but was not found. Creating new TCC.db file...".format(path))
363363

364-
# Make sure our directory tree exists.
365-
local_created = False
366-
if not os.path.exists(os.path.dirname(path)):
367-
os.makedirs(os.path.dirname(path), int('700', 8))
368-
# If the user isn't root and we're adjusting their local database,
369-
# we'll fix some permissions.
364+
# Make sure our directory tree exists properly.
365+
chown_database = False
366+
# Check for existence of
367+
# .../Library/Application Support/com.apple.TCC/TCC.db
368+
if not os.path.isfile(path):
369+
database_dir = os.path.dirname(path)
370+
app_support_dir = os.path.dirname(database_dir)
371+
# Let's only bother with user permissions if this isn't a folder
372+
# owned by root.
370373
if self.user != 'root' and path == self.local_path:
371-
local_created = True
372-
database_dir = os.path.dirname(self.local_path)
373-
os.chown(database_dir, uid, gid)
374+
# We'll have to modify the permissions on 'TCC.db' later.
375+
chown_database = True
376+
# Check existence of
377+
# .../Library/Application Support/com.apple.TCC/
378+
if not os.path.isdir(database_dir):
379+
# Check existence of
380+
# .../Library/Application Support/
381+
if not os.path.isdir(app_support_dir):
382+
# Check that the 'Library' folder exists.
383+
if not os.path.isdir(os.path.dirname(app_support_dir)):
384+
# There's no 'Library' folder? Something isn't right.
385+
raise RuntimeError("No 'Library' directory found for database: {}".format(path))
386+
# Create and chown 'Application Support' folder.
387+
os.mkdir(app_support_dir, int('700', 8))
388+
os.chown(app_support_dir, uid, gid)
389+
# Create and chown the 'com.apple.TCC' folder.
390+
os.mkdir(database_dir, int('700', 8))
391+
os.chown(database_dir, uid, gid)
392+
else:
393+
# We're not dealing with a specific user's directory, so just
394+
# make the parent directories as needed and ignore permissions.
395+
os.makedirs(os.path.dirname(path), int('700', 8))
374396

375397
# Form an SQL connection with the file.
376398
connection = sqlite3.connect(path)
@@ -448,7 +470,7 @@ def __create(self, path):
448470
self.logger.info("TCC.db file created successfully.")
449471

450472
# The local database was created, so make sure permissions are set.
451-
if local_created:
473+
if chown_database:
452474
os.chown(self.local_path, uid, gid)
453475

454476
def __enter__(self):

privacy_services_management/universal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
attributes = {
66
'long_name': "Privacy Services Manager",
77
'name': "privacy_services_manager",
8-
'version': "1.7.1",
8+
'version': "1.7.2",
99
}
1010

1111
# This is a list of services which can be modified.

0 commit comments

Comments
 (0)