changeset 3980:3648a2b2e17a

accept that repos are read-only - very convenient for testing. Users are prompt to confirm they want to use read only paths. org author: Mads Kiilerich
author Marcin Kuzminski <marcin@python-works.com>
date Mon, 10 Jun 2013 14:54:37 +0200
parents 04242759b61e
children 4c78da22dbbb
files rhodecode/lib/db_manage.py rhodecode/lib/utils.py rhodecode/model/scm.py
diffstat 3 files changed, 25 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/lib/db_manage.py	Wed Jun 12 10:21:56 2013 +0200
+++ b/rhodecode/lib/db_manage.py	Mon Jun 10 14:54:37 2013 +0200
@@ -614,16 +614,24 @@
         # check proper dir
         if not os.path.isdir(path):
             path_ok = False
-            log.error('Given path %s is not a valid directory' % path)
+            log.error('Given path %s is not a valid directory' % (path,))
 
         elif not os.path.isabs(path):
             path_ok = False
-            log.error('Given path %s is not an absolute path' % path)
+            log.error('Given path %s is not an absolute path' % (path,))
+
+        # check if path is at least readable.
+        if not os.access(path, os.R_OK):
+            path_ok = False
+            log.error('Given path %s is not readable' % (path,))
 
-        # check write access
+        # check write access, warn user about non writeable paths
         elif not os.access(path, os.W_OK) and path_ok:
-            path_ok = False
-            log.error('No write permission to given path %s' % path)
+            log.warn('No write permission to given path %s' % (path,))
+            if not ask_ok('Given path %s is not writeable, do you want to '
+                          'continue with read only mode ? [y/n]' % (path,)):
+                log.error('Canceled by user')
+                sys.exit(-1)
 
         if retries == 0:
             sys.exit('max retries reached')
@@ -635,7 +643,7 @@
 
         if real_path != os.path.normpath(path):
             if not ask_ok(('Path looks like a symlink, Rhodecode will store '
-                           'given path as %s ? [y/n]') % (real_path)):
+                           'given path as %s ? [y/n]') % (real_path,)):
                 log.error('Canceled by user')
                 sys.exit(-1)
 
--- a/rhodecode/lib/utils.py	Wed Jun 12 10:21:56 2013 +0200
+++ b/rhodecode/lib/utils.py	Mon Jun 10 14:54:37 2013 +0200
@@ -201,9 +201,11 @@
     log.debug('now scanning in %s location recursive:%s...' % (path, recursive))
 
     def _get_repos(p):
+        if not os.access(p, os.R_OK) or not os.access(p, os.X_OK):
+            log.warn('ignoring repo path without access: %s', p)
+            return
         if not os.access(p, os.W_OK):
-            log.warn('ignoring repo path without write access: %s', p)
-            return
+            log.warn('repo path without write access: %s', p)
         for dirpath in os.listdir(p):
             if os.path.isfile(os.path.join(p, dirpath)):
                 continue
--- a/rhodecode/model/scm.py	Wed Jun 12 10:21:56 2013 +0200
+++ b/rhodecode/model/scm.py	Mon Jun 10 14:54:37 2013 +0200
@@ -744,9 +744,12 @@
 
             if _rhodecode_hook or force_create:
                 log.debug('writing %s hook file !' % (h_type,))
-                with open(_hook_file, 'wb') as f:
-                    tmpl = tmpl.replace('_TMPL_', rhodecode.__version__)
-                    f.write(tmpl)
-                os.chmod(_hook_file, 0755)
+                try:
+                    with open(_hook_file, 'wb') as f:
+                        tmpl = tmpl.replace('_TMPL_', rhodecode.__version__)
+                        f.write(tmpl)
+                    os.chmod(_hook_file, 0755)
+                except IOError, e:
+                    log.error('error writing %s: %s' % (_hook_file, e))
             else:
                 log.debug('skipping writing hook file')