mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-22 13:37:27 +08:00
Fix for issue where history file would be read immediately on launch
This commit is contained in:
parent
b1e86d6fea
commit
19eddddcff
31
history.cpp
31
history.cpp
|
@ -1468,14 +1468,35 @@ void history_t::clear(void)
|
||||||
|
|
||||||
bool history_t::is_empty(void)
|
bool history_t::is_empty(void)
|
||||||
{
|
{
|
||||||
bool result = false;
|
|
||||||
scoped_lock locker(lock);
|
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();
|
/* If we've loaded old items, see if we have any offsets */
|
||||||
result = old_item_offsets.empty();
|
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 */
|
/* Indicate whether we ought to import the bash history file into fish */
|
||||||
|
|
|
@ -159,6 +159,9 @@ private:
|
||||||
|
|
||||||
/** Loads old if necessary */
|
/** Loads old if necessary */
|
||||||
bool load_old_if_needed(void);
|
bool load_old_if_needed(void);
|
||||||
|
|
||||||
|
/** Memory maps the history file if necessary */
|
||||||
|
bool mmap_if_needed(void);
|
||||||
|
|
||||||
/** Deletes duplicates in new_items. */
|
/** Deletes duplicates in new_items. */
|
||||||
void compact_new_items();
|
void compact_new_items();
|
||||||
|
|
|
@ -694,7 +694,7 @@ void signal_unblock()
|
||||||
// debug( 0, L"signal block level decreased to %d", block_count );
|
// debug( 0, L"signal block level decreased to %d", block_count );
|
||||||
}
|
}
|
||||||
|
|
||||||
int signal_is_blocked()
|
bool signal_is_blocked()
|
||||||
{
|
{
|
||||||
return !!block_count;
|
return !!block_count;
|
||||||
}
|
}
|
||||||
|
|
2
signal.h
2
signal.h
|
@ -55,7 +55,7 @@ void signal_unblock();
|
||||||
/**
|
/**
|
||||||
Returns true if signals are being blocked
|
Returns true if signals are being blocked
|
||||||
*/
|
*/
|
||||||
int signal_is_blocked();
|
bool signal_is_blocked();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns signals with non-default handlers
|
Returns signals with non-default handlers
|
||||||
|
|
Loading…
Reference in New Issue
Block a user