mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-14 05:53:59 +00:00
Correctly invoke callbacks with fishd-less universal variables. All
tests now pass.
This commit is contained in:
parent
3b4794ae94
commit
d7f22a0c27
4 changed files with 35 additions and 10 deletions
|
@ -289,7 +289,10 @@ void env_universal_init(wchar_t * p,
|
||||||
{
|
{
|
||||||
if (! synchronizes_via_fishd())
|
if (! synchronizes_via_fishd())
|
||||||
{
|
{
|
||||||
|
external_callback = cb;
|
||||||
|
env_universal_common_init(&callback);
|
||||||
env_universal_read_from_file();
|
env_universal_read_from_file();
|
||||||
|
s_env_univeral_inited = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -379,6 +382,12 @@ void env_universal_barrier()
|
||||||
message_t *msg;
|
message_t *msg;
|
||||||
fd_set fds;
|
fd_set fds;
|
||||||
|
|
||||||
|
if (! synchronizes_via_fishd())
|
||||||
|
{
|
||||||
|
env_universal_common_sync();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!s_env_univeral_inited || is_dead())
|
if (!s_env_univeral_inited || is_dead())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -443,7 +452,7 @@ void env_universal_set(const wcstring &name, const wcstring &value, bool exportv
|
||||||
|
|
||||||
debug(3, L"env_universal_set( \"%ls\", \"%ls\" )", name.c_str(), value.c_str());
|
debug(3, L"env_universal_set( \"%ls\", \"%ls\" )", name.c_str(), value.c_str());
|
||||||
|
|
||||||
if (is_dead())
|
if (! synchronizes_via_fishd() || is_dead())
|
||||||
{
|
{
|
||||||
env_universal_common_set(name.c_str(), value.c_str(), exportv);
|
env_universal_common_set(name.c_str(), value.c_str(), exportv);
|
||||||
}
|
}
|
||||||
|
@ -480,7 +489,7 @@ int env_universal_remove(const wchar_t *name)
|
||||||
L"env_universal_remove( \"%ls\" )",
|
L"env_universal_remove( \"%ls\" )",
|
||||||
name);
|
name);
|
||||||
|
|
||||||
if (is_dead())
|
if (! synchronizes_via_fishd() || is_dead())
|
||||||
{
|
{
|
||||||
env_universal_common_remove(name_str);
|
env_universal_common_remove(name_str);
|
||||||
}
|
}
|
||||||
|
|
|
@ -234,6 +234,11 @@ void env_universal_common_set(const wchar_t *key, const wchar_t *val, bool expor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void env_universal_common_sync()
|
||||||
|
{
|
||||||
|
default_universal_vars().sync();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Attempt to send the specified message to the specified file descriptor
|
Attempt to send the specified message to the specified file descriptor
|
||||||
|
|
||||||
|
@ -859,7 +864,7 @@ bool env_universal_t::open_and_acquire_lock(const wcstring &path, int *out_fd)
|
||||||
return result_fd >= 0;
|
return result_fd >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool env_universal_t::save()
|
bool env_universal_t::sync()
|
||||||
{
|
{
|
||||||
scoped_lock locker(lock);
|
scoped_lock locker(lock);
|
||||||
/* Our saving strategy:
|
/* Our saving strategy:
|
||||||
|
@ -884,6 +889,13 @@ bool env_universal_t::save()
|
||||||
Permission denied / other errors: log to the console (once) and then give up
|
Permission denied / other errors: log to the console (once) and then give up
|
||||||
*/
|
*/
|
||||||
const wcstring vars_path = explicit_vars_path.empty() ? default_vars_path() : explicit_vars_path;
|
const wcstring vars_path = explicit_vars_path.empty() ? default_vars_path() : explicit_vars_path;
|
||||||
|
|
||||||
|
/* If we have no changes, just load */
|
||||||
|
if (modified.empty())
|
||||||
|
{
|
||||||
|
return this->load_from_path(vars_path);
|
||||||
|
}
|
||||||
|
|
||||||
const wcstring directory = wdirname(vars_path);
|
const wcstring directory = wdirname(vars_path);
|
||||||
bool success = false;
|
bool success = false;
|
||||||
int vars_fd = -1;
|
int vars_fd = -1;
|
||||||
|
|
|
@ -189,6 +189,9 @@ env_var_t env_universal_common_get(const wcstring &name);
|
||||||
*/
|
*/
|
||||||
bool env_universal_common_get_export(const wcstring &name);
|
bool env_universal_common_get_export(const wcstring &name);
|
||||||
|
|
||||||
|
/** Synchronizes all changse: writes everything out, reads stuff in */
|
||||||
|
void env_universal_common_sync();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Add messages about all existing variables to the specified connection
|
Add messages about all existing variables to the specified connection
|
||||||
*/
|
*/
|
||||||
|
@ -260,8 +263,8 @@ public:
|
||||||
/** Loads variables at the correct path */
|
/** Loads variables at the correct path */
|
||||||
bool load();
|
bool load();
|
||||||
|
|
||||||
/** Writes variables at the correct path */
|
/** Reads and writes variables at the correct path */
|
||||||
bool save();
|
bool sync();
|
||||||
|
|
||||||
/* Internal use */
|
/* Internal use */
|
||||||
void read_message(connection_t *src);
|
void read_message(connection_t *src);
|
||||||
|
|
|
@ -2160,7 +2160,7 @@ static void test_input()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define UVARS_PER_THREAD 100
|
#define UVARS_PER_THREAD 8
|
||||||
|
|
||||||
static int test_universal_helper(int *x)
|
static int test_universal_helper(int *x)
|
||||||
{
|
{
|
||||||
|
@ -2170,10 +2170,10 @@ static int test_universal_helper(int *x)
|
||||||
const wcstring key = format_string(L"key_%d_%d", *x, j);
|
const wcstring key = format_string(L"key_%d_%d", *x, j);
|
||||||
const wcstring val = format_string(L"val_%d_%d", *x, j);
|
const wcstring val = format_string(L"val_%d_%d", *x, j);
|
||||||
uvars.set(key, val, false);
|
uvars.set(key, val, false);
|
||||||
bool saved = uvars.save();
|
bool synced = uvars.sync();
|
||||||
if (! saved)
|
if (! synced)
|
||||||
{
|
{
|
||||||
err(L"Failed to save universal variables");
|
err(L"Failed to sync universal variables");
|
||||||
}
|
}
|
||||||
fputc('.', stderr);
|
fputc('.', stderr);
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
|
@ -2186,7 +2186,7 @@ static void test_universal()
|
||||||
say(L"Testing universal variables");
|
say(L"Testing universal variables");
|
||||||
if (system("mkdir -p /tmp/fish_uvars_test/")) err(L"mkdir failed");
|
if (system("mkdir -p /tmp/fish_uvars_test/")) err(L"mkdir failed");
|
||||||
|
|
||||||
const int threads = 32;
|
const int threads = 16;
|
||||||
for (int i=0; i < threads; i++)
|
for (int i=0; i < threads; i++)
|
||||||
{
|
{
|
||||||
iothread_perform(test_universal_helper, (void (*)(int *, int))NULL, new int(i));
|
iothread_perform(test_universal_helper, (void (*)(int *, int))NULL, new int(i));
|
||||||
|
@ -2214,6 +2214,7 @@ static void test_universal()
|
||||||
}
|
}
|
||||||
|
|
||||||
system("rm -Rf /tmp/fish_uvars_test");
|
system("rm -Rf /tmp/fish_uvars_test");
|
||||||
|
putc('\n', stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
class history_tests_t
|
class history_tests_t
|
||||||
|
|
Loading…
Reference in a new issue