Commit bcabef29 authored by Tres Seaver's avatar Tres Seaver

Ensured that export/index files created by repozo share the same timestamp.

https://bugs.launchpad.net/zodb/+bug/993350
parent c0c6c6c3
...@@ -32,6 +32,11 @@ New Features ...@@ -32,6 +32,11 @@ New Features
Bugs Fixed Bugs Fixed
---------- ----------
- Ensured that the export file and index file created by ``repozo`` share
the same timestamp.
https://bugs.launchpad.net/zodb/+bug/993350
- Pinned the ``transaction`` and ``manuel`` dependencies to Python 2.5- - Pinned the ``transaction`` and ``manuel`` dependencies to Python 2.5-
compatible versions when installing under Python 2.5. compatible versions when installing under Python 2.5.
......
...@@ -305,7 +305,10 @@ def concat(files, ofp=None): ...@@ -305,7 +305,10 @@ def concat(files, ofp=None):
return bytesread, sum.hexdigest() return bytesread, sum.hexdigest()
def gen_filename(options, ext=None): def gen_filedate(options):
return getattr(options, 'test_now', time.gmtime()[:6])
def gen_filename(options, ext=None, now=None):
if ext is None: if ext is None:
if options.full: if options.full:
ext = '.fs' ext = '.fs'
...@@ -314,7 +317,8 @@ def gen_filename(options, ext=None): ...@@ -314,7 +317,8 @@ def gen_filename(options, ext=None):
if options.gzip: if options.gzip:
ext += 'z' ext += 'z'
# Hook for testing # Hook for testing
now = getattr(options, 'test_now', time.gmtime()[:6]) if now is None:
now = gen_filedate(options)
t = now + (ext,) t = now + (ext,)
return '%04d-%02d-%02d-%02d-%02d-%02d%s' % t return '%04d-%02d-%02d-%02d-%02d-%02d%s' % t
...@@ -330,7 +334,7 @@ del re ...@@ -330,7 +334,7 @@ del re
def find_files(options): def find_files(options):
when = options.date when = options.date
if not when: if not when:
when = gen_filename(options, '') when = gen_filename(options, ext='')
log('looking for files between last full backup and %s...', when) log('looking for files between last full backup and %s...', when)
all = filter(is_data_file, os.listdir(options.repository)) all = filter(is_data_file, os.listdir(options.repository))
all.sort() all.sort()
...@@ -429,7 +433,8 @@ def delete_old_backups(options): ...@@ -429,7 +433,8 @@ def delete_old_backups(options):
def do_full_backup(options): def do_full_backup(options):
options.full = True options.full = True
dest = os.path.join(options.repository, gen_filename(options)) tnow = gen_filedate(options)
dest = os.path.join(options.repository, gen_filename(options, now=tnow))
if os.path.exists(dest): if os.path.exists(dest):
raise WouldOverwriteFiles('Cannot overwrite existing file: %s' % dest) raise WouldOverwriteFiles('Cannot overwrite existing file: %s' % dest)
# Find the file position of the last completed transaction. # Find the file position of the last completed transaction.
...@@ -442,7 +447,7 @@ def do_full_backup(options): ...@@ -442,7 +447,7 @@ def do_full_backup(options):
pos = fs.getSize() pos = fs.getSize()
# Save the storage index into the repository # Save the storage index into the repository
index_file = os.path.join(options.repository, index_file = os.path.join(options.repository,
gen_filename(options, '.index')) gen_filename(options, '.index', tnow))
log('writing index') log('writing index')
fs._index.save(pos, index_file) fs._index.save(pos, index_file)
fs.close() fs.close()
...@@ -461,7 +466,8 @@ def do_full_backup(options): ...@@ -461,7 +466,8 @@ def do_full_backup(options):
def do_incremental_backup(options, reposz, repofiles): def do_incremental_backup(options, reposz, repofiles):
options.full = False options.full = False
dest = os.path.join(options.repository, gen_filename(options)) tnow = gen_filedate(options)
dest = os.path.join(options.repository, gen_filename(options, now=tnow))
if os.path.exists(dest): if os.path.exists(dest):
raise WouldOverwriteFiles('Cannot overwrite existing file: %s' % dest) raise WouldOverwriteFiles('Cannot overwrite existing file: %s' % dest)
# Find the file position of the last completed transaction. # Find the file position of the last completed transaction.
...@@ -474,7 +480,7 @@ def do_incremental_backup(options, reposz, repofiles): ...@@ -474,7 +480,7 @@ def do_incremental_backup(options, reposz, repofiles):
pos = fs.getSize() pos = fs.getSize()
log('writing index') log('writing index')
index_file = os.path.join(options.repository, index_file = os.path.join(options.repository,
gen_filename(options, '.index')) gen_filename(options, '.index', tnow))
fs._index.save(pos, index_file) fs._index.save(pos, index_file)
fs.close() fs.close()
log('writing incremental: %s bytes to %s', pos-reposz, dest) log('writing incremental: %s bytes to %s', pos-reposz, dest)
......
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