avoid fstat() call if no file index entry exists
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
diff --git a/lib/worktree.c b/lib/worktree.c
index bd32578..2acdc3d 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -1064,27 +1064,31 @@ get_file_status(unsigned char *status, struct stat *sb,
sb->st_mode = GOT_DEFAULT_FILE_MODE;
return NULL;
}
- return got_error_from_errno2("fopen", abspath);
+ return got_error_from_errno2("open", abspath);
}
- if (fstat(fd, sb) == -1) {
- err = got_error_from_errno2("fstat", abspath);
+ if (ie == NULL)
goto done;
- }
- if (!S_ISREG(sb->st_mode)) {
- *status = GOT_STATUS_OBSTRUCTED;
+ if (fstat(fd, sb) == -1) {
+ err = got_error_from_errno2("fstat", abspath);
goto done;
}
- if (ie == NULL)
- goto done;
-
if (!got_fileindex_entry_has_file_on_disk(ie)) {
- *status = GOT_STATUS_DELETE;
+ if (S_ISREG(sb->st_mode))
+ *status = GOT_STATUS_DELETE;
+ else
+ *status = GOT_STATUS_OBSTRUCTED;
goto done;
} else if (!got_fileindex_entry_has_blob(ie)) {
- *status = GOT_STATUS_ADD;
+ 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;
}