summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2010-07-04 11:25:42 +1200
committerLars Wirzenius <liw@liw.fi>2010-07-04 11:25:42 +1200
commit91f3cc5c6c5765cec49d9e5736beed628a2f4c59 (patch)
treebbb40c7c0fc45e885af77ad9245f541510392e93
parentfe33391ada080ead0b60f28b1d20824c8eff7593 (diff)
downloadobnam-91f3cc5c6c5765cec49d9e5736beed628a2f4c59.tar.gz
Add counter of written bytes to VFS.
-rw-r--r--obnamlib/vfs.py2
-rw-r--r--obnamlib/vfs_local.py2
-rw-r--r--obnamlib/vfs_local_tests.py11
3 files changed, 14 insertions, 1 deletions
diff --git a/obnamlib/vfs.py b/obnamlib/vfs.py
index b3fb62f1..82ec173e 100644
--- a/obnamlib/vfs.py
+++ b/obnamlib/vfs.py
@@ -45,7 +45,7 @@ class VirtualFileSystem(object):
"""
def __init__(self, baseurl):
- pass
+ self.written = 0
def connect(self):
"""Connect to filesystem."""
diff --git a/obnamlib/vfs_local.py b/obnamlib/vfs_local.py
index 4ed4cb23..7ba752e0 100644
--- a/obnamlib/vfs_local.py
+++ b/obnamlib/vfs_local.py
@@ -138,6 +138,7 @@ class LocalFS(obnamlib.VirtualFileSystem):
os.remove(name)
raise
os.remove(name)
+ self.written += len(contents)
def overwrite_file(self, pathname, contents, make_backup=True):
path = self.join(pathname)
@@ -167,6 +168,7 @@ class LocalFS(obnamlib.VirtualFileSystem):
os.remove(bak)
except OSError:
pass
+ self.written += len(contents)
def listdir(self, dirname):
return os.listdir(self.join(dirname))
diff --git a/obnamlib/vfs_local_tests.py b/obnamlib/vfs_local_tests.py
index 7c0d300a..dbbc841e 100644
--- a/obnamlib/vfs_local_tests.py
+++ b/obnamlib/vfs_local_tests.py
@@ -263,6 +263,17 @@ class LocalFSTests(unittest.TestCase):
self.fs.write_file("foo", "bar")
self.fs.overwrite_file("foo", "foobar")
self.assertEqual(self.fs.cat("foo"), "foobar")
+
+ def test_has_written_nothing_initially(self):
+ self.assertEqual(self.fs.written, 0)
+
+ def test_write_updates_written(self):
+ self.fs.write_file('foo', 'foo')
+ self.assertEqual(self.fs.written, 3)
+
+ def test_overwrite_updates_written(self):
+ self.fs.overwrite_file('foo', 'foo')
+ self.assertEqual(self.fs.written, 3)
class DepthFirstTests(unittest.TestCase):