]> arthur.barton.de Git - bup.git/commitdiff
Calling bup-server with "-r host:" fails to activate dumb mode.
authorOei, Yung-Chin <yungchin@yungchin.nl>
Tue, 18 Sep 2012 13:13:13 +0000 (14:13 +0100)
committerRob Browning <rlb@defaultvalue.org>
Mon, 24 Sep 2012 20:04:03 +0000 (15:04 -0500)
When no remote directory is supplied to the -r option, no set-dir
command is sent to the server. This has the weird side effect that the
server actually does not check whether it needs to be in "smart" or
"dumb" mode.

By forcing all commands to make that verification, we'll ensure that the
server mode is correct.

Signed-off-by: Yung-Chin Oei <yungchin@yungchin.nl>
Reviewed-by: Gabriel Filion <lelutin@gmail.com>
Reviewed-by: Zoran Zaric <zz@zoranzaric.de>
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
cmd/server-cmd.py

index a9d742ca7c6f6c81077f25f39a1fbcdb68bdeb54..43a3fce5c1a0539bb3552be243f8108a0c1c983d 100755 (executable)
@@ -19,25 +19,31 @@ def _set_mode():
            % (dumb_server_mode and 'dumb' or 'smart'))
 
 
+def _init_session(reinit_with_new_repopath=None):
+    if reinit_with_new_repopath is None and git.repodir:
+        return
+    git.check_repo_or_die(reinit_with_new_repopath)
+    # OK. we now know the path is a proper repository. Record this path in the
+    # environment so that subprocesses inherit it and know where to operate.
+    os.environ['BUP_DIR'] = git.repodir
+    debug1('bup server: bupdir is %r\n' % git.repodir)
+    _set_mode()
+
+
 def init_dir(conn, arg):
     git.init_repo(arg)
     debug1('bup server: bupdir initialized: %r\n' % git.repodir)
-    _set_mode()
+    _init_session(arg)
     conn.ok()
 
 
 def set_dir(conn, arg):
-    git.check_repo_or_die(arg)
-    # OK. we now know the path is a proper repository. Record this path in the
-    # environment so that subprocesses inherit it and know where to operate.
-    os.environ['BUP_DIR'] = arg
-    debug1('bup server: bupdir is %r\n' % git.repodir)
-    _set_mode()
+    _init_session(arg)
     conn.ok()
 
     
 def list_indexes(conn, junk):
-    git.check_repo_or_die()
+    _init_session()
     suffix = ''
     if dumb_server_mode:
         suffix = ' load'
@@ -48,7 +54,7 @@ def list_indexes(conn, junk):
 
 
 def send_index(conn, name):
-    git.check_repo_or_die()
+    _init_session()
     assert(name.find('/') < 0)
     assert(name.endswith('.idx'))
     idx = git.open_idx(git.repo('objects/pack/%s' % name))
@@ -59,7 +65,7 @@ def send_index(conn, name):
 
 def receive_objects_v2(conn, junk):
     global suspended_w
-    git.check_repo_or_die()
+    _init_session()
     suggested = set()
     if suspended_w:
         w = suspended_w
@@ -123,14 +129,14 @@ def _check(w, expected, actual, msg):
 
 
 def read_ref(conn, refname):
-    git.check_repo_or_die()
+    _init_session()
     r = git.read_ref(refname)
     conn.write('%s\n' % (r or '').encode('hex'))
     conn.ok()
 
 
 def update_ref(conn, refname):
-    git.check_repo_or_die()
+    _init_session()
     newval = conn.readline().strip()
     oldval = conn.readline().strip()
     git.update_ref(refname, newval.decode('hex'), oldval.decode('hex'))
@@ -140,7 +146,7 @@ def update_ref(conn, refname):
 cat_pipe = None
 def cat(conn, id):
     global cat_pipe
-    git.check_repo_or_die()
+    _init_session()
     if not cat_pipe:
         cat_pipe = git.CatPipe()
     try: