Use git_open_noatime when accessing pack data
[gitweb.git] / sha1_file.c
index 42517987a85df35115c03be0f1fc2ca525448dc9..e53778230026e51034e10678be2795e21b2e7f02 100644 (file)
@@ -35,6 +35,8 @@ static size_t sz_fmt(size_t s) { return s; }
 
 const unsigned char null_sha1[20];
 
+static int git_open_noatime(const char *name);
+
 int safe_create_leading_directories(char *path)
 {
        char *pos = path + offset_1st_component(path);
@@ -298,7 +300,7 @@ static void read_info_alternates(const char * relative_base, int depth)
        int fd;
 
        sprintf(path, "%s/%s", relative_base, alt_file_name);
-       fd = open(path, O_RDONLY);
+       fd = git_open_noatime(path);
        if (fd < 0)
                return;
        if (fstat(fd, &st) || (st.st_size == 0)) {
@@ -411,7 +413,7 @@ static int check_packed_git_idx(const char *path,  struct packed_git *p)
        struct pack_idx_header *hdr;
        size_t idx_size;
        uint32_t version, nr, i, *index;
-       int fd = open(path, O_RDONLY);
+       int fd = git_open_noatime(path);
        struct stat st;
 
        if (fd < 0)
@@ -655,9 +657,9 @@ static int open_packed_git_1(struct packed_git *p)
        if (!p->index_data && open_pack_index(p))
                return error("packfile %s index unavailable", p->pack_name);
 
-       p->pack_fd = open(p->pack_name, O_RDONLY);
+       p->pack_fd = git_open_noatime(p->pack_name);
        while (p->pack_fd < 0 && errno == EMFILE && unuse_one_window(p, -1))
-               p->pack_fd = open(p->pack_name, O_RDONLY);
+               p->pack_fd = git_open_noatime(p->pack_name);
        if (p->pack_fd < 0 || fstat(p->pack_fd, &st))
                return -1;
 
@@ -2090,16 +2092,21 @@ void *read_sha1_file_repl(const unsigned char *sha1,
                          const unsigned char **replacement)
 {
        const unsigned char *repl = lookup_replace_object(sha1);
-       void *data = read_object(repl, type, size);
+       void *data;
        char *path;
        const struct packed_git *p;
 
+       errno = 0;
+       data = read_object(repl, type, size);
        if (data) {
                if (replacement)
                        *replacement = repl;
                return data;
        }
 
+       if (errno != ENOENT)
+               die_errno("failed to read object %s", sha1_to_hex(sha1));
+
        /* die if we replaced an object with one that does not exist */
        if (repl != sha1)
                die("replacement %s not found for %s",