Commit graph

79 commits

Author SHA1 Message Date
ridiculousfish
1af441b4cc Do not lock the history file on remote filesystems
This avoids using locks for the history file if the file appears to be on
a remote file system, like NFS. This is to avoid hangs if the filesystem
does not support locking.

If locking is not enabled, then in rare cases, history items may be
dropped if multiple sessions try to write to the history file at once.
This is thought to be better than hanging. Hopefully the recent change to
require a trailing newline will avoid propagating partial items.
2021-05-10 14:23:07 -07:00
ridiculousfish
d1fd3d5825 Detect at startup whether config and data paths are remote
This is in preparation for changing the locking regime of history.
2021-05-10 14:23:07 -07:00
ridiculousfish
541e1d2fad base_directory_t to stop storing explicit success bool
This can be trivially computed from the error code.
2021-05-10 14:23:07 -07:00
Fabian Homborg
df53d1415d
cd first, ask questions later (#7586)
cd: Just try to cd without checking first

Some filesystems are broken and error out on `stat(3)` of existing and
cd-able directories.

So we just try to `fchdir` and report errors later.

Fixes #7577.
2021-03-27 18:28:03 +01:00
Fabian Homborg
25d85bdc64 path_get_path: Remove error on unknown errno
This seems like a good idea, but there isn't anything we or anyone
else can *do* in this case. All we ever do is pile on additional
errors on the ignore pile, we can't handle any of them differently.
The command isn't a thing, so we check the next path.

The impetus for this is Cygwin apparently returning a wonderfully
useless 0, and it's not even the first one to do so.

Fixes #7785
2021-03-06 08:12:27 +01:00
Fabian Homborg
31166f4731 Simplify some duplicated path checks
This has one functional difference, in that we now report non-EACCESS
errors even for relative paths. I consider that to be a plus.

Some other sites might benefit from this, let's look into that later.
2020-12-15 18:15:59 +01:00
Fabian Homborg
0f6669f43c Stop using env_var_t::to_list in a few places
We don't need the entire list in modifiable form here - some just needs
the size, the others can just get a reference.
2020-12-15 15:47:44 +01:00
ridiculousfish
c9b42c6f1f Stop #include-ing wcstringutil.h in flog.h
This is a header dependency that we can break.
2020-07-29 17:04:18 -07:00
Fabian Homborg
1406d63b85 Restyle
I kinda hate how fussy clang-format is. It reflows text
constantly (line limit), forces things onto one line *except* when
they're too long, and wants to turn this:

```c++
    return true;;
```

into this:

```c++
    return true;
    ;
```

instead of, you know, eliminating the second semicolon?

Anyway, it is what it is and we use it, I'll just look into getting some
more slack.
2020-03-26 20:45:40 +01:00
Fabian Homborg
ee943a0821 Make unusable path warnings their own FLOG category
Fixes #6630.
2020-02-20 17:30:14 +01:00
ridiculousfish
af2265b4b0 Migrate create_directory inside path.cpp
It is not used outside of path.cpp
2020-01-28 10:30:51 -08:00
Fabian Homborg
26fa774f44 Add path flog category 2020-01-19 14:55:39 +01:00
Fabian Homborg
b09ae82ecf Remove a few less useful debug messages
These were level 5, so I'd bet nobody ever saw them
2020-01-19 14:22:50 +01:00
Fabian Homborg
024e03ab1e Replace debug(1) with FLOGF(warning) 2020-01-19 14:22:39 +01:00
ridiculousfish
6705a2efc6 Migrate a bunch of code out of common.h
Put it into wcstringutil, path, or a new file null_terminated_array.
2020-01-15 13:16:43 -08:00
Jason
3cf6ebc0e1 Amend typos and grammar errors 2019-11-25 13:07:15 +01:00
Johannes Altmanninger
5e274066e3 Always return absolute path in path_get_cdpath
Fixes #6220
2019-10-19 12:38:17 +02:00
ridiculousfish
82eca4bc86 Run clang-format on all files
The main change here is to reorder headers.
2019-10-13 15:50:48 -07:00
ridiculousfish
fc99d6c7af clang-format all files 2019-06-03 20:30:48 -07:00
Fabian Homborg
7525befadb path_get_path: Narrow string before
This cuts down on the wcs2string here by ~25%.

The better solution would be to cache narrow versions of $PATH, since
we compute that over and over and over and over again, while it rarely changes.

Or we could add a full path-cache (where which command is), but that's
much harder to invalidate.

See #5905.
2019-06-01 09:57:18 +02:00
Fabian Homborg
d73ee4d54b More using FLOGF when formatting is needed
sed-patched, every time a "%" is used in a call to `FLOG`, we use
`FLOGF` instead.
2019-05-30 11:54:09 +02:00
ridiculousfish
ea9d1ad82f Convert debug(0) calls to FLOG 2019-05-27 17:31:17 -07:00
Fabian Homborg
1faffa515e Don't crash if CDPATH is "./"
Fixes #5887.
2019-05-22 21:48:40 +02:00
Fabian Homborg
c2970f9618 Reformat all files
This runs build_tools/style.fish, which runs clang-format on C++, fish_indent on fish and (new) black on python.

If anything is wrong with the formatting, we should fix the tools, but automated formatting is worth it.
2019-05-05 12:09:25 +02:00
ridiculousfish
649d3ac101 Simplify reporting of invalid config paths
Do this at a well defined point, instead of randomly the first time they're
queried.
2019-05-01 17:51:51 -07:00
ridiculousfish
72e43a514b Correct the warning for invalid directories
This was inadvertently broken.
2019-05-01 17:47:50 -07:00
Aaron Gyes
b064eaa571 use std::move in a couple spots where things were unsed after copy 2019-04-04 14:16:34 -07:00
Fabian Homborg
b86200938f Always use "." for cd
Nobody doesn't want to use $PWD to cd, so if $CDPATH does not include
it that was a mistake.

Bash also appends "." here.

Fixes #4484.
2019-03-26 10:11:36 +01:00
Aaron Gyes
477b2e8d7c std::vector<wcstring> is wcstring_list_t 2019-03-14 11:17:26 -07:00
Aaron Gyes
aaacdb89b6 Switches over to cstring from string.h. 2019-03-12 15:09:36 -07:00
Aaron Gyes
d5ac239f68 This commit changes wchar.h includes to cwchar, and uses std::
for everything it provides.
2019-03-12 15:09:36 -07:00
ridiculousfish
3b1709180f Instantize env_get 2019-01-10 20:07:53 -08:00
ridiculousfish
6f52e6bb1c Instantize contents of exec.cpp and others 2019-01-10 20:07:47 -08:00
ridiculousfish
03b92ffe00 Clean up path_get_cdpath and path_can_be_implicit_cd 2019-01-10 20:07:10 -08:00
ridiculousfish
c1dd284b3e Instantize env_set
Switch env_set to an instance method on environmnet_t.
2019-01-10 20:05:45 -08:00
ridiculousfish
391af6af0c Introduce class environment_t
This will be used as a base class for variable snapshots and variable stacks.
2019-01-10 20:29:10 -08:00
ridiculousfish
a8ce7bad7b Always pass in the working directory in path_get_cdpath
If the user is in a directory which has been unlinked, it is possible
for the path .. to not exist, relative to the working directory.
Always pass in the working directory (potentially virtual) to
path_get_cdpath; this ensures we check absolute paths and are immune
from issues if the working directory has been unlinked.

Also introduce a new function path_normalize_for_cd which normalizes the
"join point" of a path and a working directory. This allows us to 'cd' out of
a non-existent directory, but not cd into such a directory.

Fixes #5341
2018-11-18 14:36:42 -08:00
Mahmoud Al-Qudsi
e753581df7 Bring some consistency and rationale to debug log levels
* Debug level 3: describe all commands being executed (this is, after all,
a shell and one can argue that this is the most important debug
information avaliable)
* Debug level 4: details of execution, mainly fork vs no-fork and io
handling

Also introduced j->preview() to print a short descriptor of the job
based on the head of the first process so we don't overwhelm with
needless repitition, but also so that we don't have to rely on
distinguishing between repeated, non-unique/non-monotonic job ids that
are often recycled within a single "execution cycle" (pressing enter
once).
2018-10-27 18:01:38 -05:00
Fabian Homborg
f64a87a374 path: Make working_directory wcstring
Kinda weird that that one was a wchar_t*
2018-10-23 19:10:14 +02:00
ridiculousfish
bd7fea55c4 Remove some unnecessary env_var_t usage 2018-09-30 18:20:59 -04:00
ridiculousfish
6147e9ee0d path_get_cdpath to accept string instead of env_var_t
Unclear why it ever needed an env_var_t. wcstring is sufficient and much
simpler.
2018-09-30 18:13:14 -04:00
ridiculousfish
f3da54d99c Convert some iterators to C++-11 range-based loops 2018-09-16 15:49:18 -07:00
Mahmoud Al-Qudsi
a6d64c1086 Handle odd return codes for waccess(..) in src/path.cpp under Solaris 2018-06-17 19:58:20 -05:00
Mahmoud Al-Qudsi
56c041b889 Work around WSL access(2) EINVAL bug
See Microsoft/BashOnWindows#2522, Microsoft/BashOnWindows#2448
2017-09-24 13:43:50 -05:00
ridiculousfish
3d40292c00 Switch env_var to using maybe_t
This eliminates the "missing" notion of env_var_t. Instead
env_get returns a maybe_t<env_var_t>, which forces callers to
handle the possibility that the variable is missing.
2017-09-01 00:14:42 -07:00
ridiculousfish
4baada25b9 Use move semantics instead of swap in env_set
This commit backs out certain optimizations around setting environment
variables, and replaces them with move semantics. env_set accepts a
list,  by value, permitting callers to use std::move to transfer
ownership.
2017-08-30 00:59:45 -07:00
Kurtis Rader
f872f25f5b change env_var_t to a vector of strings
Internally fish should store vars as a vector of elements. The current
flat string representation is a holdover from when the code was written
in C.

Fixes #4200
2017-08-18 16:24:30 -07:00
Mahmoud Al-Qudsi
e6bb7fc973 Silence unused result warnings on newer compilers
Newer versions of GCC and Clang are not satisfied by a cast to void,
this fix is adapted from glibc's solution.

New wrapper function ignore_result should be used when a function with
explicit _unused_attribute_ wrapper is called whose result will not be
handled.
2017-08-14 18:18:10 -07:00
Kurtis Rader
58b604c5ba change order of env_set() args
It's bugged me forever that the scope is the second arg to `env_get()`
but not `env_set()`. And since I'll be introducing some helper functions
that wrap `env_set()` now is a good time to change the order of its
arguments.
2017-08-14 18:18:09 -07:00
Kurtis Rader
728a4634a1 replace var_entry_t with env_var_t
This is a step to storing fish vars as actual vectors rather than flat
strings.
2017-08-14 18:18:09 -07:00