Skip to content

Commit f1f3f3d

Browse files
authored
Merge pull request #100 from mikedarcy/master
Allow bag in-place on empty directories
2 parents b6d1c26 + 110ae13 commit f1f3f3d

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

bagit.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,10 @@ def make_manifests(data_dir, processes, algorithms=DEFAULT_CHECKSUMS, encoding='
11441144
byte_value_set = set(total_bytes.values())
11451145
file_count_set = set(num_files.values())
11461146

1147+
# allow a bag with an empty payload
1148+
if not byte_value_set and not file_count_set:
1149+
return 0, 0
1150+
11471151
if len(file_count_set) != 1:
11481152
raise RuntimeError(_('Expected the same number of files for each checksum'))
11491153

test.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,22 @@ def test_make_bag_sha512_manifest(self):
516516
def test_make_bag_unknown_algorithm(self):
517517
self.assertRaises(ValueError, bagit.make_bag, self.tmpdir, checksum=['not-really-a-name'])
518518

519+
def test_make_bag_with_empty_directory(self):
520+
tmpdir = tempfile.mkdtemp()
521+
try:
522+
bagit.make_bag(tmpdir)
523+
finally:
524+
shutil.rmtree(tmpdir)
525+
526+
def test_make_bag_with_empty_directory_tree(self):
527+
tmpdir = tempfile.mkdtemp()
528+
path = j(tmpdir, "test1", "test2")
529+
try:
530+
os.makedirs(path)
531+
bagit.make_bag(tmpdir)
532+
finally:
533+
shutil.rmtree(tmpdir)
534+
519535
def test_make_bag_with_bogus_directory(self):
520536
bogus_directory = os.path.realpath('this-directory-does-not-exist')
521537

0 commit comments

Comments
 (0)