Commit Graph

533 Commits

Author SHA1 Message Date
Johannes Altmanninger
18654b1872 build.rs: silence error output of compile checks
These compile checks are expected to produce compiler errors on some systems.
The errors show up when there is an unrelated error, this is probably quite
confusing so fix that. Should revisit this later.
2023-12-01 11:59:33 +01:00
Fabian Boehm
0aa08cf267 Make wgettext_fmt! require an argument *to* format
Like FLOGF!, this now needs at least one argument to format.

This avoids some issues with missing variables and broken format
strings - it is how I found 13ba5bd405 -
where disown had a format string, with two placeholders, but no
arguments to fill them with.

For use in e.g. macros, where it's otherwise hard to tell if we have
something to format or not, this adds a wgettext_maybe_fmt! version to
"maybe" format, if necessary.
2023-11-29 21:12:21 +01:00
Johannes Altmanninger
f57c5e3a5f history: remove bogus assertion crashing on empty history items
In LastC++11, an empty history item means we either reached the end of history,
or the item is actually empty. The second meaning is still true.  We never
append empty history items but the history file might have been modified.

Fixes #10129
2023-11-29 20:26:36 +01:00
Fabian Boehm
b23057ee61 fix fmt 2023-11-29 17:03:10 +01:00
Fabian Boehm
13ba5bd405 disown: Fix a format string
Missed in 77aeb6a2a8, this would crash otherwise.
2023-11-29 16:59:53 +01:00
ridiculousfish
9b54e243b1 Add FFI bindings to universal notifiers and adopt in input_common
This removes the C++ bits for universal notifiers.
2023-11-26 17:29:53 -08:00
ridiculousfish
acd0bf1a43 Migrate uvar notifier test helper into its own module
Reduce the amount of stuff in mod.rs
2023-11-26 17:29:48 -08:00
ridiculousfish
a950a8270d Create an inotify based universal notifier for Linux
Recall that universal notifiers are used to report changes to universal
variables to other shell instances. This adds a new strategy based on using
inotify to directly monitor the universal variables
file.

We have tried this in the past and abandoned it because it doesn't properly
work on some CI systems - let's try again.
2023-11-26 17:29:48 -08:00
ridiculousfish
38d198a83a Port macOS universal notifiers to Rust
This ports the notifyd-based universal notifier to Rust.
2023-11-26 17:29:48 -08:00
ridiculousfish
99dfbaffb9 Remove an unreachable_code "allow" declaration
This is no longer necessary - all of the code is readable.
2023-11-26 17:23:02 -08:00
ridiculousfish
f773697bc1 Fix a clippy lint in ConstPointer 2023-11-25 19:12:14 -08:00
ridiculousfish
0f3d4b754f Fix some bogus unused import warnings 2023-11-25 19:12:11 -08:00
ridiculousfish
cf4f07b837 Correct a misseplling 2023-11-25 16:01:58 -08:00
Fabian Boehm
62b9a0f983 path: Keep metadata around for special permissions 2023-11-24 17:05:08 +01:00
Fabian Boehm
9d1c0da773 path: Reduce syscalls for special permissions
This

1. Skips access() if we only have "special" permissions like the owner
that need stat
2. Does the geteuid()/getegid() *once* outside of filter_path, if we
need it

In the extreme case of `path filter --perm user,group` it will remove
3 syscalls per file.
2023-11-24 17:05:08 +01:00
Yonas Yanfa
1c2440c3ac
Enable dynamic title in Rio and Foot terminals (#10115) 2023-11-24 17:04:50 +01:00
Fabian Boehm
6361362996
Replace some direct uses of libc with wrappers (#10090)
This removes some spurious unsafe blocks and makes usage a bit nicer
2023-11-19 20:07:24 +01:00
ridiculousfish
a718852ad4 Fix a typo and suppress an annoying clippy lint 2023-11-18 19:03:23 -08:00
ridiculousfish
da646a38ba Remove some unnecessary widestrs 2023-11-18 19:03:23 -08:00
ridiculousfish
f0eaa516c0 Stop boxing ParseExecutionContext
This wasn't necessary - probably a holdover from using unique_ptr in C++.
2023-11-18 19:03:23 -08:00
ridiculousfish
89376d5fd0 Fix a clippy lint 2023-11-18 19:03:23 -08:00
a-kenji
17eadcff03 Fix small typos 2023-11-18 18:27:25 -08:00
ridiculousfish
a9f346acf0 Remove some environment and null_terminated_array ffi bits
These are now unused and can be removed.
2023-11-18 11:12:25 -08:00
Johannes Altmanninger
7df70e18f4 Add hint to error message about cmdsub in command position
We might end up allowing this but let's add some help for now.

See #5575
2023-11-18 12:26:45 +01:00
Johannes Altmanninger
f3ce78bc53 history: remove spurious UTF-8 check regression
Closes #10102
2023-11-15 16:31:33 +01:00
Johannes Altmanninger
4e37dc29dc Fix autosuggestion dropping too many keyword tokens 2023-11-15 11:09:48 +01:00
Johannes Altmanninger
6569943cb8 Port builtin read 2023-11-15 11:09:48 +01:00
Johannes Altmanninger
77aeb6a2a8 Port execution
Drop support for history file version 1.

ParseExecutionContext no longer contains an OperationContext because in my
first implementation, ParseExecutionContext didn't have interior mutability.
We should probably try to add it back.

Add a few to-do style comments. Search for "todo!" and "PORTING".

Co-authored-by: Xiretza <xiretza@xiretza.xyz>
(complete, wildcard, expand, history, history/file)
Co-authored-by: Henrik Hørlück Berg <36937807+henrikhorluck@users.noreply.github.com>
(builtins/set)
2023-11-15 11:09:48 +01:00
Johannes Altmanninger
c4155db933 Rename Rust-side parser_t/io_streams_t to Parser/IoStreams
This reduces noise in the upcoming "Port execution" commit.

I accidentally made IoStreams a "class" instead of a "struct".  Would be
easy to correct that but this will be deleted soon, so I don't think we care.
2023-11-15 11:09:48 +01:00
Johannes Altmanninger
aaa48e89a5 Temporarily rename Rust-native IoStreams to make way
The next commit will use this name.
2023-11-15 11:09:48 +01:00
Johannes Altmanninger
6280fcc8c5 Don't use virtual dispatch for OutputStream
It's not really needed since we know all specializations.
Also this allows us to define generic methods like

    fn append(&self, s: AsRef<wstr>);
2023-11-15 11:09:48 +01:00
Johannes Altmanninger
7fd4ad025a Traced refcell and mutex wrappers for debugging 2023-11-15 11:09:48 +01:00
Johannes Altmanninger
aec6b9e5e1 common: simplify a variable definition 2023-11-15 11:09:48 +01:00
Fabian Boehm
0f8bcb0414
wildcard: Rationalize file/command completions (#10052)
* wildcard: Remove file size from the description

We no longer add descriptions for normal file completions, so this was
only ever reached if this was a command completion, and then it was
only added if the file wasn't a regular file... in which case it can't
be an executable.

So this was dead.

* Make possible_link() a maybe

This gives us the full information, not just "no" or "maybe"

* wildcard: Rationalize file/command completions

This keeps the entry_t as long as possible, and asks it, so especially
on systems with working d_type we can get by without a single stat in
most cases.

Then it guts file_get_desc, because that is only used for command
completions - we have been disabling file descriptions for *years*,
and so this is never called there.

That means we have no need to print descriptions about e.g. broken symlinks, because those are not executable.

Put together, what this means is that we, in most cases, only do
an *access(2)* call instead of a stat, because that might be checking
more permissions.

So we have the following constellations:

- If we have d_type:
  - We need a stat() for every _symlink_ to get the type (e.g. dir or regular)
    (this is for most symlinks, if we want to know if it's a dir or executable)
  - We need an access() for every file for executables
- If we do not have d_type:
  - We need a stat() for every file
  - We need an lstat() for every file if we do descriptions
    (i.e. just for command completion)
  - We need an access() for every file for executables

As opposed to the current way, where every file gets one lstat whether
with d_type or not, and an additional stat() for links, *and* an
access.

So we go from two syscalls to one for executables.

* Some more comments

* rust link option

* rust remove size

* rust accessovaganza

* Check for .dll first for WSL

This saves quite a few checks if e.g. System32 is in $PATH (which it
is if you inherit windows paths, IIRC).

Note: Our WSL check currently fails for WSL2, where this would
be *more* important because of how abysmal the filesystem performance
on that is.
2023-10-14 08:45:15 +02:00
Johannes Altmanninger
773a507b01 fish.rs: fix regression in fish_xdm_login_hack_hack_hack_hack
This is off by one from the C++ version.

It wasn't super obvious why this worked in the first place.
Looks like args[0] is "-" because we are invoked like

    fish -c 'exec "${@}"' - "${@}"

and it looks like "-" is treated like "--" by bash, so we emulate that.
See https://github.com/fish-shell/fish-shell/issues/367#issuecomment-11740812
2023-10-13 19:58:50 +02:00
Johannes Altmanninger
b8c5627eb1 io: use Vec::with_capacity 2023-10-13 19:53:45 +02:00
Johannes Altmanninger
bba0103103 build.rs: re-run if compat.c changed 2023-10-12 21:55:11 +02:00
Mahmoud Al-Qudsi
0233c0c437 fix is_windows_subsystem_for_linux(), check for post-fork-safety
This function only ever returns true if target_os=linux, so we need to invert
the OS check.

In the first invocation, this function may allocate heap memory.
Clarify that this is safe.

[ja: I don't have the original commit handy so I made up the log message]
2023-10-08 20:48:24 +02:00
Johannes Altmanninger
0a48f4b55c common: remove deprecated methods 2023-10-08 20:46:53 +02:00
Johannes Altmanninger
b583c51238 Sort clippy lints 2023-10-08 20:46:53 +02:00
Johannes Altmanninger
d15e475440 event: reduce lock scope to allow re-locking in event handler
The following "Port execution" commit will use RefCell for the wait handle
store.  If we hold a borrow while we are running an event (which may run
script code) there will be a borrowing conflict. Avoid this by returning
the borrow earlier.
2023-10-08 20:46:53 +02:00
Johannes Altmanninger
575c271461 job_group: reuse RelaxedAtomicBool 2023-10-08 20:46:53 +02:00
Johannes Altmanninger
d764625069 getcwd: fix bad error message 2023-10-08 20:46:53 +02:00
Johannes Altmanninger
ad75c72621 flog: reuse write_to_fd 2023-10-08 20:46:53 +02:00
Johannes Altmanninger
637926a7fd env: fix porting regression recording inherited vars 2023-10-08 20:46:53 +02:00
Johannes Altmanninger
d8de497ebc Use shorter escape() function 2023-10-08 20:46:53 +02:00
Johannes Altmanninger
0b25793097 wildcard: use "zelf" over "this" for consistency
The following "Port execution" commit will add lots of variables called "zelf".
2023-10-08 20:46:53 +02:00
Johannes Altmanninger
e8712af0c3 builtin random: make option parsing consistent with other builtins again
As suggested in a comment on2fb352a9e (Address some clippy lints from nightly
clippy, 2023-10-03).
2023-10-08 20:46:53 +02:00
Fabian Boehm
86803e4442
Reduce stat calls for wildcards ending in "/" (#10032)
This makes it so expand_intermediate_segment knows about the case
where it's last, only followed by a "/".

When it is, it can do without the file_id for finding links (we don't
resolve the files we get here), which allows us to remove a stat()
call.

This speeds up the case of `...*/` by quite a bit.

If that last component was a directory with 1000 subdirectories we
could skip 1000 stat calls!

One slight weirdness: We refuse to add links to directories that we already visited, even if they are the last component and we don't actually follow them. That means we can't do the fast path here either, but we do know if something is a link (if we get d_type), so it still works in common cases.
2023-10-08 16:46:59 +02:00
ridiculousfish
f7e7396c69 Fix a deadlock affecting fish_config
This fixes the following deadlock. The C++ functions path_get_config and
path_get_data lazily determine paths and then cache those in a C++ static
variable. The path determination requires inspecting the environment stack.
If these functions are first called while the environment stack is locked
(in this case, when fetching the $history variable) we can get a deadlock.

The fix is to call them eagerly during env_init. This can be removed once
the corresponding C++ functions are removed.

This issue caused fish_config to fail to report colors and themes.

Add a test.
2023-10-07 15:20:14 -07:00