Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing path to file #121

Open
fkloft opened this issue Dec 7, 2018 · 3 comments
Open

missing path to file #121

fkloft opened this issue Dec 7, 2018 · 3 comments

Comments

@fkloft
Copy link
Contributor

fkloft commented Dec 7, 2018

In this line:

if os.path.isfile(dir) and not dir.startswith("tagmanifest-"):

I didn't test this, but shouldn't the argument to os.path.filename be prefixed with bag_dir?

@kba
Copy link
Contributor

kba commented Dec 7, 2018

This works because the assumption is that os.getcwd() is the bagdir. When creating/saving bags, directory is actively os.chdired.

For the bagit-profiles-validator code, for the same/similar purpose, there's this code, which checks paths relative to bag_dir (https://github.com/bagit-profiles/bagit-profiles-validator/blob/master/bagit_profile.py#L287-L304):

# Return true if any of the pattern fnmatches a file path
def fnmatch_any(f, pats):
    for pat in pats:
        if fnmatch(f, pat):
            return True
    return False

# Find tag files
def find_tag_files(bag_dir):
    for root, _, basenames in walk(bag_dir):
        reldir = relpath(root, bag_dir)
        for basename in basenames:
            if fnmatch(reldir, 'data*') or (reldir == '.' and fnmatch_any(basename,
                ['manifest-*.txt', 'bag-info.txt', 'tagmanifest-*.txt', 'bagit.txt', 'fetch.txt'])):
                continue
            fpath = join(root, basename)
            if isfile(fpath):
                yield fpath

@acdha
Copy link
Member

acdha commented Dec 7, 2018

Note also that I want to change this as part of the upcoming work @edsu and I are planning so the code can be used with non-POSIX filesystems where the notion of current directory doesn't exist.

@fkloft
Copy link
Contributor Author

fkloft commented Dec 7, 2018

Thanks for the response. I'll have to check my code, because I use bagit as an imported module, usually with cwd != bagdir, so that may lead to unexpected results. IMHO, this behavior should be changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants