Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

partial revert of f01e268

Silly idea is silly. Just stat the damn file.
  • Loading branch information...
commit 2f8cd405fd3155df74b504ac100664e7e6c67d0b 1 parent a61e178
@falconindy authored
Showing with 12 additions and 17 deletions.
  1. +12 −14 curl.c
  2. +0 −3  util.h
View
26 curl.c
@@ -26,9 +26,9 @@
#define _GNU_SOURCE
#include <errno.h>
-#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
+#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
@@ -205,19 +205,17 @@ long aur_upload(const char *taurball) {
struct curl_httppost *post = NULL, *last = NULL;
struct curl_slist *headers = NULL;
struct write_result response = { NULL, 0 };
- int fd;
-
- OPEN(fd, taurball, O_DIRECTORY|O_RDONLY);
- switch (errno) {
- case ENOTDIR:
- break;
- case 0:
- fprintf(stderr, "error: target is not a file: %s\n", taurball);
- CLOSE(fd);
- return ret;
- default:
- fprintf(stderr, "error: failed to read `%s': %s\n", taurball, strerror(errno));
- return ret;
+ struct stat st;
+
+ /* make sure the resolved path is a regular file */
+ if (stat(taurball, &st) != 0) {
+ fprintf(stderr, "error: failed to stat `%s': %s\n", taurball, strerror(errno));
+ return ret;
+ }
+
+ if (!S_ISREG(st.st_mode)) {
+ fprintf(stderr, "error: `%s\' is not a file\n", taurball);
+ return ret;
}
display_name = strrchr(taurball, '/');
View
3  util.h
@@ -34,9 +34,6 @@
#define MALLOC(p, s, action) do { p = calloc(1, s); if(!p) { ALLOC_FAIL(s); action; } } while(0)
#define FREE(x) do { free((void*)x); x = NULL; } while(0)
-#define OPEN(fd, path, flags) do { fd = open(path, flags); } while(fd == -1 && errno == EINTR)
-#define CLOSE(fd) do { int rc; do { rc = close(fd); } while(rc == -1 && errno == EINTR); } while(0)
-
void debug(const char*, ...);
char *read_stdin(const char*, size_t, int);
size_t strtrim(char*);
Please sign in to comment.
Something went wrong with that request. Please try again.