| 171 | } |
| 172 | |
| 173 | int check_filename(const char *prefix, const char *arg) |
| 174 | { |
| 175 | char *to_free = NULL; |
| 176 | struct stat st; |
| 177 | |
| 178 | if (skip_prefix(arg, ":/", &arg)) { |
| 179 | if (!*arg) /* ":/" is root dir, always exists */ |
| 180 | return 1; |
| 181 | prefix = NULL; |
| 182 | } else if (skip_prefix(arg, ":!", &arg) || |
| 183 | skip_prefix(arg, ":^", &arg)) { |
| 184 | if (!*arg) /* excluding everything is silly, but allowed */ |
| 185 | return 1; |
| 186 | } |
| 187 | |
| 188 | if (prefix) |
| 189 | arg = to_free = prefix_filename(prefix, arg); |
| 190 | |
| 191 | if (!lstat(arg, &st)) { |
| 192 | free(to_free); |
| 193 | return 1; /* file exists */ |
| 194 | } |
| 195 | if (is_missing_file_error(errno)) { |
| 196 | free(to_free); |
| 197 | return 0; /* file does not exist */ |
| 198 | } |
| 199 | die_errno(_("failed to stat '%s'"), arg); |
| 200 | } |
| 201 | |
| 202 | static void NORETURN die_verify_filename(struct repository *r, |
| 203 | const char *prefix, |
no test coverage detected