Skip to content

Windows: Cannot create directory with backslashes #5241

@ehuss

Description

@ehuss

Reproduction steps

Attempt to create a repository on Windows with backslashes in the path with multiple intermediate directories.

git_repository *repo;
git_repository_init_options initopts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
git_libgit2_init();
initopts.flags |= GIT_REPOSITORY_INIT_MKDIR | GIT_REPOSITORY_INIT_MKPATH;
int error = git_repository_init_ext(&repo, "C:\\Temp\\foo\\bar", &initopts);
if (error) {
    const git_error *err = git_error_last();
    fprintf(stderr, "[%d] %s\n", err->klass, err->message);
}

The above should work if the backslashes are replaced with forward slashes.

Expected behavior

The path is created without error. According to the conventions doc: "If a function accepts a path on disk, then backslashes (0x5C) are also accepted on Windows."

Actual behavior

Fails to create intermediate directories if they contain backslashes.

Version of libgit2 (release number or SHA1)

9cd5240

Operating system(s) tested

Windows 10

Notes

I'm not exactly sure how slashes in paths are intended to be supported. I see a large number of places like mkdir_canonicalize that only look for forward slashes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions