got_error_set_errno: take a char arg to pass to got_error_prefix_errno $> got rm a got: : No such file or directory becomes $> got rm a got: /path/to/a: No such file or directory
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
diff --git a/got/got.c b/got/got.c
index 679e74f..73e05dd 100644
--- a/got/got.c
+++ b/got/got.c
@@ -2020,7 +2020,7 @@ cmd_rm(int argc, char *argv[])
goto done;
error = got_repo_open(&repo, got_worktree_get_repo_path(worktree));
- if (error != NULL)
+ if (error)
goto done;
error = apply_unveil(got_repo_get_path(repo), 1,
diff --git a/include/got_error.h b/include/got_error.h
index 3fd5c96..604b154 100644
--- a/include/got_error.h
+++ b/include/got_error.h
@@ -208,9 +208,10 @@ const struct got_error *got_error_prefix_errno3(const char *, const char *,
/*
* Set errno to the specified error code and return a statically
* allocated error object with code GOT_ERR_ERRNO and an error
- * message obtained from strerror(3).
+ * message obtained from strerror(3), optionally prefixed with a
+ * string.
*/
-const struct got_error *got_error_set_errno(int);
+const struct got_error *got_error_set_errno(int, const char *);
/*
* If ferror(3) indicates an error status for the FILE, obtain an error
diff --git a/lib/error.c b/lib/error.c
index 4936ab5..1fd38ce 100644
--- a/lib/error.c
+++ b/lib/error.c
@@ -111,10 +111,10 @@ got_error_prefix_errno3(const char *prefix, const char *prefix2,
}
const struct got_error *
-got_error_set_errno(int code)
+got_error_set_errno(int code, const char *prefix)
{
errno = code;
- return got_error_prefix_errno("");
+ return got_error_prefix_errno(prefix);
}
const struct got_error *
@@ -167,7 +167,7 @@ got_error_uuid(uint32_t uuid_status)
case uuid_s_invalid_string_uuid:
return got_error(GOT_ERR_UUID_INVALID);
case uuid_s_no_memory:
- return got_error_set_errno(ENOMEM);
+ return got_error_set_errno(ENOMEM, NULL);
default:
return got_error(GOT_ERR_UUID);
}
diff --git a/lib/worktree.c b/lib/worktree.c
index 1ed6f1e..3ce4537 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -1861,7 +1861,7 @@ got_worktree_schedule_add(struct got_worktree *worktree,
goto done;
if (got_fileindex_entry_get(fileindex, relpath) != NULL) {
- err = got_error_set_errno(EEXIST);
+ err = got_error_set_errno(EEXIST, relpath);
goto done;
}
@@ -1973,7 +1973,7 @@ got_worktree_schedule_delete(struct got_worktree *worktree,
if (status != GOT_STATUS_NO_CHANGE) {
if (status == GOT_STATUS_DELETE) {
- err = got_error_set_errno(ENOENT);
+ err = got_error_set_errno(ENOENT, ondisk_path);
goto done;
}
if (status != GOT_STATUS_MODIFY) {
diff --git a/regress/cmdline/rm.sh b/regress/cmdline/rm.sh
index 581cd66..e0f866b 100755
--- a/regress/cmdline/rm.sh
+++ b/regress/cmdline/rm.sh
@@ -97,7 +97,6 @@ function test_double_rm {
(cd $testroot/wt && got rm beta > /dev/null)
for fflag in "" "-f"; do
- echo "got: No such file or directory" > $testroot/stderr.expected
(cd $testroot/wt && got rm $fflag beta 2> $testroot/stderr)
ret="$?"
if [ "$ret" == "0" ]; then
@@ -105,10 +104,11 @@ function test_double_rm {
test_done "$testroot" 1
fi
- cmp $testroot/stderr.expected $testroot/stderr
+ grep "No such file or directory" $testroot/stderr > \
+ $testroot/stderr.actual
ret="$?"
if [ "$ret" != "0" ]; then
- diff -u $testroot/stderr.expected $testroot/stderr
+ cat $testroot/stderr
test_done "$testroot" "$ret"
fi
done
diff --git a/tog/tog.c b/tog/tog.c
index c6e552d..3f82dba 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -535,11 +535,11 @@ view_input(struct tog_view **new, struct tog_view **dead,
/* Allow threads to make progress while we are waiting for input. */
errcode = pthread_mutex_unlock(&tog_mutex);
if (errcode)
- return got_error_set_errno(errcode);
+ return got_error_set_errno(errcode, "pthread_mutex_unlock");
ch = wgetch(view->window);
errcode = pthread_mutex_lock(&tog_mutex);
if (errcode)
- return got_error_set_errno(errcode);
+ return got_error_set_errno(errcode, "pthread_mutex_lock");
nodelay(stdscr, TRUE);
if (tog_sigwinch_received) {
@@ -655,7 +655,7 @@ view_loop(struct tog_view *view)
errcode = pthread_mutex_lock(&tog_mutex);
if (errcode)
- return got_error_set_errno(errcode);
+ return got_error_set_errno(errcode, "pthread_mutex_lock");
TAILQ_INIT(&views);
TAILQ_INSERT_HEAD(&views, view, entry);
@@ -774,7 +774,7 @@ done:
errcode = pthread_mutex_unlock(&tog_mutex);
if (errcode)
- return got_error_set_errno(errcode);
+ return got_error_set_errno(errcode, "pthread_mutex_unlock");
return err;
}
@@ -1096,7 +1096,7 @@ queue_commits(struct got_commit_graph *graph, struct commit_queue *commits,
errcode = pthread_mutex_lock(&tog_mutex);
if (errcode) {
- err = got_error_set_errno(errcode);
+ err = got_error_set_errno(errcode, "pthread_mutex_lock");
break;
}
@@ -1107,7 +1107,8 @@ queue_commits(struct got_commit_graph *graph, struct commit_queue *commits,
errcode = pthread_mutex_unlock(&tog_mutex);
if (errcode && err == NULL)
- err = got_error_set_errno(errcode);
+ err = got_error_set_errno(errcode,
+ "pthread_mutex_unlock");
}
return err;
@@ -1306,14 +1307,17 @@ trigger_log_thread(int load_all, int *commits_needed, int *log_complete,
/* Wake the log thread. */
errcode = pthread_cond_signal(need_commits);
if (errcode)
- return got_error_set_errno(errcode);
+ return got_error_set_errno(errcode,
+ "pthread_cond_signal");
errcode = pthread_mutex_unlock(&tog_mutex);
if (errcode)
- return got_error_set_errno(errcode);
+ return got_error_set_errno(errcode,
+ "pthread_mutex_unlock");
pthread_yield();
errcode = pthread_mutex_lock(&tog_mutex);
if (errcode)
- return got_error_set_errno(errcode);
+ return got_error_set_errno(errcode,
+ "pthread_mutex_lock");
if (*commits_needed > 0 && (!load_all || --max_wait <= 0)) {
/*
@@ -1448,7 +1452,8 @@ log_thread(void *arg)
errcode = pthread_mutex_lock(&tog_mutex);
if (errcode) {
- err = got_error_set_errno(errcode);
+ err = got_error_set_errno(errcode,
+ "pthread_mutex_lock");
break;
} else if (*a->quit)
done = 1;
@@ -1464,12 +1469,14 @@ log_thread(void *arg)
errcode = pthread_cond_wait(&a->need_commits,
&tog_mutex);
if (errcode)
- err = got_error_set_errno(errcode);
+ err = got_error_set_errno(errcode,
+ "pthread_cond_wait");
}
errcode = pthread_mutex_unlock(&tog_mutex);
if (errcode && err == NULL)
- err = got_error_set_errno(errcode);
+ err = got_error_set_errno(errcode,
+ "pthread_mutex_unlock");
}
a->log_complete = 1;
return (void *)err;
@@ -1485,22 +1492,25 @@ stop_log_thread(struct tog_log_view_state *s)
s->quit = 1;
errcode = pthread_cond_signal(&s->thread_args.need_commits);
if (errcode)
- return got_error_set_errno(errcode);
+ return got_error_set_errno(errcode,
+ "pthread_cond_signal");
errcode = pthread_mutex_unlock(&tog_mutex);
if (errcode)
- return got_error_set_errno(errcode);
+ return got_error_set_errno(errcode,
+ "pthread_mutex_unlock");
errcode = pthread_join(s->thread, (void **)&err);
if (errcode)
- return got_error_set_errno(errcode);
+ return got_error_set_errno(errcode, "pthread_join");
errcode = pthread_mutex_lock(&tog_mutex);
if (errcode)
- return got_error_set_errno(errcode);
+ return got_error_set_errno(errcode,
+ "pthread_mutex_lock");
s->thread = NULL;
}
errcode = pthread_cond_destroy(&s->thread_args.need_commits);
if (errcode && err == NULL)
- err = got_error_set_errno(errcode);
+ err = got_error_set_errno(errcode, "pthread_cond_destroy");
if (s->thread_args.repo) {
got_repo_close(s->thread_args.repo);
@@ -1571,7 +1581,7 @@ open_log_view(struct tog_view *view, struct got_object_id *start_id,
errcode = pthread_cond_init(&s->thread_args.need_commits, NULL);
if (errcode) {
- err = got_error_set_errno(errcode);
+ err = got_error_set_errno(errcode, "pthread_cond_init");
goto done;
}
@@ -1601,7 +1611,7 @@ show_log_view(struct tog_view *view)
int errcode = pthread_create(&s->thread, NULL, log_thread,
&s->thread_args);
if (errcode)
- return got_error_set_errno(errcode);
+ return got_error_set_errno(errcode, "pthread_create");
}
return draw_commits(view, &s->last_displayed_entry,
@@ -2685,7 +2695,7 @@ blame_cb(void *arg, int nlines, int lineno, struct got_object_id *id)
errcode = pthread_mutex_lock(&tog_mutex);
if (errcode)
- return got_error_set_errno(errcode);
+ return got_error_set_errno(errcode, "pthread_mutex_lock");
if (*a->quit) { /* user has quit the blame view */
err = got_error(GOT_ERR_ITER_COMPLETED);
@@ -2708,7 +2718,7 @@ blame_cb(void *arg, int nlines, int lineno, struct got_object_id *id)
done:
errcode = pthread_mutex_unlock(&tog_mutex);
if (errcode)
- err = got_error_set_errno(errcode);
+ err = got_error_set_errno(errcode, "pthread_mutex_unlock");
return err;
}
@@ -2725,7 +2735,8 @@ blame_thread(void *arg)
errcode = pthread_mutex_lock(&tog_mutex);
if (errcode)
- return (void *)got_error_set_errno(errcode);
+ return (void *)got_error_set_errno(errcode,
+ "pthread_mutex_lock");
got_repo_close(ta->repo);
ta->repo = NULL;
@@ -2733,7 +2744,7 @@ blame_thread(void *arg)
errcode = pthread_mutex_unlock(&tog_mutex);
if (errcode && err == NULL)
- err = got_error_set_errno(errcode);
+ err = got_error_set_errno(errcode, "pthread_mutex_unlock");
return (void *)err;
}
@@ -2761,13 +2772,15 @@ stop_blame(struct tog_blame *blame)
int errcode;
errcode = pthread_mutex_unlock(&tog_mutex);
if (errcode)
- return got_error_set_errno(errcode);
+ return got_error_set_errno(errcode,
+ "pthread_mutex_unlock");
errcode = pthread_join(blame->thread, (void **)&err);
if (errcode)
- return got_error_set_errno(errcode);
+ return got_error_set_errno(errcode, "pthread_join");
errcode = pthread_mutex_lock(&tog_mutex);
if (errcode)
- return got_error_set_errno(errcode);
+ return got_error_set_errno(errcode,
+ "pthread_mutex_lock");
if (err && err->code == GOT_ERR_ITER_COMPLETED)
err = NULL;
blame->thread = NULL;
@@ -2937,7 +2950,7 @@ show_blame_view(struct tog_view *view)
errcode = pthread_create(&s->blame.thread, NULL, blame_thread,
&s->blame.thread_args);
if (errcode)
- return got_error_set_errno(errcode);
+ return got_error_set_errno(errcode, "pthread_create");
}
err = draw_blame(view, s->blamed_commit->id, s->blame.f,