#!/usr/bin/env python
-import sys, struct
+import os, sys, struct
from bup import options, git
from bup.helpers import *
suspended_w = None
+dumb_server_mode = False
+
+def _set_mode():
+ global dumb_server_mode
+ dumb_server_mode = os.path.exists(git.repo('bup-dumb-server'))
+ debug1('bup server: serving in %s mode\n'
+ % (dumb_server_mode and 'dumb' or 'smart'))
def init_dir(conn, arg):
git.init_repo(arg)
debug1('bup server: bupdir initialized: %r\n' % git.repodir)
+ _set_mode()
conn.ok()
def set_dir(conn, arg):
git.check_repo_or_die(arg)
debug1('bup server: bupdir is %r\n' % git.repodir)
+ _set_mode()
conn.ok()
def list_indexes(conn, junk):
git.check_repo_or_die()
+ suffix = ''
+ if dumb_server_mode:
+ suffix = ' load'
for f in os.listdir(git.repo('objects/pack')):
if f.endswith('.idx'):
- conn.write('%s\n' % f)
+ conn.write('%s%s\n' % (f, suffix))
conn.ok()
if not n:
debug1('bup server: received %d object%s.\n'
% (w.count, w.count!=1 and "s" or ''))
- fullpath = w.close()
+ fullpath = w.close(run_midx=not dumb_server_mode)
if fullpath:
(dir, name) = os.path.split(fullpath)
conn.write('%s.idx\n' % name)
w.abort()
raise Exception('object read: expected %d bytes, got %d\n'
% (n, len(buf)))
- oldpack = w.exists(shar)
+ if dumb_server_mode:
+ oldpack = None
+ else:
+ oldpack = w.exists(shar)
# FIXME: we only suggest a single index per cycle, because the client
# is currently too dumb to download more than one per cycle anyway.
# Actually we should fix the client, but this is a minor optimization