mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
lint: Use early exit/continue
This commit is contained in:
parent
225caa2fe8
commit
eab836864e
1 changed files with 34 additions and 32 deletions
|
@ -939,24 +939,28 @@ void history_t::populate_from_mmap(void) {
|
||||||
/// if successful. Returns the mapped memory region by reference.
|
/// if successful. Returns the mapped memory region by reference.
|
||||||
bool history_t::map_file(const wcstring &name, const char **out_map_start, size_t *out_map_len,
|
bool history_t::map_file(const wcstring &name, const char **out_map_start, size_t *out_map_len,
|
||||||
file_id_t *file_id) {
|
file_id_t *file_id) {
|
||||||
bool result = false;
|
|
||||||
wcstring filename = history_filename(name, L"");
|
wcstring filename = history_filename(name, L"");
|
||||||
if (!filename.empty()) {
|
if (filename.empty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int fd = wopen_cloexec(filename, O_RDONLY);
|
int fd = wopen_cloexec(filename, O_RDONLY);
|
||||||
if (fd >= 0) {
|
if (fd == -1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool result = false;
|
||||||
// Get the file ID if requested.
|
// Get the file ID if requested.
|
||||||
if (file_id != NULL) *file_id = file_id_for_fd(fd);
|
if (file_id != NULL) *file_id = file_id_for_fd(fd);
|
||||||
|
|
||||||
// Take a read lock to guard against someone else appending. This is released when the
|
// Take a read lock to guard against someone else appending. This is released when the file
|
||||||
// file is closed (below). We will read the file after releasing the lock, but that's
|
// is closed (below). We will read the file after releasing the lock, but that's not a
|
||||||
// not a problem, because we never modify already written data. In short, the purpose of
|
// problem, because we never modify already written data. In short, the purpose of this lock
|
||||||
// this lock is to ensure we don't see the file size change mid-update.
|
// is to ensure we don't see the file size change mid-update.
|
||||||
//
|
//
|
||||||
// We may fail to lock (e.g. on lockless NFS - see
|
// We may fail to lock (e.g. on lockless NFS - see issue #685. In that case, we proceed as
|
||||||
// https://github.com/fish-shell/fish-shell/issues/685 ). In that case, we proceed as
|
// if it did not fail. The risk is that we may get an incomplete history item; this is
|
||||||
// if it did not fail. The risk is that we may get an incomplete history item; this
|
// unlikely because we only treat an item as valid if it has a terminating newline.
|
||||||
// is unlikely because we only treat an item as valid if it has a terminating
|
|
||||||
// newline.
|
|
||||||
//
|
//
|
||||||
// Simulate a failing lock in chaos_mode.
|
// Simulate a failing lock in chaos_mode.
|
||||||
if (!chaos_mode) history_file_lock(fd, F_RDLCK);
|
if (!chaos_mode) history_file_lock(fd, F_RDLCK);
|
||||||
|
@ -974,8 +978,6 @@ bool history_t::map_file(const wcstring &name, const char **out_map_start, size_
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue