verify_dotfile: mention case-insensitivity in comment
[gitweb.git] / read-cache.c
index 0d0081a11b858227d3f55ebbc21f04bd49875f68..333e0c542967814fcb3e71fd4cec973548b4f567 100644 (file)
@@ -810,8 +810,10 @@ static int verify_dotfile(const char *rest)
 
        switch (*rest) {
        /*
-        * ".git" followed by  NUL or slash is bad. This
-        * shares the path end test with the ".." case.
+        * ".git" followed by NUL or slash is bad. Note that we match
+        * case-insensitively here, even if ignore_case is not set.
+        * This outlaws ".GIT" everywhere out of an abundance of caution,
+        * since there's really no good reason to allow it.
         */
        case 'g':
        case 'G':
@@ -819,8 +821,9 @@ static int verify_dotfile(const char *rest)
                        break;
                if (rest[2] != 't' && rest[2] != 'T')
                        break;
-               rest += 2;
-       /* fallthrough */
+               if (rest[3] == '\0' || is_dir_sep(rest[3]))
+                       return 0;
+               break;
        case '.':
                if (rest[1] == '\0' || is_dir_sep(rest[1]))
                        return 0;
@@ -2187,9 +2190,10 @@ void update_index_if_able(struct index_state *istate, struct lock_file *lockfile
                rollback_lock_file(lockfile);
 }
 
-static int do_write_index(struct index_state *istate, int newfd,
+static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
                          int strip_extensions)
 {
+       int newfd = tempfile->fd;
        git_SHA_CTX c;
        struct cache_header hdr;
        int i, err, removed, extended, hdr_version;
@@ -2298,7 +2302,11 @@ static int do_write_index(struct index_state *istate, int newfd,
                        return -1;
        }
 
-       if (ce_flush(&c, newfd, istate->sha1) || fstat(newfd, &st))
+       if (ce_flush(&c, newfd, istate->sha1))
+               return -1;
+       if (close_tempfile(tempfile))
+               return error(_("could not close '%s'"), tempfile->filename.buf);
+       if (stat(tempfile->filename.buf, &st))
                return -1;
        istate->timestamp.sec = (unsigned int)st.st_mtime;
        istate->timestamp.nsec = ST_MTIME_NSEC(st);
@@ -2321,7 +2329,7 @@ static int commit_locked_index(struct lock_file *lk)
 static int do_write_locked_index(struct index_state *istate, struct lock_file *lock,
                                 unsigned flags)
 {
-       int ret = do_write_index(istate, get_lock_file_fd(lock), 0);
+       int ret = do_write_index(istate, &lock->tempfile, 0);
        if (ret)
                return ret;
        assert((flags & (COMMIT_LOCK | CLOSE_LOCK)) !=
@@ -2418,9 +2426,17 @@ static int write_shared_index(struct index_state *istate,
                return do_write_locked_index(istate, lock, flags);
        }
        move_cache_to_base_index(istate);
-       ret = do_write_index(si->base, fd, 1);
+       ret = do_write_index(si->base, &temporary_sharedindex, 1);
+       if (ret) {
+               delete_tempfile(&temporary_sharedindex);
+               return ret;
+       }
+       ret = adjust_shared_perm(get_tempfile_path(&temporary_sharedindex));
        if (ret) {
+               int save_errno = errno;
+               error("cannot fix permission bits on %s", get_tempfile_path(&temporary_sharedindex));
                delete_tempfile(&temporary_sharedindex);
+               errno = save_errno;
                return ret;
        }
        ret = rename_tempfile(&temporary_sharedindex,