Skip to content

Commit

Permalink
config.c: rewrite ENODEV into EISDIR when mmap fails
Browse files Browse the repository at this point in the history
If we try to mmap a directory, we'll get ENODEV. This
translates to "no such device" for the user, which is not
very helpful. Since we've just fstat()'d the file, we can
easily check whether the problem was a directory to give a
better message.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed May 28, 2015
1 parent 1570856 commit 0e8771f
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -2051,6 +2051,8 @@ int git_config_set_multivar_in_file(const char *config_filename,
contents = xmmap_gently(NULL, contents_sz, PROT_READ,
MAP_PRIVATE, in_fd, 0);
if (contents == MAP_FAILED) {
if (errno == ENODEV && S_ISDIR(st.st_mode))
errno = EISDIR;
error("unable to mmap '%s': %s",
config_filename, strerror(errno));
ret = CONFIG_INVALID_FILE;
Expand Down

0 comments on commit 0e8771f

Please sign in to comment.