From 1b15a7a26357d280d9497957183eb9cd8a099945 Mon Sep 17 00:00:00 2001 From: Michael Ziegler Date: Thu, 4 Mar 2010 08:59:16 +0100 Subject: [PATCH] move the database file to a db subdirectory, to get the perms right when people run "chmod -R /*" --- .hgignore | 2 ++ db/README.txt | 8 ++++++++ pyweb/mumble/management/__init__.py | 15 +++++++++++++++ pyweb/settings.py | 2 +- 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 db/README.txt diff --git a/.hgignore b/.hgignore index 538a18f..ddef0ed 100644 --- a/.hgignore +++ b/.hgignore @@ -2,6 +2,8 @@ syntax: glob *.pyc *.db3 +*.db3.bak +*.db3-journal *~ .directory .secret.txt diff --git a/db/README.txt b/db/README.txt new file mode 100644 index 0000000..239f868 --- /dev/null +++ b/db/README.txt @@ -0,0 +1,8 @@ +This file basically only exists to have HG keep the "db" directory. I +moved the DB to this subdirectory, because people keep running into +a "Cannot open database file" error which results from permissions +being set incorrectly. People mostly run "chown -R /*" instead +of "chown -R " and therefore run into these problems. + +When the db is in a subdir of , it matches the wildcard and +will then have correct permissions. diff --git a/pyweb/mumble/management/__init__.py b/pyweb/mumble/management/__init__.py index d66da50..59765dc 100644 --- a/pyweb/mumble/management/__init__.py +++ b/pyweb/mumble/management/__init__.py @@ -14,6 +14,10 @@ * GNU General Public License for more details. """ +from shutil import copy, move +from os.path import exists, join + +from django.conf import settings from django.db import connection from django.db.models import signals @@ -22,6 +26,14 @@ from mumble import models from update_schema import update_schema from server_detect import find_existing_instances + +if settings.DATABASE_ENGINE == "sqlite3": + # Move the DB to the db subdirectory if necessary. + oldpath = join( settings.MUMBLE_DJANGO_ROOT, "mumble-django.db3" ) + if not exists( settings.DATABASE_NAME ) and exists( oldpath ): + move( oldpath, settings.DATABASE_NAME ) + + cursor = connection.cursor() tablename = models.Mumble._meta.db_table @@ -38,6 +50,9 @@ else: uptodate = True if not uptodate: + if settings.DATABASE_ENGINE == "sqlite3": + # backup the db before the conversion. + copy( settings.DATABASE_NAME, settings.DATABASE_NAME+".bak" ) signals.post_syncdb.connect( update_schema, sender=models ); else: signals.post_syncdb.connect( find_existing_instances, sender=models ); diff --git a/pyweb/settings.py b/pyweb/settings.py index b49d862..a0f8796 100644 --- a/pyweb/settings.py +++ b/pyweb/settings.py @@ -106,7 +106,7 @@ MUNIN_CATEGORY = 'network' # Database settings for Mumble-Django's database. These do NOT need to point to Murmur's database, # Mumble-Django should use its own! DATABASE_ENGINE = 'sqlite3' -DATABASE_NAME = join( MUMBLE_DJANGO_ROOT, 'mumble-django.db3' ) +DATABASE_NAME = join( MUMBLE_DJANGO_ROOT, 'db', 'mumble-django.db3' ) DATABASE_USER = '' DATABASE_PASSWORD = '' DATABASE_HOST = ''