Commit 7ee7c920 authored by Jim Fulton's avatar Jim Fulton

Merged the tseaver-better_repozo_tests branch.

parent c36d4c48
...@@ -93,6 +93,9 @@ READCHUNK = 16 * 1024 ...@@ -93,6 +93,9 @@ READCHUNK = 16 * 1024
VERBOSE = False VERBOSE = False
class WouldOverwriteFiles(Exception):
pass
def usage(code, msg=''): def usage(code, msg=''):
outfp = sys.stderr outfp = sys.stderr
if code == 0: if code == 0:
...@@ -301,7 +304,9 @@ def gen_filename(options, ext=None): ...@@ -301,7 +304,9 @@ def gen_filename(options, ext=None):
ext = '.deltafs' ext = '.deltafs'
if options.gzip: if options.gzip:
ext += 'z' ext += 'z'
t = time.gmtime()[:6] + (ext,) # Hook for testing
now = getattr(options, 'test_now', time.gmtime()[:6])
t = now + (ext,)
return '%04d-%02d-%02d-%02d-%02d-%02d%s' % t return '%04d-%02d-%02d-%02d-%02d-%02d%s' % t
# Return a list of files needed to reproduce state at time options.date. # Return a list of files needed to reproduce state at time options.date.
...@@ -419,8 +424,7 @@ def do_full_backup(options): ...@@ -419,8 +424,7 @@ def do_full_backup(options):
options.full = True options.full = True
dest = os.path.join(options.repository, gen_filename(options)) dest = os.path.join(options.repository, gen_filename(options))
if os.path.exists(dest): if os.path.exists(dest):
print >> sys.stderr, 'Cannot overwrite existing file:', dest raise WouldOverwriteFiles('Cannot overwrite existing file: %s' % dest)
sys.exit(2)
log('writing full backup: %s bytes to %s', pos, dest) log('writing full backup: %s bytes to %s', pos, dest)
sum = copyfile(options, dest, 0, pos) sum = copyfile(options, dest, 0, pos)
# Write the data file for this full backup # Write the data file for this full backup
...@@ -447,8 +451,7 @@ def do_incremental_backup(options, reposz, repofiles): ...@@ -447,8 +451,7 @@ def do_incremental_backup(options, reposz, repofiles):
options.full = False options.full = False
dest = os.path.join(options.repository, gen_filename(options)) dest = os.path.join(options.repository, gen_filename(options))
if os.path.exists(dest): if os.path.exists(dest):
print >> sys.stderr, 'Cannot overwrite existing file:', dest raise WouldOverwriteFiles('Cannot overwrite existing file: %s' % dest)
sys.exit(2)
log('writing incremental: %s bytes to %s', pos-reposz, dest) log('writing incremental: %s bytes to %s', pos-reposz, dest)
sum = copyfile(options, dest, reposz, pos - reposz) sum = copyfile(options, dest, reposz, pos - reposz)
# The first file in repofiles points to the last full backup. Use this to # The first file in repofiles points to the last full backup. Use this to
...@@ -570,7 +573,11 @@ def main(argv=None): ...@@ -570,7 +573,11 @@ def main(argv=None):
argv = sys.argv[1:] argv = sys.argv[1:]
options = parseargs(argv) options = parseargs(argv)
if options.mode == BACKUP: if options.mode == BACKUP:
do_backup(options) try:
do_backup(options)
except WouldOverwriteFiles, e:
print >> sys.stderr, str(e)
sys.exit(2)
else: else:
assert options.mode == RECOVER assert options.mode == RECOVER
do_recover(options) do_recover(options)
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment