overwritten. This option causes even devices, sockets, and fifos to be
skipped.
""")
+group.add_argument('--strip-manifest', action='store_true', default=False,
+ help="""
+When getting a collection manifest, strip its access tokens before writing
+it.
+""")
def parse_arguments(arguments, stdout, stderr):
args = parser.parse_args(arguments)
return 1
# User asked to download the collection's manifest
- should_strip_manifest = False
- if re.match(util.keep_locator_pattern, col_loc):
- should_strip_manifest = True
if not get_prefix:
if not args.n:
open_flags = os.O_CREAT | os.O_WRONLY
open_flags |= os.O_EXCL
try:
if args.destination == "-":
- stdout.write(reader.manifest_text(strip=should_strip_manifest))
+ stdout.write(reader.manifest_text(strip=args.strip_manifest))
else:
out_fd = os.open(args.destination, open_flags)
with os.fdopen(out_fd, 'wb') as out_file:
- out_file.write(reader.manifest_text(strip=should_strip_manifest))
+ out_file.write(reader.manifest_text(strip=args.strip_manifest))
except (IOError, OSError) as error:
logger.error("can't write to '{}': {}".format(args.destination, error))
return 1
shutil.rmtree(self.tempdir)
def write_test_collection(self,
- strip_manifest=True,
+ strip_manifest=False,
contents = {
'foo.txt' : 'foo',
'bar.txt' : 'bar',
with open("{}/subdir/baz.txt".format(self.tempdir), "r") as f:
self.assertEqual("baz", f.read())
- def test_get_collection_manifest(self):
- # Get the collection manifest
+ def test_get_collection_unstripped_manifest(self):
+ # Get the collection manifest by UUID
+ r = self.run_get([self.col_loc, self.tempdir])
+ self.assertEqual(0, r)
+ with open("{}/{}".format(self.tempdir, self.col_loc), "r") as f:
+ self.assertEqual(self.col_manifest, f.read())
+ # Get the collection manifest by PDH
r = self.run_get([self.col_pdh, self.tempdir])
self.assertEqual(0, r)
with open("{}/{}".format(self.tempdir, self.col_pdh), "r") as f:
self.assertEqual(self.col_manifest, f.read())
+ def test_get_collection_stripped_manifest(self):
+ col_loc, col_pdh, col_manifest = self.write_test_collection(strip_manifest=True)
+ # Get the collection manifest by UUID
+ r = self.run_get(['--strip-manifest', col_loc, self.tempdir])
+ self.assertEqual(0, r)
+ with open("{}/{}".format(self.tempdir, col_loc), "r") as f:
+ self.assertEqual(col_manifest, f.read())
+ # Get the collection manifest by PDH
+ r = self.run_get(['--strip-manifest', col_pdh, self.tempdir])
+ self.assertEqual(0, r)
+ with open("{}/{}".format(self.tempdir, col_pdh), "r") as f:
+ self.assertEqual(col_manifest, f.read())
+
def test_invalid_collection(self):
# Asking for an invalid collection should generate an error.
r = self.run_get(['this-uuid-seems-to-be-fake', self.tempdir])