Skip to content

Commit 464cd77

Browse files
committed
Prevent bagging a parent directory (see #101)
This avoids errors when the paths suddenly change because e.g. /foo/bar (where you started) is renamed to /foo/data/bar when moving the payload files.
1 parent e727525 commit 464cd77

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

bagit.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ def make_bag(bag_dir, bag_info=None, processes=1, checksums=None, checksum=None,
147147
checksums = DEFAULT_CHECKSUMS
148148

149149
bag_dir = os.path.abspath(bag_dir)
150+
cwd = os.path.abspath(os.path.curdir)
151+
152+
if cwd.startswith(bag_dir) and cwd != bag_dir:
153+
raise RuntimeError(_('Bagging a parent of the current directory is not supported'))
154+
150155
LOGGER.info(_("Creating bag for directory %s"), bag_dir)
151156

152157
if not os.path.isdir(bag_dir):

0 commit comments

Comments
 (0)