summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2014-03-04 18:52:54 +0000
committerLars Wirzenius <liw@liw.fi>2014-03-04 18:52:54 +0000
commit4424cd2dff6cc24b0dce107364a9f5592bd40352 (patch)
tree2c55d5faba6eaf7459091d6584b100620ec45cb5
parent99f862d19febbf1ab1ae89d4d3fbf1a7bf90ccde (diff)
downloadobnam-4424cd2dff6cc24b0dce107364a9f5592bd40352.tar.gz
Fix how metadata is compared
Two bugs fixed here. First was wrong naming of metadata fields (missing the st_ prefix). Second was not treating '' and None as the same value in xattr.
-rw-r--r--obnamlib/plugins/backup_plugin.py58
1 files changed, 39 insertions, 19 deletions
diff --git a/obnamlib/plugins/backup_plugin.py b/obnamlib/plugins/backup_plugin.py
index 5c08c9ed..b4512806 100644
--- a/obnamlib/plugins/backup_plugin.py
+++ b/obnamlib/plugins/backup_plugin.py
@@ -641,19 +641,19 @@ class BackupPlugin(obnamlib.ObnamPlugin):
tracing.trace('gen=%s' % repr(gen))
try:
old = obnamlib.Metadata(
- mtime_sec=self.repo.get_file_key(
+ st_mtime_sec=self.repo.get_file_key(
gen, pathname, obnamlib.REPO_FILE_MTIME_SEC),
- mtime_nsec=self.repo.get_file_key(
+ st_mtime_nsec=self.repo.get_file_key(
gen, pathname, obnamlib.REPO_FILE_MTIME_NSEC),
- mode=self.repo.get_file_key(
+ st_mode=self.repo.get_file_key(
gen, pathname, obnamlib.REPO_FILE_MODE),
- nlink=self.repo.get_file_key(
+ st_nlink=self.repo.get_file_key(
gen, pathname, obnamlib.REPO_FILE_NLINK),
- size=self.repo.get_file_key(
+ st_size=self.repo.get_file_key(
gen, pathname, obnamlib.REPO_FILE_SIZE),
- uid=self.repo.get_file_key(
+ st_uid=self.repo.get_file_key(
gen, pathname, obnamlib.REPO_FILE_UID),
- gid=self.repo.get_file_key(
+ st_gid=self.repo.get_file_key(
gen, pathname, obnamlib.REPO_FILE_GID),
xattr=self.repo.get_file_key(
gen, pathname, obnamlib.REPO_FILE_XATTR_BLOB))
@@ -665,18 +665,38 @@ class BackupPlugin(obnamlib.ObnamPlugin):
tracing.trace(traceback.format_exc())
return True
- needs = (current.st_mtime_sec != old.st_mtime_sec or
- current.st_mtime_nsec != old.st_mtime_nsec or
- current.st_mode != old.st_mode or
- current.st_nlink != old.st_nlink or
- current.st_size != old.st_size or
- current.st_uid != old.st_uid or
- current.st_gid != old.st_gid or
- current.xattr != old.xattr)
- if needs:
- tracing.trace(
- '%s has changed metadata, so needs backup' % pathname)
- return needs
+ must_be_equal = (
+ 'st_mtime_sec',
+ 'st_mtime_nsec',
+ 'st_mode',
+ 'st_nlink',
+ 'st_size',
+ 'st_uid',
+ 'st_gid',
+ )
+
+ for field in must_be_equal:
+ current_value = getattr(current, field)
+ old_value = getattr(old, field)
+ tracing.trace('current.%s=%r', field, current_value)
+ tracing.trace('old.%s=%r', field, old_value)
+ if current_value != old_value:
+ tracing.trace('NEED to backup %r', pathname)
+ return True
+
+ # Treat xattr values None (no extended attributes) and ''
+ # (there are no values, but the xattr blob exists as an empty
+ # string) as equal values.
+ xattr_current = current.xattr or None
+ xattr_old = old.xattr or None
+ tracing.trace('xattr_current=%r', xattr_current)
+ tracing.trace('xattr_old=%r', xattr_old)
+ if xattr_current != xattr_old:
+ tracing.trace('NEED to backup %r', pathname)
+ return True
+
+ tracing.trace('Do NOT need to backup %r', pathname)
+ return False
def add_file_to_generation(self, filename, metadata):
self.repo.add_file(self.new_generation, filename)