commit 339c298e66d94d2a92f3b1af99c60e0e4172b1e7 from: Stefan Sperling date: Sat Jul 27 14:25:48 2019 UTC undo previous 3 commits; stat is faster than open commit - 3f148bc66e13559704e12d07a8c05612be797de2 commit + 339c298e66d94d2a92f3b1af99c60e0e4172b1e7 blob - fd98027aca25f70b7500f2f6e60ae73cc02d6033 blob + 08d2a404aeb438f0119da97f048a5a3735aa51c1 --- lib/worktree.c +++ lib/worktree.c @@ -1033,7 +1033,6 @@ stat_info_differs(struct got_fileindex_entry *ie, stru ie->size == (sb->st_size & 0xffffffff)); } -/* Report file status and initialize sb->st_mode. */ static const struct got_error * get_file_status(unsigned char *status, struct stat *sb, struct got_fileindex_entry *ie, const char *abspath, @@ -1042,7 +1041,6 @@ get_file_status(unsigned char *status, struct stat *sb const struct got_error *err = NULL; struct got_object_id id; size_t hdrlen; - int fd; FILE *f = NULL; uint8_t fbuf[8192]; struct got_blob_object *blob = NULL; @@ -1050,8 +1048,7 @@ get_file_status(unsigned char *status, struct stat *sb *status = GOT_STATUS_NO_CHANGE; - fd = open(abspath, O_RDONLY | O_NOFOLLOW); - if (fd == -1) { + if (lstat(abspath, sb) == -1) { if (errno == ENOENT) { if (ie) { if (got_fileindex_entry_has_file_on_disk(ie)) @@ -1065,50 +1062,38 @@ get_file_status(unsigned char *status, struct stat *sb sb->st_mode = GOT_DEFAULT_FILE_MODE; return NULL; } - return got_error_from_errno2("open", abspath); + return got_error_from_errno2("lstat", abspath); } - if (ie == NULL) { - sb->st_mode = GOT_DEFAULT_FILE_MODE; - goto done; + if (!S_ISREG(sb->st_mode)) { + *status = GOT_STATUS_OBSTRUCTED; + return NULL; } - if (fstat(fd, sb) == -1) { - err = got_error_from_errno2("fstat", abspath); - goto done; - } + if (ie == NULL) + return NULL; if (!got_fileindex_entry_has_file_on_disk(ie)) { - if (S_ISREG(sb->st_mode)) - *status = GOT_STATUS_DELETE; - else - *status = GOT_STATUS_OBSTRUCTED; - goto done; + *status = GOT_STATUS_DELETE; + return NULL; } else if (!got_fileindex_entry_has_blob(ie)) { - if (S_ISREG(sb->st_mode)) - *status = GOT_STATUS_ADD; - else - *status = GOT_STATUS_OBSTRUCTED; - goto done; - } else if (!S_ISREG(sb->st_mode)) { - *status = GOT_STATUS_OBSTRUCTED; - goto done; + *status = GOT_STATUS_ADD; + return NULL; } if (!stat_info_differs(ie, sb)) - goto done; + return NULL; memcpy(id.sha1, ie->blob_sha1, sizeof(id.sha1)); err = got_object_open_as_blob(&blob, repo, &id, sizeof(fbuf)); if (err) - goto done; + return err; - f = fdopen(fd, "r"); + f = fopen(abspath, "r"); if (f == NULL) { - err = got_error_from_errno2("fdopen", abspath); + err = got_error_from_errno2("fopen", abspath); goto done; } - fd = -1; hdrlen = got_object_blob_get_hdrlen(blob); for (;;) { const uint8_t *bbuf = got_object_blob_get_read_buf(blob); @@ -1149,8 +1134,6 @@ get_file_status(unsigned char *status, struct stat *sb done: if (blob) got_object_blob_close(blob); - if (fd != -1 && close(fd) == -1 && err == NULL) - err = got_error_from_errno2("close", abspath); if (f) fclose(f); return err;