From ef0a6c3015002712cd584892027869196de91cb4 Mon Sep 17 00:00:00 2001
From: David-Sarah Hopwood <david-sarah@jacaranda.org>
Date: Wed, 20 Mar 2013 00:57:50 +0000
Subject: [PATCH] Avoid double-counting source files in 'tahoe cp --verbose'.
 fixes #1783

Signed-off-by: David-Sarah Hopwood <david-sarah@jacaranda.org>
---
 src/allmydata/scripts/tahoe_cp.py |  1 -
 src/allmydata/test/test_cli.py    | 28 ++++++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/src/allmydata/scripts/tahoe_cp.py b/src/allmydata/scripts/tahoe_cp.py
index f2f8c922..1ad460d8 100644
--- a/src/allmydata/scripts/tahoe_cp.py
+++ b/src/allmydata/scripts/tahoe_cp.py
@@ -652,7 +652,6 @@ class Copier:
 
         for (name,s) in source_files:
             self.attach_to_target(s, name, target)
-            self.files_to_copy += 1
 
         for source in source_dirs:
             self.assign_targets(source, target)
diff --git a/src/allmydata/test/test_cli.py b/src/allmydata/test/test_cli.py
index ccf5fddc..333da02a 100644
--- a/src/allmydata/test/test_cli.py
+++ b/src/allmydata/test/test_cli.py
@@ -2468,6 +2468,34 @@ class Cp(GridTestMixin, CLITestMixin, unittest.TestCase):
         d.addCallback(_got_testdir_json)
         return d
 
+    def test_cp_verbose(self):
+        self.basedir = "cli/Cp/cp_verbose"
+        self.set_up_grid()
+
+        # Write two test files, which we'll copy to the grid.
+        test1_path = os.path.join(self.basedir, "test1")
+        test2_path = os.path.join(self.basedir, "test2")
+        fileutil.write(test1_path, "test1")
+        fileutil.write(test2_path, "test2")
+
+        d = self.do_cli("create-alias", "tahoe")
+        d.addCallback(lambda ign:
+            self.do_cli("cp", "--verbose", test1_path, test2_path, "tahoe:"))
+        def _check(res):
+            (rc, out, err) = res
+            self.failUnlessEqual(rc, 0, str(res))
+            self.failUnlessIn("Success: files copied", out, str(res))
+            self.failUnlessEqual(err, """\
+attaching sources to targets, 2 files / 0 dirs in root
+targets assigned, 1 dirs, 2 files
+starting copy, 2 files, 1 directories
+1/2 files, 0/1 directories
+2/2 files, 0/1 directories
+1/1 directories
+""", str(res))
+        d.addCallback(_check)
+        return d
+
 
 class Backup(GridTestMixin, CLITestMixin, StallMixin, unittest.TestCase):
 
-- 
2.45.2