Skip to content

Commit a7c44b5

Browse files
committed
Fix crash when bagging content containing 'data' dir
Fixes #29
1 parent 80fa583 commit a7c44b5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

bagit.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import optparse
3939
import multiprocessing
4040
import codecs
41+
import tempfile
4142

4243
from glob import glob
4344
from datetime import date
@@ -94,14 +95,16 @@ def make_bag(bag_dir, bag_info=None, processes=1):
9495
sys.exit("\nRead permissions are required to calculate file fixities.")
9596
else:
9697
logging.info("creating data dir")
97-
os.mkdir('data')
98+
temp_data = tempfile.mkdtemp(dir=os.getcwd())
9899

99100
for f in os.listdir('.'):
100-
if f == 'data': continue
101-
new_f = os.path.join('data', f)
101+
if os.path.abspath(f) == temp_data: continue
102+
new_f = os.path.join(temp_data, f)
102103
logging.info("moving %s to %s" % (f, new_f))
103104
os.rename(f, new_f)
104105

106+
os.rename(temp_data, 'data')
107+
105108
logging.info("writing manifest-md5.txt")
106109
Oxum = _make_manifest('manifest-md5.txt', 'data', processes)
107110

0 commit comments

Comments
 (0)