mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 21:33:09 +00:00
Migrate autoload file checks to file_id_t
This commit is contained in:
parent
6dd2766a15
commit
fe75a3a650
2 changed files with 15 additions and 23 deletions
|
@ -27,20 +27,10 @@ static const int kAutoloadStalenessInterval = 15;
|
||||||
|
|
||||||
file_access_attempt_t access_file(const wcstring &path, int mode) {
|
file_access_attempt_t access_file(const wcstring &path, int mode) {
|
||||||
file_access_attempt_t result = {};
|
file_access_attempt_t result = {};
|
||||||
struct stat statbuf;
|
file_id_t file_id = file_id_for_path(path);
|
||||||
if (wstat(path, &statbuf)) {
|
if (file_id != kInvalidFileID && 0 == waccess(path, mode)) {
|
||||||
result.error = errno;
|
result.file_id = file_id;
|
||||||
} else {
|
|
||||||
result.mod_time = statbuf.st_mtime;
|
|
||||||
if (waccess(path, mode)) {
|
|
||||||
result.error = errno;
|
|
||||||
} else {
|
|
||||||
result.accessible = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note that we record the last checked time after the call, on the assumption that in a slow
|
|
||||||
// filesystem, the lag comes before the kernel check, not after.
|
|
||||||
result.last_checked = time(NULL);
|
result.last_checked = time(NULL);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -178,7 +168,7 @@ bool autoload_t::locate_file_and_maybe_load_it(const wcstring &cmd, bool really_
|
||||||
|
|
||||||
// If we can use this function, return whether we were able to access it.
|
// If we can use this function, return whether we were able to access it.
|
||||||
if (use_cached(func, really_load, allow_stale_functions)) {
|
if (use_cached(func, really_load, allow_stale_functions)) {
|
||||||
return func->access.accessible;
|
return func->access.accessible();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +184,7 @@ bool autoload_t::locate_file_and_maybe_load_it(const wcstring &cmd, bool really_
|
||||||
wcstring path = next + L"/" + cmd + L".fish";
|
wcstring path = next + L"/" + cmd + L".fish";
|
||||||
|
|
||||||
const file_access_attempt_t access = access_file(path, R_OK);
|
const file_access_attempt_t access = access_file(path, R_OK);
|
||||||
if (!access.accessible) {
|
if (!access.accessible()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,7 +195,7 @@ bool autoload_t::locate_file_and_maybe_load_it(const wcstring &cmd, bool really_
|
||||||
// Generate the source if we need to load it.
|
// Generate the source if we need to load it.
|
||||||
bool need_to_load_function =
|
bool need_to_load_function =
|
||||||
really_load &&
|
really_load &&
|
||||||
(func == NULL || func->access.mod_time != access.mod_time || !func->is_loaded);
|
(func == NULL || func->access.file_id != access.file_id || !func->is_loaded);
|
||||||
if (need_to_load_function) {
|
if (need_to_load_function) {
|
||||||
// Generate the script source.
|
// Generate the script source.
|
||||||
script_source = L"source " + escape_string(path, ESCAPE_ALL);
|
script_source = L"source " + escape_string(path, ESCAPE_ALL);
|
||||||
|
|
|
@ -15,14 +15,16 @@
|
||||||
|
|
||||||
/// Record of an attempt to access a file.
|
/// Record of an attempt to access a file.
|
||||||
struct file_access_attempt_t {
|
struct file_access_attempt_t {
|
||||||
/// Modification time of the file
|
/// If filled, the file ID of the checked file.
|
||||||
time_t mod_time;
|
/// Otherwise the file did not exist or was otherwise inaccessible.
|
||||||
/// When we last checked the file
|
/// Note that this will never contain kInvalidFileID.
|
||||||
|
maybe_t<file_id_t> file_id;
|
||||||
|
|
||||||
|
/// When we last checked the file.
|
||||||
time_t last_checked;
|
time_t last_checked;
|
||||||
/// Whether or not we believe we can access this file
|
|
||||||
bool accessible;
|
/// Whether or not we believe we can access this file.
|
||||||
/// If we cannot access the file, the error code encountered.
|
bool accessible() const { return file_id.has_value(); }
|
||||||
int error;
|
|
||||||
};
|
};
|
||||||
file_access_attempt_t access_file(const wcstring &path, int mode);
|
file_access_attempt_t access_file(const wcstring &path, int mode);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue