From 4c1f65d97a7884bd1fdac2f7c00d46cce3d1f994 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Thu, 13 May 2021 10:52:12 -0400 Subject: [PATCH 1/7] Test for leading slash check. --- src/allmydata/test/cli/test_put.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/allmydata/test/cli/test_put.py b/src/allmydata/test/cli/test_put.py index c6a577074..d916ae7a2 100644 --- a/src/allmydata/test/cli/test_put.py +++ b/src/allmydata/test/cli/test_put.py @@ -486,3 +486,21 @@ class Put(GridTestMixin, CLITestMixin, unittest.TestCase): self.failUnlessReallyEqual(rc_out_err[1], DATA)) return d + + def test_no_leading_slash(self): + self.basedir = "cli/Put/leading_slash" + self.set_up_grid(oneshare=True) + + DATA1 = b"data" * 100 + fn1 = os.path.join(self.basedir, "DATA1") + + d = self.do_cli("create-alias", "tahoe") + d.addCallback(lambda res: + self.do_cli("put", fn1, "tahoe:/uploaded.txt")) + def _check(args): + (rc, out, err) = args + self.assertEqual(rc, 1) + self.failUnlessIn("must not start with a slash", err) + self.assertEqual(len(out), 0, out) + d.addCallback(_check) + return d From 01db93119266067fcd65bca65babe96d978685fb Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Tue, 18 May 2021 13:35:34 -0400 Subject: [PATCH 2/7] A test that doesn't really increase coverage much. Ideally this would test immutable directories to test caching logic, but that's too much of a pain. Since I already have this written, going to leave in cause why not. --- src/allmydata/test/cli/test_cp.py | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/allmydata/test/cli/test_cp.py b/src/allmydata/test/cli/test_cp.py index d198a832c..7e651b737 100644 --- a/src/allmydata/test/cli/test_cp.py +++ b/src/allmydata/test/cli/test_cp.py @@ -238,6 +238,43 @@ class Cp(GridTestMixin, CLITestMixin, unittest.TestCase): return d + @defer.inlineCallbacks + def test_cp_duplicate_directories(self): + self.basedir = "cli/Cp/cp_duplicate_directories" + self.set_up_grid(oneshare=True) + + filename = os.path.join(self.basedir, "file") + data = b"abc\xff\x00\xee" + with open(filename, "wb") as f: + f.write(data) + + yield self.do_cli("create-alias", "tahoe") + (rc, out, err) = yield self.do_cli("mkdir", "tahoe:test1") + self.assertEqual(rc, 0, (rc, err)) + dircap = out.strip() + + (rc, out, err) = yield self.do_cli("cp", filename, "tahoe:test1/file") + self.assertEqual(rc, 0, (rc, err)) + + # Now duplicate dirnode, testing duplicates on destination side: + (rc, out, err) = yield self.do_cli( + "cp", "--recursive", dircap, "tahoe:test2/") + self.assertEqual(rc, 0, (rc, err)) + (rc, out, err) = yield self.do_cli( + "cp", "--recursive", dircap, "tahoe:test3/") + self.assertEqual(rc, 0, (rc, err)) + + (rc, out, err) = yield self.do_cli("ls", "tahoe:test1") + (rc, out, err) = yield self.do_cli("ls", "tahoe:test2") + (rc, out, err) = yield self.do_cli("ls", "tahoe:test3") + + # Now copy to local directory, testing duplicates on origin side: + yield self.do_cli("cp", "--recursive", "tahoe:", self.basedir) + + for i in range(1, 4): + with open(os.path.join(self.basedir, "test%d" % (i,), "file"), "rb") as f: + self.assertEquals(f.read(), data) + def test_cp_replaces_mutable_file_contents(self): self.basedir = "cli/Cp/cp_replaces_mutable_file_contents" self.set_up_grid(oneshare=True) From bb74b7fe0c87120a677dfb7bcaa649fa3a9477a5 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Fri, 21 May 2021 11:01:00 -0400 Subject: [PATCH 3/7] Note this code is buggy. --- src/allmydata/scripts/tahoe_cp.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/allmydata/scripts/tahoe_cp.py b/src/allmydata/scripts/tahoe_cp.py index fb86ff0ec..df4965dc7 100644 --- a/src/allmydata/scripts/tahoe_cp.py +++ b/src/allmydata/scripts/tahoe_cp.py @@ -701,6 +701,8 @@ class Copier(object): def need_to_copy_bytes(self, source, target): + # This should likley be a method call! but enabling that triggers + # additional bugs. https://tahoe-lafs.org/trac/tahoe-lafs/ticket/3719 if source.need_to_copy_bytes: # mutable tahoe files, and local files return True From 1e9dfd2fcee068640f99996c5058220f12e8672b Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Fri, 21 May 2021 11:01:17 -0400 Subject: [PATCH 4/7] Another test. --- src/allmydata/test/cli/test_cp.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/allmydata/test/cli/test_cp.py b/src/allmydata/test/cli/test_cp.py index 7e651b737..45efae949 100644 --- a/src/allmydata/test/cli/test_cp.py +++ b/src/allmydata/test/cli/test_cp.py @@ -275,6 +275,33 @@ class Cp(GridTestMixin, CLITestMixin, unittest.TestCase): with open(os.path.join(self.basedir, "test%d" % (i,), "file"), "rb") as f: self.assertEquals(f.read(), data) + @defer.inlineCallbacks + def test_cp_immutable_file(self): + self.basedir = "cli/Cp/cp_immutable_file" + self.set_up_grid(oneshare=True) + + filename = os.path.join(self.basedir, "source_file") + data = b"abc\xff\x00\xee" + with open(filename, "wb") as f: + f.write(data) + + # Create immutable file: + yield self.do_cli("create-alias", "tahoe") + (rc, out, _) = yield self.do_cli("put", filename, "tahoe:file1") + filecap = out.strip() + self.assertEqual(rc, 0) + + # Copy it: + (rc, _, _) = yield self.do_cli("cp", "tahoe:file1", "tahoe:file2") + self.assertEqual(rc, 0) + + # Make sure resulting file is the same: + (rc, _, _) = yield self.do_cli("cp", "--recursive", "--caps-only", + "tahoe:", self.basedir) + self.assertEqual(rc, 0) + with open(os.path.join(self.basedir, "file2")) as f: + self.assertEqual(f.read().strip(), filecap) + def test_cp_replaces_mutable_file_contents(self): self.basedir = "cli/Cp/cp_replaces_mutable_file_contents" self.set_up_grid(oneshare=True) From 8ec41fff458890073a8c347b9aee102c2dd7e1ef Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Fri, 21 May 2021 11:11:48 -0400 Subject: [PATCH 5/7] News file. --- newsfragments/3714.minor | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 newsfragments/3714.minor diff --git a/newsfragments/3714.minor b/newsfragments/3714.minor new file mode 100644 index 000000000..e69de29bb From 9e6915ca78de3e0016175f89897142c6794f5acf Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Fri, 21 May 2021 11:12:41 -0400 Subject: [PATCH 6/7] Not used. --- src/allmydata/test/cli/test_put.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/allmydata/test/cli/test_put.py b/src/allmydata/test/cli/test_put.py index d916ae7a2..03306ab71 100644 --- a/src/allmydata/test/cli/test_put.py +++ b/src/allmydata/test/cli/test_put.py @@ -491,7 +491,6 @@ class Put(GridTestMixin, CLITestMixin, unittest.TestCase): self.basedir = "cli/Put/leading_slash" self.set_up_grid(oneshare=True) - DATA1 = b"data" * 100 fn1 = os.path.join(self.basedir, "DATA1") d = self.do_cli("create-alias", "tahoe") From cf299684c29190eb47a43be58ec9e90a58be8093 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Tue, 25 May 2021 10:40:44 -0400 Subject: [PATCH 7/7] Unneeded. --- src/allmydata/test/cli/test_cp.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/allmydata/test/cli/test_cp.py b/src/allmydata/test/cli/test_cp.py index 45efae949..d55bc01bd 100644 --- a/src/allmydata/test/cli/test_cp.py +++ b/src/allmydata/test/cli/test_cp.py @@ -264,10 +264,6 @@ class Cp(GridTestMixin, CLITestMixin, unittest.TestCase): "cp", "--recursive", dircap, "tahoe:test3/") self.assertEqual(rc, 0, (rc, err)) - (rc, out, err) = yield self.do_cli("ls", "tahoe:test1") - (rc, out, err) = yield self.do_cli("ls", "tahoe:test2") - (rc, out, err) = yield self.do_cli("ls", "tahoe:test3") - # Now copy to local directory, testing duplicates on origin side: yield self.do_cli("cp", "--recursive", "tahoe:", self.basedir)