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

_homedir_setter unable to handle windows paths #199

Open
Paradoxis opened this issue Jul 4, 2017 · 1 comment
Open

_homedir_setter unable to handle windows paths #199

Paradoxis opened this issue Jul 4, 2017 · 1 comment

Comments

@Paradoxis
Copy link

When setting the home directory, it's not possible to pass a windows style home directory. The path gets escaped before getting padded to _meta._create_if_necessary. The lines that cause this:

# Fix: change 'hd' to 'directory', since they don't handle shell commands at all
_util._create_if_necessary(hd) -> _util._create_if_necessary(directory)
 OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: "C:\\Users\\Luke\\Documents\\Projects\\myproject\\'C:"
# in _homedir_setter
# directory = 'C:\\Users\\Paradoxis\\/.gnupg/'
hd = _parsers._fix_unsafe(directory)
# hd = '\\'C:\\Users\\Luke\\/.gnupg/\\''
# Path gets wrapped in quotes
log.debug("GPGBase._homedir_setter(): got directory '%s'" % hd)

if hd:
    log.debug("GPGBase._homedir_setter(): Check existence of '%s'" % hd)
    _util._create_if_necessary(hd)   # Quoted path passed to standard library


# in _create_if_necessary
# directory = '\\'C:\\Users\\Luke\\/.gnupg/\\''

if not os.path.isabs(directory):
    log.debug("Got non-absolute path: %s" % directory)
    directory = os.path.abspath(directory)
    # Standard directory doesn't understand the quotes, so appends the current working directory to it
    # directory = 'C:\\Users\\Luke\\Documents\\Projects\\myproject\\\\'C:\\Users\\Luke\\.gnupg\\\\''

if not os.path.isdir(directory):
    log.info("Creating directory: %s" % directory)  
    # Invalid path triggers exception
    # OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: "C:\\Users\\Luke\\Documents\\Projects\\myproject\\'C:"
    try:
        os.makedirs(directory, 0x1C0)
@Paradoxis
Copy link
Author

Working monkey-patch, but the entire library has issues handling paths in Windows which means its still useless.

from os.path import abspath, expanduser
import gnupg._meta
gnupg._meta.GPGBase._homedir_setter = lambda self, directory: setattr(self, "_homedir", abspath(expanduser(directory)))

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

1 participant