aboutsummaryrefslogtreecommitdiffhomepage
path: root/history.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-12-04 16:00:35 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-12-04 16:00:35 -0800
commit19eddddcffe9d49fc33d89b0e624ab9eae4e9ee4 (patch)
tree4da39edbf408533b53ca6f0d964d9174ba48d775 /history.cpp
parentb1e86d6feac5e2bb03298b67c4897045ebcba45d (diff)
Fix for issue where history file would be read immediately on launch
Diffstat (limited to 'history.cpp')
-rw-r--r--history.cpp31
1 files changed, 26 insertions, 5 deletions
diff --git a/history.cpp b/history.cpp
index e4dd529f..6a557d68 100644
--- a/history.cpp
+++ b/history.cpp
@@ -1468,14 +1468,35 @@ void history_t::clear(void)
bool history_t::is_empty(void)
{
- bool result = false;
scoped_lock locker(lock);
- if (new_items.empty())
+
+ /* If we have new items, we're not empty */
+ if (! new_items.empty())
+ return false;
+
+ bool empty = false;
+ if (loaded_old)
{
- load_old_if_needed();
- result = old_item_offsets.empty();
+ /* If we've loaded old items, see if we have any offsets */
+ empty = old_item_offsets.empty();
}
- return result;
+ else
+ {
+ /* If we have not loaded old items, don't actually load them (which may be expensive); just stat the file and see if it exists and is nonempty */
+ const wcstring where = history_filename(name, L"");
+ struct stat buf = {};
+ if (wstat(where, &buf) != 0)
+ {
+ /* Access failed, assume missing */
+ empty = true;
+ }
+ else
+ {
+ /* We're empty if the file is empty */
+ empty = (buf.st_size == 0);
+ }
+ }
+ return empty;
}
/* Indicate whether we ought to import the bash history file into fish */