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

Handle pipes via process substitution #206

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

shkm
Copy link

@shkm shkm commented Aug 18, 2020

FWIW I'm not a python developer so this code may have repercussions that I'm unable to diagnose.

Background

I'm doing some manual templating on config files for two programs: khal and khard, both of which use configobj. Neither program allows for interpolation in the config files, so I was required to roll my own. Essentially, I run these programs with a wrapper like this:

#!/usr/bin/env bash
source pimenv

/usr/bin/khal -c <(envsubst < "$XDG_CONFIG_HOME/khal/config") "$@"

Sourcing pimenv provides a bunch of environment variables which are interpolated into the config file using envsubst with process substitution, producing a file descriptor (/dev/fd/63).

On Linux, at least, os.path.isfile() returns False for this descriptor, but os.path.islink() returns True. As a result, even though the file is readable, configobj never tries to read it and throws an error.

The Fix

Well, the code is pretty self-explanatory. I've tested this under both khal and khard, and found that everything works as expected now. Interestingly, os.path.isfile() does return True for a symlink, so this is probably quite an edge case.

@shkm
Copy link
Author

shkm commented Aug 18, 2020

I now see that this has already been handled by another PR: #187.

I'll leave this open, though; I'm not sure what's the better solution here. Feel free to close if the other is preferred.

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

Successfully merging this pull request may close these issues.

1 participant