paintedwolf-ai's picture
Release open1-b5-e4-bialy
24918f7 verified
Raw History Blame Contribute Delete
202 kB
{"repo":"fd","file":"Makefile","line":1,"symbol":"PROFILE?","kind":"variable","lang":"make","code":"PROFILE?=release"}
{"repo":"fd","file":"Makefile","line":2,"symbol":"EXE","kind":"variable","lang":"make","code":"EXE=target/$(PROFILE)/fd"}
{"repo":"fd","file":"Makefile","line":3,"symbol":"prefix","kind":"variable","lang":"make","code":"prefix=/usr/local"}
{"repo":"fd","file":"Makefile","line":4,"symbol":"bindir","kind":"variable","lang":"make","code":"bindir=$(prefix)/bin"}
{"repo":"fd","file":"Makefile","line":5,"symbol":"datadir","kind":"variable","lang":"make","code":"datadir=$(prefix)/share"}
{"repo":"fd","file":"Makefile","line":6,"symbol":"exe_name","kind":"variable","lang":"make","code":"exe_name=fd"}
{"repo":"fd","file":"Makefile","line":13,"symbol":"archive_path","kind":"variable","lang":"make","code":"archive_path=package/$(ARCHIVE_NAME).tar.gz"}
{"repo":"fd","file":"Makefile","line":18,"symbol":".PHONY","kind":"target","lang":"make","code":".PHONY: completions"}
{"repo":"fd","file":"Makefile","line":19,"symbol":"completions","kind":"target","lang":"make","code":"completions: autocomplete/fd.bash autocomplete/fd.fish autocomplete/_fd.ps1 autocomplete/_fd autocomplete/_fdfind autocomplete/fdfind.bash autocomplete/fdfind.fish"}
{"repo":"fd","file":"Makefile","line":21,"symbol":"comp_dir","kind":"variable","lang":"make","code":"comp_dir=@mkdir -p autocomplete"}
{"repo":"fd","file":"Makefile","line":23,"symbol":"autocomplete/fd.bash","kind":"target","lang":"make","code":"autocomplete/fd.bash: $(EXE)\n\t$(comp_dir)\n\t$(EXE) --gen-completions bash > $@"}
{"repo":"fd","file":"Makefile","line":27,"symbol":"autocomplete/fd.fish","kind":"target","lang":"make","code":"autocomplete/fd.fish: $(EXE)\n\t$(comp_dir)\n\t$(EXE) --gen-completions fish > $@"}
{"repo":"fd","file":"Makefile","line":31,"symbol":"autocomplete/_fd.ps1","kind":"target","lang":"make","code":"autocomplete/_fd.ps1: $(EXE)\n\t$(comp_dir)\n\t$(EXE) --gen-completions powershell > $@"}
{"repo":"fd","file":"Makefile","line":35,"symbol":"autocomplete/_fd","kind":"target","lang":"make","code":"autocomplete/_fd: contrib/completion/_fd\n\t$(comp_dir)\n\tcp $< $@"}
{"repo":"fd","file":"Makefile","line":39,"symbol":"autocomplete/_fdfind","kind":"target","lang":"make","code":"autocomplete/_fdfind: contrib/completion/_fdfind\n\t$(comp_dir)\n\tcp $< $@"}
{"repo":"fd","file":"Makefile","line":43,"symbol":"autocomplete/fdfind.bash","kind":"target","lang":"make","code":"autocomplete/fdfind.bash: contrib/completion/fdfind.bash\n\t$(comp_dir)\n\tcp $< $@"}
{"repo":"fd","file":"Makefile","line":47,"symbol":"autocomplete/fdfind.fish","kind":"target","lang":"make","code":"autocomplete/fdfind.fish: contrib/completion/fdfind.fish\n\t$(comp_dir)\n\tcp $< $@"}
{"repo":"fd","file":"Makefile","line":51,"symbol":"archive","kind":"target","lang":"make","code":"archive: $(archive_path)"}
{"repo":"fd","file":"Makefile","line":56,"symbol":"install","kind":"target","lang":"make","code":"install: $(EXE) completions\n\tinstall -Dm755 $(EXE) $(DESTDIR)$(bindir)/fd\n\tinstall -Dm644 autocomplete/fd.bash $(DESTDIR)/$(datadir)/bash-completion/completions/$(exe_name)\n\tinstall -Dm644 autocomplete/fd.fish $(DESTDIR)/$(datadir)/fish/vendor_completions.d/$(exe_name).fish\n\tinstall -Dm644 autocomplete/_fd $(DESTDIR)/$(datadir)/zsh/site-functions/_fd\n\tinstall -Dm644 autocomplete/fdfind.bash $(DESTDIR)/$(datadir)/zsh/site-functions/fdfind.bash\n\tinstall -Dm644 autocomplete/fdfind.fish $(DESTDIR)/$(datadir)/zsh/site-functions/fdfind.fish\n\tinstall -Dm644 autocomplete/_fdfind $(DESTDIR)/$(datadir)/zsh/site-functions/_fdfind\n\tinstall -Dm644 doc/fd.1 $(DESTDIR)/$(datadir)/man/man1/$(exe_name).1"}
{"repo":"fd","file":"doc/screencast.sh","line":9,"symbol":"PROMPT","kind":"variable","lang":"bash","code":"PROMPT=\"▶\""}
{"repo":"fd","file":"doc/screencast.sh","line":11,"symbol":"enter","kind":"function","lang":"bash","code":"enter() {\n INPUT=$1\n DELAY=1\n\n prompt\n sleep \"$DELAY\"\n type \"$INPUT\"\n sleep 0.5\n printf '%b' \"\\\\n\"\n eval \"$INPUT\"\n type \"\\\\n\"\n}"}
{"repo":"fd","file":"doc/screencast.sh","line":12,"symbol":"INPUT","kind":"variable","lang":"bash","code":"INPUT=$1"}
{"repo":"fd","file":"doc/screencast.sh","line":13,"symbol":"DELAY","kind":"variable","lang":"bash","code":"DELAY=1"}
{"repo":"fd","file":"doc/screencast.sh","line":24,"symbol":"prompt","kind":"function","lang":"bash","code":"prompt() {\n printf '%b ' \"$PROMPT\" | pv -q\n}"}
{"repo":"fd","file":"doc/screencast.sh","line":28,"symbol":"type","kind":"function","lang":"bash","code":"type() {\n printf '%b' \"$1\" | pv -qL $((10+(-2 + RANDOM%5)))\n}"}
{"repo":"fd","file":"doc/screencast.sh","line":32,"symbol":"main","kind":"function","lang":"bash","code":"main() {\n IFS='%'\n\n enter \"fd\"\n\n enter \"fd app\"\n\n enter \"fd fi\"\n\n enter \"fd fi --type f\"\n\n enter \"fd --type d\"\n\n enter \"fd -e md\"\n\n enter \"fd -e md --exec wc -l\"\n\n enter \"fd '^[A-Z]'\"\n\n enter \"fd --exclude src\"\n\n enter \"fd --hidden sample\"\n\n prompt\n\n sleep 3\n\n echo \"\"\n\n unset IFS\n}"}
{"repo":"fd","file":"doc/screencast.sh","line":33,"symbol":"IFS","kind":"variable","lang":"bash","code":"IFS='%'"}
{"repo":"fd","file":"scripts/create-archive.sh","line":16,"symbol":"TARGET","kind":"variable","lang":"bash","code":"TARGET=\"$(rustc -vV | sed -n 's/host: //p')\""}
{"repo":"fd","file":"scripts/create-archive.sh","line":19,"symbol":"PKG_suffix","kind":"variable","lang":"bash","code":"PKG_suffix=\".tar.gz\""}
{"repo":"fd","file":"scripts/create-archive.sh","line":20,"symbol":"EXE_suffix","kind":"variable","lang":"bash","code":"EXE_suffix=\"\""}
{"repo":"fd","file":"scripts/create-archive.sh","line":23,"symbol":"PKG_suffix","kind":"variable","lang":"bash","code":"PKG_suffix=\".zip\""}
{"repo":"fd","file":"scripts/create-archive.sh","line":24,"symbol":"EXE_suffix","kind":"variable","lang":"bash","code":"EXE_suffix=\".exe\""}
{"repo":"fd","file":"scripts/create-archive.sh","line":29,"symbol":"BIN_PATH","kind":"variable","lang":"bash","code":"BIN_PATH=target/${PROFILE:-release}/fd"}
{"repo":"fd","file":"scripts/create-archive.sh","line":33,"symbol":"ARCHIVE_NAME","kind":"variable","lang":"bash","code":"ARCHIVE_NAME=fd"}
{"repo":"fd","file":"scripts/create-archive.sh","line":34,"symbol":"ARCHIVE_NAME","kind":"variable","lang":"bash","code":"ARCHIVE_NAME+=\"-v$VERSION\""}
{"repo":"fd","file":"scripts/create-archive.sh","line":37,"symbol":"PKG_NAME","kind":"variable","lang":"bash","code":"PKG_NAME=${ARCHIVE_NAME}${PKG_suffix}"}
{"repo":"fd","file":"scripts/create-archive.sh","line":39,"symbol":"staging_dir","kind":"variable","lang":"bash","code":"staging_dir=\"${PKG_STAGING:-package}\""}
{"repo":"fd","file":"scripts/create-archive.sh","line":40,"symbol":"ARCHIVE_DIR","kind":"variable","lang":"bash","code":"ARCHIVE_DIR=\"${staging_dir}/${ARCHIVE_NAME}/\""}
{"repo":"fd","file":"scripts/create-deb.sh","line":2,"symbol":"COPYRIGHT_YEARS","kind":"variable","lang":"bash","doc":"!/bin/bash","code":"COPYRIGHT_YEARS=\"2018 - \"$(date \"+%Y\")"}
{"repo":"fd","file":"scripts/create-deb.sh","line":3,"symbol":"MAINTAINER","kind":"variable","lang":"bash","code":"MAINTAINER=\"David Peter <mail@david-peter.de>\""}
{"repo":"fd","file":"scripts/create-deb.sh","line":4,"symbol":"REPO","kind":"variable","lang":"bash","code":"REPO=\"https://github.com/sharkdp/fd\""}
{"repo":"fd","file":"scripts/create-deb.sh","line":5,"symbol":"DPKG_STAGING","kind":"variable","lang":"bash","code":"DPKG_STAGING=\"${CICD_INTERMEDIATES_DIR:-.}/debian-package\""}
{"repo":"fd","file":"scripts/create-deb.sh","line":6,"symbol":"DPKG_DIR","kind":"variable","lang":"bash","code":"DPKG_DIR=\"${DPKG_STAGING}/dpkg\""}
{"repo":"fd","file":"scripts/create-deb.sh","line":10,"symbol":"TARGET","kind":"variable","lang":"bash","code":"TARGET=\"$(rustc -vV | sed -n 's|host: \\(.*\\)|\\1|p')\""}
{"repo":"fd","file":"scripts/create-deb.sh","line":15,"symbol":"DPKG_BASENAME","kind":"variable","lang":"bash","code":"DPKG_BASENAME=fd-musl"}
{"repo":"fd","file":"scripts/create-deb.sh","line":16,"symbol":"DPKG_CONFLICTS","kind":"variable","lang":"bash","code":"DPKG_CONFLICTS=\"fd, fd-find\""}
{"repo":"fd","file":"scripts/create-deb.sh","line":19,"symbol":"DPKG_BASENAME","kind":"variable","lang":"bash","code":"DPKG_BASENAME=fd"}
{"repo":"fd","file":"scripts/create-deb.sh","line":20,"symbol":"DPKG_CONFLICTS","kind":"variable","lang":"bash","code":"DPKG_CONFLICTS=\"fd-musl, fd-find\""}
{"repo":"fd","file":"scripts/create-deb.sh","line":25,"symbol":"DPKG_VERSION","kind":"variable","lang":"bash","code":"DPKG_VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r .packages[0].version)"}
{"repo":"fd","file":"scripts/create-deb.sh","line":30,"symbol":"DPKG_ARCH","kind":"variable","lang":"bash","code":"DPKG_ARCH=arm64"}
{"repo":"fd","file":"scripts/create-deb.sh","line":31,"symbol":"DPKG_ARCH","kind":"variable","lang":"bash","code":"DPKG_ARCH=armhf"}
{"repo":"fd","file":"scripts/create-deb.sh","line":32,"symbol":"DPKG_ARCH","kind":"variable","lang":"bash","code":"DPKG_ARCH=i686"}
{"repo":"fd","file":"scripts/create-deb.sh","line":33,"symbol":"DPKG_ARCH","kind":"variable","lang":"bash","code":"DPKG_ARCH=amd64"}
{"repo":"fd","file":"scripts/create-deb.sh","line":34,"symbol":"DPKG_ARCH","kind":"variable","lang":"bash","code":"DPKG_ARCH=notset"}
{"repo":"fd","file":"scripts/create-deb.sh","line":37,"symbol":"DPKG_NAME","kind":"variable","lang":"bash","code":"DPKG_NAME=\"${DPKG_BASENAME}_${DPKG_VERSION}_${DPKG_ARCH}.deb\""}
{"repo":"fd","file":"scripts/create-deb.sh","line":39,"symbol":"BIN_PATH","kind":"variable","lang":"bash","code":"BIN_PATH=${BIN_PATH:-target/${TARGET}/release/fd}"}
{"repo":"fd","file":"scripts/create-deb.sh","line":127,"symbol":"DPKG_PATH","kind":"variable","lang":"bash","code":"DPKG_PATH=\"${DPKG_STAGING}/${DPKG_NAME}\""}
{"repo":"fd","file":"scripts/version-bump.sh","line":7,"symbol":"version","kind":"variable","lang":"bash","code":"version=\"$1\""}
{"repo":"fd","file":"scripts/version-bump.sh","line":17,"symbol":"msrv","kind":"variable","lang":"bash","code":"msrv=\"$(grep -F rust-version Cargo.toml | sed -e 's/^rust-version= \"\\(.*\\)\"/\\1/')\""}
{"repo":"fd","file":"src/cli.rs","line":31,"symbol":"Opts","kind":"type","lang":"rust","code":"pub struct Opts {\n /// Include hidden directories and files in the search results (default:\n /// hidden files and directories are skipped). Files and directories are\n /// considered to be hidden if their name starts with a `.` sign (dot).\n /// Any files or directories that are ignored due to the rules described by\n /// --no-ignore are still ignored unless otherwise specified.\n /// The flag can be overridden with --no-hidden.\n #[arg(\n long,\n short = 'H',\n help = \"Search hidden files and directories\",\n long_help\n )]\n pub hidden: bool,\n\n /// Overrides --hidden\n #[arg(long, overrides_with = \"hidden\", hide = true, action = ArgAction::SetTrue)]\n no_hidden: (),\n\n /// Show search results from files and directories that would otherwise be\n /// ignored by '.gitignore', '.ignore', '.fdignore', or the global ignore file,\n /// The flag can be overridden with --ignore.\n #[arg(\n long,\n short = 'I',\n help = \"Do not respect .(git|fd)ignore files\",\n long_help\n )]\n pub no_ignore: bool,\n\n /// Overrides --no-ignore\n #[arg(long, overrides_with = \"no_ignore\", hide = true, action = ArgAction"}
{"repo":"fd","file":"src/cli.rs","line":697,"symbol":"search_paths","kind":"function","lang":"rust","code":"pub fn search_paths(&self) -> anyhow::Result<Vec<PathBuf>> {\n // would it make sense to concatenate these?\n let paths = if !self.path.is_empty() {\n &self.path\n } else if !self.search_path.is_empty() {\n &self.search_path\n } else {\n let current_directory = Path::new(\"./\");\n ensure_current_directory_exists(current_directory)?;\n return Ok(vec![self.normalize_path(current_directory)]);\n };\n Ok(paths\n .iter()\n .filter_map(|path| {\n if filesystem::is_existing_directory(path) {\n Some(self.normalize_path(path))\n } else {\n // We use debug for the path to make it more readable if it has special characters\n // Should we use a more reliable escape?\n print_error!(\n \"Search path {:?} is not a directory.\",\n path.to_string_lossy().as_ref()\n );\n None\n }\n })\n .collect())\n }"}
{"repo":"fd","file":"src/cli.rs","line":726,"symbol":"normalize_path","kind":"function","lang":"rust","code":"fn normalize_path(&self, path: &Path) -> PathBuf {\n if self.absolute_path {\n filesystem::absolute_path(path.normalize().unwrap().as_path()).unwrap()\n } else if path == Path::new(\".\") {\n // Change \".\" to \"./\" as a workaround for https://github.com/BurntSushi/ripgrep/pull/2711\n PathBuf::from(\"./\")\n } else if path == Path::new(\"-\") {\n // Prefix \"-\" so the underlying walker treats it as a path.\n // See sharkdp/fd#849.\n Path::new(\".\").join(path)\n } else {\n path.to_path_buf()\n }\n }"}
{"repo":"fd","file":"src/cli.rs","line":741,"symbol":"no_search_paths","kind":"function","lang":"rust","code":"pub fn no_search_paths(&self) -> bool {\n self.path.is_empty() && self.search_path.is_empty()\n }"}
{"repo":"fd","file":"src/cli.rs","line":746,"symbol":"rg_alias_ignore","kind":"function","lang":"rust","code":"pub fn rg_alias_ignore(&self) -> bool {\n self.rg_alias_hidden_ignore > 0\n }"}
{"repo":"fd","file":"src/cli.rs","line":750,"symbol":"max_depth","kind":"function","lang":"rust","code":"pub fn max_depth(&self) -> Option<usize> {\n self.max_depth.or(self.exact_depth)\n }"}
{"repo":"fd","file":"src/cli.rs","line":754,"symbol":"min_depth","kind":"function","lang":"rust","code":"pub fn min_depth(&self) -> Option<usize> {\n self.min_depth.or(self.exact_depth)\n }"}
{"repo":"fd","file":"src/cli.rs","line":758,"symbol":"threads","kind":"function","lang":"rust","code":"pub fn threads(&self) -> NonZeroUsize {\n self.threads.unwrap_or_else(default_num_threads)\n }"}
{"repo":"fd","file":"src/cli.rs","line":762,"symbol":"max_results","kind":"function","lang":"rust","code":"pub fn max_results(&self) -> Option<usize> {\n self.max_results\n .filter(|&m| m > 0)\n .or_else(|| self.max_one_result.then_some(1))\n }"}
{"repo":"fd","file":"src/cli.rs","line":768,"symbol":"strip_cwd_prefix","kind":"function","lang":"rust","code":"pub fn strip_cwd_prefix<P: FnOnce() -> bool>(&self, auto_pred: P) -> bool {\n use self::StripCwdWhen::*;\n self.no_search_paths()\n && match self.strip_cwd_prefix.map_or(Auto, |o| o.unwrap_or(Always)) {\n Auto => auto_pred(),\n Always => true,\n Never => false,\n }\n }"}
{"repo":"fd","file":"src/cli.rs","line":779,"symbol":"gen_completions","kind":"function","lang":"rust","code":"pub fn gen_completions(&self) -> anyhow::Result<Option<Shell>> {\n self.gen_completions\n .map(|maybe_shell| match maybe_shell {\n Some(sh) => Ok(sh),\n None => {\n Shell::from_env().ok_or_else(|| anyhow!(\"Unable to get shell from environment\"))\n }\n })\n .transpose()\n }"}
{"repo":"fd","file":"src/cli.rs","line":792,"symbol":"default_num_threads","kind":"function","lang":"rust","doc":"Get the default number of threads to use, if not explicitly specified.","code":"fn default_num_threads() -> NonZeroUsize {\n // If we can't get the amount of parallelism for some reason, then\n // default to a single thread, because that is safe.\n let fallback = NonZeroUsize::MIN;\n // To limit startup overhead on massively parallel machines, don't use more\n // than 64 threads.\n let limit = NonZeroUsize::new(64).unwrap();\n\n std::thread::available_parallelism()\n .unwrap_or(fallback)\n .min(limit)\n}"}
{"repo":"fd","file":"src/cli.rs","line":806,"symbol":"FileType","kind":"type","lang":"rust","code":"pub enum FileType {\n #[value(alias = \"f\")]\n File,\n #[value(alias = \"d\", alias = \"dir\")]\n Directory,\n #[value(alias = \"l\")]\n Symlink,\n #[value(alias = \"b\")]\n BlockDevice,\n #[value(alias = \"c\")]\n CharDevice,\n /// A file which is executable by the current effective user\n #[value(alias = \"x\")]\n Executable,\n #[value(alias = \"e\")]\n Empty,\n #[value(alias = \"s\")]\n Socket,\n #[value(alias = \"p\")]\n Pipe,\n}"}
{"repo":"fd","file":"src/cli.rs","line":829,"symbol":"ColorWhen","kind":"type","lang":"rust","code":"pub enum ColorWhen {\n /// show colors if the output goes to an interactive console (default)\n Auto,\n /// always use colorized output\n Always,\n /// do not use colorized output\n Never,\n}"}
{"repo":"fd","file":"src/cli.rs","line":839,"symbol":"StripCwdWhen","kind":"type","lang":"rust","code":"pub enum StripCwdWhen {\n /// Use the default behavior\n Auto,\n /// Always strip the ./ at the beginning of paths\n Always,\n /// Never strip the ./\n Never,\n}"}
{"repo":"fd","file":"src/cli.rs","line":849,"symbol":"HyperlinkWhen","kind":"type","lang":"rust","code":"pub enum HyperlinkWhen {\n /// Use hyperlinks only if color is enabled\n Auto,\n /// Always use hyperlinks when printing file paths\n Always,\n /// Never use hyperlinks\n Never,\n}"}
{"repo":"fd","file":"src/cli.rs","line":860,"symbol":"Exec","kind":"type","lang":"rust","doc":"there isn't a derive api for getting grouped values yet, so we have to use hand-rolled parsing for exec and exec-batch","code":"pub struct Exec {\n pub command: Option<CommandSet>,\n}"}
{"repo":"fd","file":"src/cli.rs","line":865,"symbol":"from_arg_matches","kind":"function","lang":"rust","code":"fn from_arg_matches(matches: &ArgMatches) -> clap::error::Result<Self> {\n let command = matches\n .get_occurrences::<String>(\"exec\")\n .map(CommandSet::new)\n .or_else(|| {\n matches\n .get_occurrences::<String>(\"exec_batch\")\n .map(CommandSet::new_batch)\n })\n .transpose()\n .map_err(|e| clap::Error::raw(ErrorKind::InvalidValue, e))?;\n Ok(Exec { command })\n }"}
{"repo":"fd","file":"src/cli.rs","line":879,"symbol":"update_from_arg_matches","kind":"function","lang":"rust","code":"fn update_from_arg_matches(&mut self, matches: &ArgMatches) -> clap::error::Result<()> {\n *self = Self::from_arg_matches(matches)?;\n Ok(())\n }"}
{"repo":"fd","file":"src/cli.rs","line":886,"symbol":"augment_args","kind":"function","lang":"rust","code":"fn augment_args(cmd: Command) -> Command {\n cmd.arg(Arg::new(\"exec\")\n .action(ArgAction::Append)\n .long(\"exec\")\n .short('x')\n .num_args(1..)\n .allow_hyphen_values(true)\n .value_terminator(\";\")\n .value_name(\"cmd\")\n .conflicts_with(\"list_details\")\n .help(\"Execute a command for each search result\")\n .long_help(\n \"Execute a command for each search result in parallel (use --threads=1 for sequential command execution). \\\n The order in which different search results are processed and their output is printed is not guaranteed, even with --threads=1. \\\n All positional arguments following --exec are considered to be arguments to the command - not to fd. \\\n It is therefore recommended to place the '-x'/'--exec' option last. \\\n Use '\\\\;' to terminate the command template if you need to continue passing fd arguments afterwards.\\n\\n\\\n Specify this option multiple times to run several commands for each file or directory found. \\\n "}
{"repo":"fd","file":"src/cli.rs","line":962,"symbol":"augment_args_for_update","kind":"function","lang":"rust","code":"fn augment_args_for_update(cmd: Command) -> Command {\n Self::augment_args(cmd)\n }"}
{"repo":"fd","file":"src/cli.rs","line":967,"symbol":"parse_millis","kind":"function","lang":"rust","code":"fn parse_millis(arg: &str) -> Result<Duration, std::num::ParseIntError> {\n Ok(Duration::from_millis(arg.parse()?))\n}"}
{"repo":"fd","file":"src/cli.rs","line":971,"symbol":"ensure_current_directory_exists","kind":"function","lang":"rust","code":"fn ensure_current_directory_exists(current_directory: &Path) -> anyhow::Result<()> {\n if filesystem::is_existing_directory(current_directory) {\n Ok(())\n } else {\n Err(anyhow!(\n \"Could not retrieve current directory (has it been deleted?).\"\n ))\n }\n}"}
{"repo":"fd","file":"src/config.rs","line":14,"symbol":"Config","kind":"type","lang":"rust","doc":"Configuration options for *fd*.","code":"pub struct Config {\n /// Whether the search is case-sensitive or case-insensitive.\n pub case_sensitive: bool,\n\n /// Cached current working directory for absolute path construction.\n /// Populated when `--full-path` is set; `None` means search by filename only.\n pub full_path_base: Option<PathBuf>,\n\n /// Whether to ignore hidden files and directories (or not).\n pub ignore_hidden: bool,\n\n /// Whether to respect `.fdignore` files or not.\n pub read_fdignore: bool,\n\n /// Whether to respect ignore files in parent directories or not.\n pub read_parent_ignore: bool,\n\n /// Whether to respect VCS ignore files (`.gitignore`, ..) or not.\n pub read_vcsignore: bool,\n\n /// Whether to require a `.git` directory to respect gitignore files.\n pub require_git_to_read_vcsignore: bool,\n\n /// Whether to respect the global ignore file or not.\n pub read_global_ignore: bool,\n\n /// Whether to follow symlinks or not.\n pub follow_links: bool,\n\n /// Whether to limit the search to starting file system or not.\n pub one_file_system: bool,\n\n /// Whether elements of output should be separated by a null character\n pub null_separator: bool,\n\n /// T"}
{"repo":"fd","file":"src/config.rs","line":140,"symbol":"is_printing","kind":"function","lang":"rust","doc":"Check whether results are being printed.","code":"pub fn is_printing(&self) -> bool {\n self.command.is_none()\n }"}
{"repo":"fd","file":"src/dir_entry.rs","line":12,"symbol":"DirEntryInner","kind":"type","lang":"rust","code":"enum DirEntryInner {\n Normal(ignore::DirEntry),\n // Broken symlinks reach us as walk errors rather than entries, so we carry\n // over the depth the walker recorded on the error.\n BrokenSymlink { path: PathBuf, depth: Option<usize> },\n}"}
{"repo":"fd","file":"src/dir_entry.rs","line":20,"symbol":"DirEntry","kind":"type","lang":"rust","code":"pub struct DirEntry {\n inner: DirEntryInner,\n metadata: OnceCell<Option<Metadata>>,\n style: OnceCell<Option<Style>>,\n}"}
{"repo":"fd","file":"src/dir_entry.rs","line":28,"symbol":"normal","kind":"function","lang":"rust","code":"pub fn normal(e: ignore::DirEntry) -> Self {\n Self {\n inner: DirEntryInner::Normal(e),\n metadata: OnceCell::new(),\n style: OnceCell::new(),\n }\n }"}
{"repo":"fd","file":"src/dir_entry.rs","line":36,"symbol":"broken_symlink","kind":"function","lang":"rust","code":"pub fn broken_symlink(path: PathBuf, depth: Option<usize>) -> Self {\n Self {\n inner: DirEntryInner::BrokenSymlink { path, depth },\n metadata: OnceCell::new(),\n style: OnceCell::new(),\n }\n }"}
{"repo":"fd","file":"src/dir_entry.rs","line":44,"symbol":"path","kind":"function","lang":"rust","code":"pub fn path(&self) -> &Path {\n match &self.inner {\n DirEntryInner::Normal(e) => e.path(),\n DirEntryInner::BrokenSymlink { path, .. } => path.as_path(),\n }\n }"}
{"repo":"fd","file":"src/dir_entry.rs","line":51,"symbol":"into_path","kind":"function","lang":"rust","code":"pub fn into_path(self) -> PathBuf {\n match self.inner {\n DirEntryInner::Normal(e) => e.into_path(),\n DirEntryInner::BrokenSymlink { path, .. } => path,\n }\n }"}
{"repo":"fd","file":"src/dir_entry.rs","line":61,"symbol":"stripped_path","kind":"function","lang":"rust","doc":"Returns the path as it should be presented to the user. When stripping `./` would leave the path starting with `-`, keep the original (with `./`) so downstream tools don't interpret it as an option.","code":"pub fn stripped_path(&self, config: &Config) -> &Path {\n let path = self.path();\n if config.strip_cwd_prefix {\n let stripped = strip_current_dir(path);\n if starts_with_dash(stripped) {\n path\n } else {\n stripped\n }\n } else {\n path\n }\n }"}
{"repo":"fd","file":"src/dir_entry.rs","line":76,"symbol":"into_stripped_path","kind":"function","lang":"rust","doc":"Returns the path as it should be presented to the user.","code":"pub fn into_stripped_path(self, config: &Config) -> PathBuf {\n if config.strip_cwd_prefix {\n self.stripped_path(config).to_path_buf()\n } else {\n self.into_path()\n }\n }"}
{"repo":"fd","file":"src/dir_entry.rs","line":84,"symbol":"file_type","kind":"function","lang":"rust","code":"pub fn file_type(&self) -> Option<FileType> {\n match &self.inner {\n DirEntryInner::Normal(e) => e.file_type(),\n DirEntryInner::BrokenSymlink { .. } => self.metadata().map(|m| m.file_type()),\n }\n }"}
{"repo":"fd","file":"src/dir_entry.rs","line":91,"symbol":"metadata","kind":"function","lang":"rust","code":"pub fn metadata(&self) -> Option<&Metadata> {\n self.metadata\n .get_or_init(|| match &self.inner {\n DirEntryInner::Normal(e) => e.metadata().ok(),\n DirEntryInner::BrokenSymlink { path, .. } => path.symlink_metadata().ok(),\n })\n .as_ref()\n }"}
{"repo":"fd","file":"src/dir_entry.rs","line":100,"symbol":"depth","kind":"function","lang":"rust","code":"pub fn depth(&self) -> Option<usize> {\n match &self.inner {\n DirEntryInner::Normal(e) => Some(e.depth()),\n DirEntryInner::BrokenSymlink { depth, .. } => *depth,\n }\n }"}
{"repo":"fd","file":"src/dir_entry.rs","line":107,"symbol":"style","kind":"function","lang":"rust","code":"pub fn style(&self, ls_colors: &LsColors) -> Option<&Style> {\n self.style\n .get_or_init(|| ls_colors.style_for(self).cloned())\n .as_ref()\n }"}
{"repo":"fd","file":"src/dir_entry.rs","line":114,"symbol":"starts_with_dash","kind":"function","lang":"rust","code":"fn starts_with_dash(path: &Path) -> bool {\n path.as_os_str().as_encoded_bytes().first() == Some(&b'-')\n}"}
{"repo":"fd","file":"src/dir_entry.rs","line":120,"symbol":"eq","kind":"function","lang":"rust","code":"fn eq(&self, other: &Self) -> bool {\n self.path() == other.path()\n }"}
{"repo":"fd","file":"src/dir_entry.rs","line":129,"symbol":"partial_cmp","kind":"function","lang":"rust","code":"fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {\n Some(self.cmp(other))\n }"}
{"repo":"fd","file":"src/dir_entry.rs","line":136,"symbol":"cmp","kind":"function","lang":"rust","code":"fn cmp(&self, other: &Self) -> std::cmp::Ordering {\n self.path().cmp(other.path())\n }"}
{"repo":"fd","file":"src/dir_entry.rs","line":142,"symbol":"path","kind":"function","lang":"rust","code":"fn path(&self) -> PathBuf {\n self.path().to_owned()\n }"}
{"repo":"fd","file":"src/dir_entry.rs","line":146,"symbol":"file_name","kind":"function","lang":"rust","code":"fn file_name(&self) -> OsString {\n let name = match &self.inner {\n DirEntryInner::Normal(e) => e.file_name(),\n DirEntryInner::BrokenSymlink { path, .. } => {\n // Path::file_name() only works if the last component is Normal,\n // but we want it for all component types, so we open code it.\n // Copied from LsColors::style_for_path_with_metadata().\n path.components()\n .next_back()\n .map(|c| c.as_os_str())\n .unwrap_or_else(|| path.as_os_str())\n }\n };\n name.to_owned()\n }"}
{"repo":"fd","file":"src/dir_entry.rs","line":162,"symbol":"file_type","kind":"function","lang":"rust","code":"fn file_type(&self) -> Option<FileType> {\n self.file_type()\n }"}
{"repo":"fd","file":"src/dir_entry.rs","line":166,"symbol":"metadata","kind":"function","lang":"rust","code":"fn metadata(&self) -> Option<Metadata> {\n self.metadata().cloned()\n }"}
{"repo":"fd","file":"src/dir_entry.rs","line":177,"symbol":"dash_prefixed_paths_detected","kind":"function","lang":"rust","code":"fn dash_prefixed_paths_detected() {\n assert!(starts_with_dash(Path::new(\"-rf\")));\n assert!(starts_with_dash(Path::new(\"--delete\")));\n assert!(starts_with_dash(Path::new(\"-\")));\n }"}
{"repo":"fd","file":"src/dir_entry.rs","line":184,"symbol":"safe_paths_not_flagged","kind":"function","lang":"rust","code":"fn safe_paths_not_flagged() {\n assert!(!starts_with_dash(Path::new(\"foo\")));\n assert!(!starts_with_dash(Path::new(\"./foo\")));\n assert!(!starts_with_dash(Path::new(\"sub/-rf\")));\n assert!(!starts_with_dash(Path::new(\"\")));\n assert!(!starts_with_dash(Path::new(\" -rf\")));\n }"}
{"repo":"fd","file":"src/error.rs","line":14,"symbol":"SanitizeErr","kind":"type","lang":"rust","doc":"Trait for specifying how to sanitize a type for error display, if needed.","code":"pub(crate) trait SanitizeErr {\n type Sanitized: Display;\n\n fn sanitize(self) -> Self::Sanitized;\n}"}
{"repo":"fd","file":"src/error.rs","line":17,"symbol":"sanitize","kind":"function","lang":"rust","code":"fn sanitize(self) -> Self::Sanitized;"}
{"repo":"fd","file":"src/error.rs","line":23,"symbol":"sanitize","kind":"function","lang":"rust","code":"fn sanitize(self) -> Self {\n self\n }"}
{"repo":"fd","file":"src/error.rs","line":31,"symbol":"sanitize","kind":"function","lang":"rust","code":"fn sanitize(self) -> Self::Sanitized {\n SanitizedError(self)\n }"}
{"repo":"fd","file":"src/error.rs","line":39,"symbol":"sanitize","kind":"function","lang":"rust","code":"fn sanitize(self) -> Self::Sanitized {\n SanitizedError(self)\n }"}
{"repo":"fd","file":"src/error.rs","line":44,"symbol":"SanitizedError","kind":"type","lang":"rust","code":"pub struct SanitizedError<E>(E);"}
{"repo":"fd","file":"src/error.rs","line":47,"symbol":"fmt","kind":"function","lang":"rust","code":"fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n let raw = self.0.to_string();\n write_sanitized(f, &raw)\n }"}
{"repo":"fd","file":"src/exec/command.rs","line":8,"symbol":"Outputs","kind":"type","lang":"rust","code":"struct Outputs {\n stdout: Vec<u8>,\n stderr: Vec<u8>,\n}"}
{"repo":"fd","file":"src/exec/command.rs","line":12,"symbol":"OutputBuffer","kind":"type","lang":"rust","code":"pub struct OutputBuffer {\n null_separator: bool,\n outputs: Vec<Outputs>,\n}"}
{"repo":"fd","file":"src/exec/command.rs","line":18,"symbol":"new","kind":"function","lang":"rust","code":"pub fn new(null_separator: bool) -> Self {\n Self {\n null_separator,\n outputs: Vec::new(),\n }\n }"}
{"repo":"fd","file":"src/exec/command.rs","line":25,"symbol":"push","kind":"function","lang":"rust","code":"fn push(&mut self, stdout: Vec<u8>, stderr: Vec<u8>) {\n self.outputs.push(Outputs { stdout, stderr });\n }"}
{"repo":"fd","file":"src/exec/command.rs","line":29,"symbol":"write","kind":"function","lang":"rust","code":"fn write(self) {\n // Avoid taking the lock if there is nothing to do.\n // If null_separator is true, then we still need to write the\n // null separator, because the output may have been written directly\n // to stdout\n if self.outputs.is_empty() && !self.null_separator {\n return;\n }\n\n let stdout = io::stdout();\n let stderr = io::stderr();\n\n // While we hold these locks, only this thread will be able\n // to write its outputs.\n let mut stdout = stdout.lock();\n let mut stderr = stderr.lock();\n\n for output in self.outputs.iter() {\n let _ = stdout.write_all(&output.stdout);\n let _ = stderr.write_all(&output.stderr);\n }\n if self.null_separator {\n // If null_separator is enabled, then we should write a \\0 at the end\n // of the output for this entry\n let _ = stdout.write_all(b\"\\0\");\n }\n }"}
{"repo":"fd","file":"src/exec/command.rs","line":59,"symbol":"execute_commands","kind":"function","lang":"rust","doc":"Executes a command.","code":"pub fn execute_commands<I: Iterator<Item = io::Result<Command>>>(\n cmds: I,\n mut output_buffer: OutputBuffer,\n enable_output_buffering: bool,\n) -> ExitCode {\n for result in cmds {\n let mut cmd = match result {\n Ok(cmd) => cmd,\n Err(e) => return handle_cmd_error(None, e),\n };\n\n // Spawn the supplied command.\n let output = if enable_output_buffering {\n cmd.output()\n } else {\n // If running on only one thread, don't buffer output\n // Allows for viewing and interacting with intermediate command output\n cmd.spawn().and_then(|c| c.wait_with_output())\n };\n\n // Then wait for the command to exit, if it was spawned.\n match output {\n Ok(output) => {\n if enable_output_buffering {\n output_buffer.push(output.stdout, output.stderr);\n }\n if output.status.code() != Some(0) {\n output_buffer.write();\n return ExitCode::GeneralError;\n }\n }\n Err(why) => {\n output_buffer.write();\n return handle_c"}
{"repo":"fd","file":"src/exec/command.rs","line":100,"symbol":"handle_cmd_error","kind":"function","lang":"rust","code":"pub fn handle_cmd_error(cmd: Option<&Command>, err: io::Error) -> ExitCode {\n match (cmd, err) {\n (Some(cmd), err) if err.kind() == io::ErrorKind::NotFound => {\n print_error!(\n \"Command not found: {:?}\",\n cmd.get_program().to_string_lossy().as_ref()\n );\n ExitCode::GeneralError\n }\n (_, err) => {\n print_error!(\"Problem while executing command: {}\", err);\n ExitCode::GeneralError\n }\n }\n}"}
{"repo":"fd","file":"src/exec/job.rs","line":10,"symbol":"job","kind":"function","lang":"rust","doc":"An event loop that listens for inputs from the `rx` receiver. Each received input will generate a command with the supplied command template. The generated command will then be executed, and this process will continue until the receiver's sender has closed.","code":"pub fn job(\n results: impl IntoIterator<Item = WorkerResult>,\n cmd: &CommandSet,\n config: &Config,\n) -> ExitCode {\n // Output should be buffered when only running a single thread\n let buffer_output: bool = config.threads > 1;\n\n let mut ret = ExitCode::Success;\n for result in results {\n // Obtain the next result from the receiver, else if the channel\n // has closed, exit from the loop\n let dir_entry = match result {\n WorkerResult::Entry(dir_entry) => dir_entry,\n WorkerResult::Error(err) => {\n if config.show_filesystem_errors {\n print_error!(\"{}\", err);\n }\n continue;\n }\n };\n\n // Generate a command, execute it and store its exit code.\n let code = cmd.execute(\n dir_entry.stripped_path(config),\n config.path_separator.as_deref(),\n config.null_separator,\n buffer_output,\n );\n ret = merge_exitcodes([ret, code]);\n }\n // Returns error in case of any error.\n ret\n}"}
{"repo":"fd","file":"src/exec/job.rs","line":45,"symbol":"batch","kind":"function","lang":"rust","code":"pub fn batch(\n results: impl IntoIterator<Item = WorkerResult>,\n cmd: &CommandSet,\n config: &Config,\n) -> ExitCode {\n let paths = results\n .into_iter()\n .filter_map(|worker_result| match worker_result {\n WorkerResult::Entry(dir_entry) => Some(dir_entry.into_stripped_path(config)),\n WorkerResult::Error(err) => {\n if config.show_filesystem_errors {\n print_error!(\"{}\", err);\n }\n None\n }\n });\n\n cmd.execute_batch(paths, config.batch_size, config.path_separator.as_deref())\n}"}
{"repo":"fd","file":"src/exec/mod.rs","line":22,"symbol":"ExecutionMode","kind":"type","lang":"rust","doc":"Execution mode of the command","code":"pub enum ExecutionMode {\n /// Command is executed for each search result\n OneByOne,\n /// Command is run for a batch of results at once\n Batch,\n}"}
{"repo":"fd","file":"src/exec/mod.rs","line":30,"symbol":"CommandSet","kind":"type","lang":"rust","code":"pub struct CommandSet {\n mode: ExecutionMode,\n commands: Vec<CommandTemplate>,\n}"}
{"repo":"fd","file":"src/exec/mod.rs","line":36,"symbol":"new","kind":"function","lang":"rust","code":"pub fn new<I, T, S>(input: I) -> Result<CommandSet>\n where\n I: IntoIterator<Item = T>,\n T: IntoIterator<Item = S>,\n S: AsRef<str>,\n {\n Ok(CommandSet {\n mode: ExecutionMode::OneByOne,\n commands: input\n .into_iter()\n .map(|args| CommandTemplate::new(args, ExecutionMode::OneByOne))\n .collect::<Result<_>>()?,\n })\n }"}
{"repo":"fd","file":"src/exec/mod.rs","line":51,"symbol":"new_batch","kind":"function","lang":"rust","code":"pub fn new_batch<I, T, S>(input: I) -> Result<CommandSet>\n where\n I: IntoIterator<Item = T>,\n T: IntoIterator<Item = S>,\n S: AsRef<str>,\n {\n Ok(CommandSet {\n mode: ExecutionMode::Batch,\n commands: input\n .into_iter()\n .map(|args| {\n let cmd = CommandTemplate::new(args, ExecutionMode::Batch)?;\n if cmd.number_of_tokens() > 1 {\n bail!(\"Only one placeholder allowed for batch commands\");\n }\n Ok(cmd)\n })\n .collect::<Result<Vec<_>>>()?,\n })\n }"}
{"repo":"fd","file":"src/exec/mod.rs","line":72,"symbol":"in_batch_mode","kind":"function","lang":"rust","code":"pub fn in_batch_mode(&self) -> bool {\n self.mode == ExecutionMode::Batch\n }"}
{"repo":"fd","file":"src/exec/mod.rs","line":76,"symbol":"execute","kind":"function","lang":"rust","code":"pub fn execute(\n &self,\n input: &Path,\n path_separator: Option<&str>,\n null_separator: bool,\n buffer_output: bool,\n ) -> ExitCode {\n let commands = self\n .commands\n .iter()\n .map(|c| c.generate(input, path_separator));\n execute_commands(commands, OutputBuffer::new(null_separator), buffer_output)\n }"}
{"repo":"fd","file":"src/exec/mod.rs","line":90,"symbol":"execute_batch","kind":"function","lang":"rust","code":"pub fn execute_batch<I>(&self, paths: I, limit: usize, path_separator: Option<&str>) -> ExitCode\n where\n I: Iterator<Item = PathBuf>,\n {\n let builders: io::Result<Vec<_>> = self\n .commands\n .iter()\n .map(|c| CommandBuilder::new(c, limit))\n .collect();\n\n match builders {\n Ok(mut builders) => {\n for path in paths {\n for builder in &mut builders {\n if let Err(e) = builder.push(&path, path_separator) {\n return handle_cmd_error(Some(&builder.cmd), e);\n }\n }\n }\n\n for builder in &mut builders {\n if let Err(e) = builder.finish() {\n return handle_cmd_error(Some(&builder.cmd), e);\n }\n }\n\n merge_exitcodes(builders.iter().map(|b| b.exit_code()))\n }\n Err(e) => handle_cmd_error(None, e),\n }\n }"}
{"repo":"fd","file":"src/exec/mod.rs","line":125,"symbol":"CommandBuilder","kind":"type","lang":"rust","doc":"Represents a multi-exec command as it is built.","code":"struct CommandBuilder {\n pre_args: Vec<OsString>,\n path_arg: FormatTemplate,\n post_args: Vec<OsString>,\n cmd: Command,\n count: usize,\n limit: usize,\n exit_code: ExitCode,\n}"}
{"repo":"fd","file":"src/exec/mod.rs","line":136,"symbol":"new","kind":"function","lang":"rust","code":"fn new(template: &CommandTemplate, limit: usize) -> io::Result<Self> {\n let mut pre_args = vec![];\n let mut path_arg = None;\n let mut post_args = vec![];\n\n for arg in &template.args {\n if arg.has_tokens() {\n path_arg = Some(arg.clone());\n } else if path_arg.is_none() {\n pre_args.push(arg.generate(\"\", None));\n } else {\n post_args.push(arg.generate(\"\", None));\n }\n }\n\n let cmd = Self::new_command(&pre_args)?;\n\n Ok(Self {\n pre_args,\n path_arg: path_arg.unwrap(),\n post_args,\n cmd,\n count: 0,\n limit,\n exit_code: ExitCode::Success,\n })\n }"}
{"repo":"fd","file":"src/exec/mod.rs","line":164,"symbol":"new_command","kind":"function","lang":"rust","code":"fn new_command(pre_args: &[OsString]) -> io::Result<Command> {\n let mut cmd = Command::new(&pre_args[0]);\n cmd.stdin(Stdio::inherit());\n cmd.stdout(Stdio::inherit());\n cmd.stderr(Stdio::inherit());\n cmd.try_args(&pre_args[1..])?;\n Ok(cmd)\n }"}
{"repo":"fd","file":"src/exec/mod.rs","line":173,"symbol":"push","kind":"function","lang":"rust","code":"fn push(&mut self, path: &Path, separator: Option<&str>) -> io::Result<()> {\n if self.limit > 0 && self.count >= self.limit {\n self.finish()?;\n }\n\n let arg = self.path_arg.generate(path, separator);\n if !self\n .cmd\n .args_would_fit(iter::once(&arg).chain(&self.post_args))\n {\n self.finish()?;\n }\n\n self.cmd.try_arg(arg)?;\n self.count += 1;\n Ok(())\n }"}
{"repo":"fd","file":"src/exec/mod.rs","line":191,"symbol":"finish","kind":"function","lang":"rust","code":"fn finish(&mut self) -> io::Result<()> {\n if self.count > 0 {\n self.cmd.try_args(&self.post_args)?;\n if !self.cmd.status()?.success() {\n self.exit_code = ExitCode::GeneralError;\n }\n\n self.cmd = Self::new_command(&self.pre_args)?;\n self.count = 0;\n }\n\n Ok(())\n }"}
{"repo":"fd","file":"src/exec/mod.rs","line":205,"symbol":"exit_code","kind":"function","lang":"rust","code":"fn exit_code(&self) -> ExitCode {\n self.exit_code\n }"}
{"repo":"fd","file":"src/exec/mod.rs","line":215,"symbol":"CommandTemplate","kind":"type","lang":"rust","doc":"Represents a template that is utilized to generate command strings. The template is meant to be coupled with an input in order to generate a command. The `generate_and_execute()` method will be used to generate a command and execute it.","code":"struct CommandTemplate {\n args: Vec<FormatTemplate>,\n}"}
{"repo":"fd","file":"src/exec/mod.rs","line":220,"symbol":"new","kind":"function","lang":"rust","code":"fn new<I, S>(input: I, mode: ExecutionMode) -> Result<CommandTemplate>\n where\n I: IntoIterator<Item = S>,\n S: AsRef<str>,\n {\n let mut args = Vec::new();\n let mut has_placeholder = false;\n\n for arg in input {\n let arg = arg.as_ref();\n\n let tmpl = FormatTemplate::parse(arg);\n has_placeholder |= tmpl.has_tokens();\n args.push(tmpl);\n }\n\n // We need to check that we have at least one argument, because if not\n // it will try to execute each file and directory it finds.\n //\n // Sadly, clap can't currently handle this for us, see\n // https://github.com/clap-rs/clap/issues/3542\n if args.is_empty() {\n bail!(\"No executable provided for --exec or --exec-batch\");\n }\n\n // A placeholder as the executable is meaningful for `--exec` but never for `--exec-batch`.\n if mode == ExecutionMode::Batch && args[0].has_tokens() {\n bail!(\"First argument of --exec-batch must be a fixed executable, not a placeholder\");\n }\n\n // If a placeholder token was not supplied, append one at the end of the command.\n if !has_pla"}
{"repo":"fd","file":"src/exec/mod.rs","line":258,"symbol":"number_of_tokens","kind":"function","lang":"rust","code":"fn number_of_tokens(&self) -> usize {\n self.args.iter().filter(|arg| arg.has_tokens()).count()\n }"}
{"repo":"fd","file":"src/exec/mod.rs","line":266,"symbol":"generate","kind":"function","lang":"rust","doc":"Generates and executes a command. Using the internal `args` field, and a supplied `input` variable, a `Command` will be build.","code":"fn generate(&self, input: &Path, path_separator: Option<&str>) -> io::Result<Command> {\n let mut cmd = Command::new(self.args[0].generate(input, path_separator));\n for arg in &self.args[1..] {\n cmd.try_arg(arg.generate(input, path_separator))?;\n }\n Ok(cmd)\n }"}
{"repo":"fd","file":"src/exec/mod.rs","line":279,"symbol":"generate_str","kind":"function","lang":"rust","code":"fn generate_str(template: &CommandTemplate, input: &str) -> Vec<String> {\n template\n .args\n .iter()\n .map(|arg| arg.generate(input, None).into_string().unwrap())\n .collect()\n }"}
{"repo":"fd","file":"src/exec/mod.rs","line":288,"symbol":"tokens_with_placeholder","kind":"function","lang":"rust","code":"fn tokens_with_placeholder() {\n assert_eq!(\n CommandSet::new(vec![vec![&\"echo\", &\"${SHELL}:\"]]).unwrap(),\n CommandSet {\n commands: vec![CommandTemplate {\n args: vec![\n FormatTemplate::Text(\"echo\".into()),\n FormatTemplate::Text(\"${SHELL}:\".into()),\n FormatTemplate::Tokens(vec![Token::Placeholder]),\n ]\n }],\n mode: ExecutionMode::OneByOne,\n }\n );\n }"}
{"repo":"fd","file":"src/exec/mod.rs","line":305,"symbol":"tokens_with_no_extension","kind":"function","lang":"rust","code":"fn tokens_with_no_extension() {\n assert_eq!(\n CommandSet::new(vec![vec![\"echo\", \"{.}\"]]).unwrap(),\n CommandSet {\n commands: vec![CommandTemplate {\n args: vec![\n FormatTemplate::Text(\"echo\".into()),\n FormatTemplate::Tokens(vec![Token::NoExt]),\n ],\n }],\n mode: ExecutionMode::OneByOne,\n }\n );\n }"}
{"repo":"fd","file":"src/exec/mod.rs","line":321,"symbol":"tokens_with_basename","kind":"function","lang":"rust","code":"fn tokens_with_basename() {\n assert_eq!(\n CommandSet::new(vec![vec![\"echo\", \"{/}\"]]).unwrap(),\n CommandSet {\n commands: vec![CommandTemplate {\n args: vec![\n FormatTemplate::Text(\"echo\".into()),\n FormatTemplate::Tokens(vec![Token::Basename]),\n ],\n }],\n mode: ExecutionMode::OneByOne,\n }\n );\n }"}
{"repo":"fd","file":"src/exec/mod.rs","line":337,"symbol":"tokens_with_parent","kind":"function","lang":"rust","code":"fn tokens_with_parent() {\n assert_eq!(\n CommandSet::new(vec![vec![\"echo\", \"{//}\"]]).unwrap(),\n CommandSet {\n commands: vec![CommandTemplate {\n args: vec![\n FormatTemplate::Text(\"echo\".into()),\n FormatTemplate::Tokens(vec![Token::Parent]),\n ],\n }],\n mode: ExecutionMode::OneByOne,\n }\n );\n }"}
{"repo":"fd","file":"src/exec/mod.rs","line":353,"symbol":"tokens_with_basename_no_extension","kind":"function","lang":"rust","code":"fn tokens_with_basename_no_extension() {\n assert_eq!(\n CommandSet::new(vec![vec![\"echo\", \"{/.}\"]]).unwrap(),\n CommandSet {\n commands: vec![CommandTemplate {\n args: vec![\n FormatTemplate::Text(\"echo\".into()),\n FormatTemplate::Tokens(vec![Token::BasenameNoExt]),\n ],\n }],\n mode: ExecutionMode::OneByOne,\n }\n );\n }"}
{"repo":"fd","file":"src/exec/mod.rs","line":369,"symbol":"tokens_with_literal_braces","kind":"function","lang":"rust","code":"fn tokens_with_literal_braces() {\n let template =\n CommandTemplate::new(vec![\"{{}}\", \"{{\", \"{.}}\"], ExecutionMode::OneByOne).unwrap();\n assert_eq!(\n generate_str(&template, \"foo\"),\n vec![\"{}\", \"{\", \"{.}\", \"foo\"]\n );\n }"}
{"repo":"fd","file":"src/exec/mod.rs","line":379,"symbol":"tokens_with_literal_braces_and_placeholder","kind":"function","lang":"rust","code":"fn tokens_with_literal_braces_and_placeholder() {\n let template =\n CommandTemplate::new(vec![\"echo\", \"{{{},end}\"], ExecutionMode::OneByOne).unwrap();\n assert_eq!(generate_str(&template, \"foo\"), vec![\"echo\", \"{foo,end}\"]);\n }"}
{"repo":"fd","file":"src/exec/mod.rs","line":386,"symbol":"tokens_multiple","kind":"function","lang":"rust","code":"fn tokens_multiple() {\n assert_eq!(\n CommandSet::new(vec![vec![\"cp\", \"{}\", \"{/.}.ext\"]]).unwrap(),\n CommandSet {\n commands: vec![CommandTemplate {\n args: vec![\n FormatTemplate::Text(\"cp\".into()),\n FormatTemplate::Tokens(vec![Token::Placeholder]),\n FormatTemplate::Tokens(vec![\n Token::BasenameNoExt,\n Token::Text(\".ext\".into())\n ]),\n ],\n }],\n mode: ExecutionMode::OneByOne,\n }\n );\n }"}
{"repo":"fd","file":"src/exec/mod.rs","line":406,"symbol":"tokens_single_batch","kind":"function","lang":"rust","code":"fn tokens_single_batch() {\n assert_eq!(\n CommandSet::new_batch(vec![vec![\"echo\", \"{.}\"]]).unwrap(),\n CommandSet {\n commands: vec![CommandTemplate {\n args: vec![\n FormatTemplate::Text(\"echo\".into()),\n FormatTemplate::Tokens(vec![Token::NoExt]),\n ],\n }],\n mode: ExecutionMode::Batch,\n }\n );\n }"}
{"repo":"fd","file":"src/exec/mod.rs","line":422,"symbol":"tokens_multiple_batch","kind":"function","lang":"rust","code":"fn tokens_multiple_batch() {\n assert!(CommandSet::new_batch(vec![vec![\"echo\", \"{.}\", \"{}\"]]).is_err());\n }"}
{"repo":"fd","file":"src/exec/mod.rs","line":427,"symbol":"template_no_args","kind":"function","lang":"rust","code":"fn template_no_args() {\n assert!(\n CommandTemplate::new::<Vec<_>, &'static str>(vec![], ExecutionMode::OneByOne).is_err()\n );\n }"}
{"repo":"fd","file":"src/exec/mod.rs","line":434,"symbol":"command_set_no_args","kind":"function","lang":"rust","code":"fn command_set_no_args() {\n assert!(CommandSet::new(vec![vec![\"echo\"], vec![]]).is_err());\n }"}
{"repo":"fd","file":"src/exec/mod.rs","line":439,"symbol":"placeholder_as_executable_rejected","kind":"function","lang":"rust","code":"fn placeholder_as_executable_rejected() {\n assert!(CommandSet::new(vec![vec![\"{}\"]]).is_ok());\n assert!(CommandSet::new(vec![vec![\"{/}\", \"arg\"]]).is_ok());\n assert!(CommandSet::new_batch(vec![vec![\"{}\"]]).is_err());\n }"}
{"repo":"fd","file":"src/exec/mod.rs","line":446,"symbol":"generate_custom_path_separator","kind":"function","lang":"rust","code":"fn generate_custom_path_separator() {\n let arg = FormatTemplate::Tokens(vec![Token::Placeholder]);\n macro_rules! check {\n ($input:expr, $expected:expr) => {\n assert_eq!(arg.generate($input, Some(\"#\")), OsString::from($expected));\n };\n }\n\n check!(\"foo\", \"foo\");\n check!(\"foo/bar\", \"foo#bar\");\n check!(\"/foo/bar/baz\", \"#foo#bar#baz\");\n }"}
{"repo":"fd","file":"src/exec/mod.rs","line":461,"symbol":"generate_custom_path_separator_windows","kind":"function","lang":"rust","code":"fn generate_custom_path_separator_windows() {\n let arg = FormatTemplate::Tokens(vec![Token::Placeholder]);\n macro_rules! check {\n ($input:expr, $expected:expr) => {\n assert_eq!(arg.generate($input, Some(\"#\")), OsString::from($expected));\n };\n }\n\n // path starting with a drive letter\n check!(r\"C:\\foo\\bar\", \"C:#foo#bar\");\n // UNC path\n check!(r\"\\\\server\\share\\path\", \"##server#share#path\");\n // Drive Relative path - no separator after the colon omits the RootDir path component.\n // This is uncommon, but valid\n check!(r\"C:foo\\bar\", \"C:foo#bar\");\n\n // forward slashes should get normalized and interpreted as separators\n check!(\"C:/foo/bar\", \"C:#foo#bar\");\n check!(\"C:foo/bar\", \"C:foo#bar\");\n\n // Rust does not interpret \"//server/share\" as a UNC path, but rather as a normal\n // absolute path that begins with RootDir, and the two slashes get combined together as\n // a single path separator during normalization.\n //check!(\"//server/share/path\", \"##server#share#path\");\n }"}
{"repo":"fd","file":"src/exit_codes.rs","line":7,"symbol":"ExitCode","kind":"type","lang":"rust","code":"pub enum ExitCode {\n Success,\n HasResults(bool),\n GeneralError,\n KilledBySigint,\n}"}
{"repo":"fd","file":"src/exit_codes.rs","line":15,"symbol":"from","kind":"function","lang":"rust","code":"fn from(code: ExitCode) -> Self {\n match code {\n ExitCode::Success => 0,\n ExitCode::HasResults(has_results) => !has_results as i32,\n ExitCode::GeneralError => 1,\n ExitCode::KilledBySigint => 130,\n }\n }"}
{"repo":"fd","file":"src/exit_codes.rs","line":26,"symbol":"is_error","kind":"function","lang":"rust","code":"fn is_error(self) -> bool {\n i32::from(self) != 0\n }"}
{"repo":"fd","file":"src/exit_codes.rs","line":31,"symbol":"exit","kind":"function","lang":"rust","doc":"Exit the process with the appropriate code.","code":"pub fn exit(self) -> ! {\n #[cfg(unix)]\n if self == ExitCode::KilledBySigint {\n // Get rid of the SIGINT handler, if present, and raise SIGINT\n unsafe {\n if signal(Signal::SIGINT, SigHandler::SigDfl).is_ok() {\n let _ = raise(Signal::SIGINT);\n }\n }\n }\n\n process::exit(self.into())\n }"}
{"repo":"fd","file":"src/exit_codes.rs","line":46,"symbol":"merge_exitcodes","kind":"function","lang":"rust","code":"pub fn merge_exitcodes(results: impl IntoIterator<Item = ExitCode>) -> ExitCode {\n if results.into_iter().any(ExitCode::is_error) {\n return ExitCode::GeneralError;\n }\n ExitCode::Success\n}"}
{"repo":"fd","file":"src/exit_codes.rs","line":58,"symbol":"success_when_no_results","kind":"function","lang":"rust","code":"fn success_when_no_results() {\n assert_eq!(merge_exitcodes([]), ExitCode::Success);\n }"}
{"repo":"fd","file":"src/exit_codes.rs","line":63,"symbol":"general_error_if_at_least_one_error","kind":"function","lang":"rust","code":"fn general_error_if_at_least_one_error() {\n assert_eq!(\n merge_exitcodes([ExitCode::GeneralError]),\n ExitCode::GeneralError\n );\n assert_eq!(\n merge_exitcodes([ExitCode::KilledBySigint]),\n ExitCode::GeneralError\n );\n assert_eq!(\n merge_exitcodes([ExitCode::KilledBySigint, ExitCode::Success]),\n ExitCode::GeneralError\n );\n assert_eq!(\n merge_exitcodes([ExitCode::Success, ExitCode::GeneralError]),\n ExitCode::GeneralError\n );\n assert_eq!(\n merge_exitcodes([ExitCode::GeneralError, ExitCode::KilledBySigint]),\n ExitCode::GeneralError\n );\n }"}
{"repo":"fd","file":"src/exit_codes.rs","line":87,"symbol":"success_if_no_error","kind":"function","lang":"rust","code":"fn success_if_no_error() {\n assert_eq!(merge_exitcodes([ExitCode::Success]), ExitCode::Success);\n assert_eq!(\n merge_exitcodes([ExitCode::Success, ExitCode::Success]),\n ExitCode::Success\n );\n }"}
{"repo":"fd","file":"src/filesystem.rs","line":14,"symbol":"path_absolute_form","kind":"function","lang":"rust","code":"pub fn path_absolute_form(path: &Path) -> io::Result<PathBuf> {\n if path.is_absolute() {\n return Ok(path.to_path_buf());\n }\n\n let path = path.strip_prefix(\".\").unwrap_or(path);\n env::current_dir().map(|path_buf| path_buf.join(path))\n}"}
{"repo":"fd","file":"src/filesystem.rs","line":23,"symbol":"absolute_path","kind":"function","lang":"rust","code":"pub fn absolute_path(path: &Path) -> io::Result<PathBuf> {\n let path_buf = path_absolute_form(path)?;\n\n #[cfg(windows)]\n let path_buf = Path::new(\n path_buf\n .as_path()\n .to_string_lossy()\n .trim_start_matches(r\"\\\\?\\\"),\n )\n .to_path_buf();\n\n Ok(path_buf)\n}"}
{"repo":"fd","file":"src/filesystem.rs","line":38,"symbol":"is_existing_directory","kind":"function","lang":"rust","code":"pub fn is_existing_directory(path: &Path) -> bool {\n // Note: we do not use `.exists()` here, as `.` always exists, even if\n // the CWD has been deleted.\n path.is_dir() && (path.file_name().is_some() || path.normalize().is_ok())\n}"}
{"repo":"fd","file":"src/filesystem.rs","line":44,"symbol":"is_empty","kind":"function","lang":"rust","code":"pub fn is_empty(entry: &dir_entry::DirEntry) -> bool {\n if let Some(file_type) = entry.file_type() {\n if file_type.is_dir() {\n if let Ok(mut entries) = fs::read_dir(entry.path()) {\n entries.next().is_none()\n } else {\n false\n }\n } else if file_type.is_file() {\n entry.metadata().map(|m| m.len() == 0).unwrap_or(false)\n } else {\n false\n }\n } else {\n false\n }\n}"}
{"repo":"fd","file":"src/filesystem.rs","line":63,"symbol":"is_block_device","kind":"function","lang":"rust","code":"pub fn is_block_device(ft: fs::FileType) -> bool {\n ft.is_block_device()\n}"}
{"repo":"fd","file":"src/filesystem.rs","line":68,"symbol":"is_block_device","kind":"function","lang":"rust","code":"pub fn is_block_device(_: fs::FileType) -> bool {\n false\n}"}
{"repo":"fd","file":"src/filesystem.rs","line":73,"symbol":"is_char_device","kind":"function","lang":"rust","code":"pub fn is_char_device(ft: fs::FileType) -> bool {\n ft.is_char_device()\n}"}
{"repo":"fd","file":"src/filesystem.rs","line":78,"symbol":"is_char_device","kind":"function","lang":"rust","code":"pub fn is_char_device(_: fs::FileType) -> bool {\n false\n}"}
{"repo":"fd","file":"src/filesystem.rs","line":83,"symbol":"is_socket","kind":"function","lang":"rust","code":"pub fn is_socket(ft: fs::FileType) -> bool {\n ft.is_socket()\n}"}
{"repo":"fd","file":"src/filesystem.rs","line":88,"symbol":"is_socket","kind":"function","lang":"rust","code":"pub fn is_socket(_: fs::FileType) -> bool {\n false\n}"}
{"repo":"fd","file":"src/filesystem.rs","line":93,"symbol":"is_pipe","kind":"function","lang":"rust","code":"pub fn is_pipe(ft: fs::FileType) -> bool {\n ft.is_fifo()\n}"}
{"repo":"fd","file":"src/filesystem.rs","line":98,"symbol":"is_pipe","kind":"function","lang":"rust","code":"pub fn is_pipe(_: fs::FileType) -> bool {\n false\n}"}
{"repo":"fd","file":"src/filesystem.rs","line":103,"symbol":"osstr_to_bytes","kind":"function","lang":"rust","code":"pub fn osstr_to_bytes(input: &OsStr) -> Cow<'_, [u8]> {\n use std::os::unix::ffi::OsStrExt;\n Cow::Borrowed(input.as_bytes())\n}"}
{"repo":"fd","file":"src/filesystem.rs","line":109,"symbol":"osstr_to_bytes","kind":"function","lang":"rust","code":"pub fn osstr_to_bytes(input: &OsStr) -> Cow<'_, [u8]> {\n let string = input.to_string_lossy();\n\n match string {\n Cow::Owned(string) => Cow::Owned(string.into_bytes()),\n Cow::Borrowed(string) => Cow::Borrowed(string.as_bytes()),\n }\n}"}
{"repo":"fd","file":"src/filesystem.rs","line":119,"symbol":"strip_current_dir","kind":"function","lang":"rust","doc":"Remove the `./` prefix from a path.","code":"pub fn strip_current_dir(path: &Path) -> &Path {\n path.strip_prefix(\".\").unwrap_or(path)\n}"}
{"repo":"fd","file":"src/filesystem.rs","line":128,"symbol":"default_path_separator","kind":"function","lang":"rust","doc":"Default value for the path_separator, mainly for MSYS/MSYS2, which set the MSYSTEM environment variable, and we set fd's path separator to '/' rather than Rust's default of '\\'. Returns Some to use a nonstandard path separator, or None to use rust's default on the target platform.","code":"pub fn default_path_separator() -> Option<String> {\n if cfg!(windows) {\n let msystem = env::var(\"MSYSTEM\").ok()?;\n if !msystem.is_empty() {\n return Some(\"/\".to_owned());\n }\n }\n None\n}"}
{"repo":"fd","file":"src/filesystem.rs","line":144,"symbol":"strip_current_dir_basic","kind":"function","lang":"rust","code":"fn strip_current_dir_basic() {\n assert_eq!(strip_current_dir(Path::new(\"./foo\")), Path::new(\"foo\"));\n assert_eq!(strip_current_dir(Path::new(\"foo\")), Path::new(\"foo\"));\n assert_eq!(\n strip_current_dir(Path::new(\"./foo/bar/baz\")),\n Path::new(\"foo/bar/baz\")\n );\n assert_eq!(\n strip_current_dir(Path::new(\"foo/bar/baz\")),\n Path::new(\"foo/bar/baz\")\n );\n }"}
{"repo":"fd","file":"src/filetypes.rs","line":8,"symbol":"FileTypes","kind":"type","lang":"rust","doc":"Whether or not to show","code":"pub struct FileTypes {\n pub files: bool,\n pub directories: bool,\n pub symlinks: bool,\n pub block_devices: bool,\n pub char_devices: bool,\n pub sockets: bool,\n pub pipes: bool,\n pub executables_only: bool,\n pub empty_only: bool,\n}"}
{"repo":"fd","file":"src/filetypes.rs","line":21,"symbol":"should_ignore","kind":"function","lang":"rust","code":"pub fn should_ignore(&self, entry: &dir_entry::DirEntry) -> bool {\n if let Some(ref entry_type) = entry.file_type() {\n (!self.files && entry_type.is_file())\n || (!self.directories && entry_type.is_dir())\n || (!self.symlinks && entry_type.is_symlink())\n || (!self.block_devices && filesystem::is_block_device(*entry_type))\n || (!self.char_devices && filesystem::is_char_device(*entry_type))\n || (!self.sockets && filesystem::is_socket(*entry_type))\n || (!self.pipes && filesystem::is_pipe(*entry_type))\n || (self.executables_only && !entry.path().executable())\n || (self.empty_only && !filesystem::is_empty(entry))\n || !(entry_type.is_file()\n || entry_type.is_dir()\n || entry_type.is_symlink()\n || filesystem::is_block_device(*entry_type)\n || filesystem::is_char_device(*entry_type)\n || filesystem::is_socket(*entry_type)\n || filesystem::is_pipe(*entry_type))\n } else {\n true\n }\n }"}
{"repo":"fd","file":"src/filter/owner.rs","line":6,"symbol":"OwnerFilter","kind":"type","lang":"rust","code":"pub struct OwnerFilter {\n uid: Check<u32>,\n gid: Check<u32>,\n}"}
{"repo":"fd","file":"src/filter/owner.rs","line":12,"symbol":"Check","kind":"type","lang":"rust","code":"enum Check<T> {\n Equal(T),\n NotEq(T),\n Ignore,\n}"}
{"repo":"fd","file":"src/filter/owner.rs","line":27,"symbol":"from_string","kind":"function","lang":"rust","doc":"Parses an owner constraint Returns an error if the string is invalid Returns Ok(None) when string is acceptable but a noop (such as \"\" or \":\")","code":"pub fn from_string(input: &str) -> Result<Self> {\n let mut it = input.split(':');\n let (fst, snd) = (it.next(), it.next());\n\n if it.next().is_some() {\n return Err(anyhow!(\n \"more than one ':' present in owner string '{}'. See 'fd --help'.\",\n input\n ));\n }\n\n let uid = Check::parse(fst, |s| {\n if let Ok(uid) = s.parse() {\n Ok(uid)\n } else {\n User::from_name(s)?\n .map(|user| user.uid.as_raw())\n .ok_or_else(|| anyhow!(\"'{}' is not a recognized user name\", s))\n }\n })?;\n let gid = Check::parse(snd, |s| {\n if let Ok(gid) = s.parse() {\n Ok(gid)\n } else {\n Group::from_name(s)?\n .map(|group| group.gid.as_raw())\n .ok_or_else(|| anyhow!(\"'{}' is not a recognized group name\", s))\n }\n })?;\n\n Ok(OwnerFilter { uid, gid })\n }"}
{"repo":"fd","file":"src/filter/owner.rs","line":61,"symbol":"filter_ignore","kind":"function","lang":"rust","doc":"If self is a no-op (ignore both uid and gid) then return `None`, otherwise wrap in a `Some`","code":"pub fn filter_ignore(self) -> Option<Self> {\n if self == Self::IGNORE {\n None\n } else {\n Some(self)\n }\n }"}
{"repo":"fd","file":"src/filter/owner.rs","line":69,"symbol":"matches","kind":"function","lang":"rust","code":"pub fn matches(&self, md: &fs::Metadata) -> bool {\n use std::os::unix::fs::MetadataExt;\n\n self.uid.check(md.uid()) && self.gid.check(md.gid())\n }"}
{"repo":"fd","file":"src/filter/owner.rs","line":77,"symbol":"check","kind":"function","lang":"rust","code":"fn check(&self, v: T) -> bool {\n match self {\n Check::Equal(x) => v == *x,\n Check::NotEq(x) => v != *x,\n Check::Ignore => true,\n }\n }"}
{"repo":"fd","file":"src/filter/owner.rs","line":85,"symbol":"parse","kind":"function","lang":"rust","code":"fn parse<F>(s: Option<&str>, f: F) -> Result<Self>\n where\n F: Fn(&str) -> Result<T>,\n {\n let (s, equality) = match s {\n Some(\"\") | None => return Ok(Check::Ignore),\n Some(s) if s.starts_with('!') => (&s[1..], false),\n Some(s) => (s, true),\n };\n\n f(s).map(|x| {\n if equality {\n Check::Equal(x)\n } else {\n Check::NotEq(x)\n }\n })\n }"}
{"repo":"fd","file":"src/filter/size.rs","line":9,"symbol":"SizeFilter","kind":"type","lang":"rust","code":"pub enum SizeFilter {\n Max(u64),\n Min(u64),\n Equals(u64),\n}"}
{"repo":"fd","file":"src/filter/size.rs","line":28,"symbol":"from_string","kind":"function","lang":"rust","code":"pub fn from_string(s: &str) -> anyhow::Result<Self> {\n SizeFilter::parse_opt(s)\n .ok_or_else(|| anyhow!(\"'{}' is not a valid size constraint. See 'fd --help'.\", s))\n }"}
{"repo":"fd","file":"src/filter/size.rs","line":33,"symbol":"parse_opt","kind":"function","lang":"rust","code":"fn parse_opt(s: &str) -> Option<Self> {\n let pattern =\n SIZE_CAPTURES.get_or_init(|| Regex::new(r\"(?i)^([+-]?)(\\d+)(b|[kmgt]i?b?)$\").unwrap());\n if !pattern.is_match(s) {\n return None;\n }\n\n let captures = pattern.captures(s)?;\n let limit_kind = captures.get(1).map_or(\"+\", |m| m.as_str());\n let quantity = captures\n .get(2)\n .and_then(|v| v.as_str().parse::<u64>().ok())?;\n\n let multiplier = match &captures.get(3).map_or(\"b\", |m| m.as_str()).to_lowercase()[..] {\n v if v.starts_with(\"ki\") => KIBI,\n v if v.starts_with('k') => KILO,\n v if v.starts_with(\"mi\") => MEBI,\n v if v.starts_with('m') => MEGA,\n v if v.starts_with(\"gi\") => GIBI,\n v if v.starts_with('g') => GIGA,\n v if v.starts_with(\"ti\") => TEBI,\n v if v.starts_with('t') => TERA,\n \"b\" => 1,\n _ => return None,\n };\n\n let size = quantity * multiplier;\n match limit_kind {\n \"+\" => Some(SizeFilter::Min(size)),\n \"-\" => Some(SizeFilter::Max(size)),\n \"\" => Some(SizeFilter::Equals(size)),\n"}
{"repo":"fd","file":"src/filter/size.rs","line":68,"symbol":"is_within","kind":"function","lang":"rust","code":"pub fn is_within(&self, size: u64) -> bool {\n match *self {\n SizeFilter::Max(limit) => size <= limit,\n SizeFilter::Min(limit) => size >= limit,\n SizeFilter::Equals(limit) => size == limit,\n }\n }"}
{"repo":"fd","file":"src/filter/size.rs","line":197,"symbol":"is_within_less_than","kind":"function","lang":"rust","code":"fn is_within_less_than() {\n let f = SizeFilter::from_string(\"-1k\").unwrap();\n assert!(f.is_within(999));\n }"}
{"repo":"fd","file":"src/filter/size.rs","line":203,"symbol":"is_within_less_than_equal","kind":"function","lang":"rust","code":"fn is_within_less_than_equal() {\n let f = SizeFilter::from_string(\"-1k\").unwrap();\n assert!(f.is_within(1000));\n }"}
{"repo":"fd","file":"src/filter/size.rs","line":209,"symbol":"is_within_greater_than","kind":"function","lang":"rust","code":"fn is_within_greater_than() {\n let f = SizeFilter::from_string(\"+1k\").unwrap();\n assert!(f.is_within(1001));\n }"}
{"repo":"fd","file":"src/filter/size.rs","line":215,"symbol":"is_within_greater_than_equal","kind":"function","lang":"rust","code":"fn is_within_greater_than_equal() {\n let f = SizeFilter::from_string(\"+1K\").unwrap();\n assert!(f.is_within(1000));\n }"}
{"repo":"fd","file":"src/filter/time.rs","line":7,"symbol":"TimeFilter","kind":"type","lang":"rust","doc":"Filter based on time ranges.","code":"pub enum TimeFilter {\n Before(SystemTime),\n After(SystemTime),\n}"}
{"repo":"fd","file":"src/filter/time.rs","line":13,"symbol":"now","kind":"function","lang":"rust","code":"fn now() -> Zoned {\n Zoned::now()\n}"}
{"repo":"fd","file":"src/filter/time.rs","line":24,"symbol":"now","kind":"function","lang":"rust","doc":"This allows us to set a specific time when running tests","code":"fn now() -> Zoned {\n TESTTIME.with_borrow(|reftime| reftime.as_ref().cloned().unwrap_or_else(Zoned::now))\n}"}
{"repo":"fd","file":"src/filter/time.rs","line":29,"symbol":"from_str","kind":"function","lang":"rust","code":"fn from_str(s: &str) -> Option<SystemTime> {\n if let Ok(span) = s.parse::<Span>() {\n let datetime = now().checked_sub(span).ok()?;\n Some(datetime.into())\n } else if let Ok(timestamp) = s.parse::<Timestamp>() {\n Some(timestamp.into())\n } else if let Ok(datetime) = s.parse::<DateTime>() {\n Some(\n TimeZone::system()\n .to_ambiguous_zoned(datetime)\n .later()\n .ok()?\n .into(),\n )\n } else {\n let timestamp_secs: u64 = s.strip_prefix('@')?.parse().ok()?;\n UNIX_EPOCH.checked_add(Duration::from_secs(timestamp_secs))\n }\n }"}
{"repo":"fd","file":"src/filter/time.rs","line":49,"symbol":"before","kind":"function","lang":"rust","code":"pub fn before(s: &str) -> Option<TimeFilter> {\n TimeFilter::from_str(s).map(TimeFilter::Before)\n }"}
{"repo":"fd","file":"src/filter/time.rs","line":53,"symbol":"after","kind":"function","lang":"rust","code":"pub fn after(s: &str) -> Option<TimeFilter> {\n TimeFilter::from_str(s).map(TimeFilter::After)\n }"}
{"repo":"fd","file":"src/filter/time.rs","line":57,"symbol":"applies_to","kind":"function","lang":"rust","code":"pub fn applies_to(&self, t: &SystemTime) -> bool {\n match self {\n TimeFilter::Before(limit) => t < limit,\n TimeFilter::After(limit) => t > limit,\n }\n }"}
{"repo":"fd","file":"src/filter/time.rs","line":70,"symbol":"TestTime","kind":"type","lang":"rust","code":"struct TestTime(SystemTime);"}
{"repo":"fd","file":"src/filter/time.rs","line":73,"symbol":"new","kind":"function","lang":"rust","code":"fn new(time: Zoned) -> Self {\n TESTTIME.with_borrow_mut(|t| *t = Some(time.clone()));\n TestTime(time.into())\n }"}
{"repo":"fd","file":"src/filter/time.rs","line":78,"symbol":"set","kind":"function","lang":"rust","code":"fn set(&mut self, time: Zoned) {\n TESTTIME.with_borrow_mut(|t| *t = Some(time.clone()));\n self.0 = time.into();\n }"}
{"repo":"fd","file":"src/filter/time.rs","line":83,"symbol":"timestamp","kind":"function","lang":"rust","code":"fn timestamp(&self) -> SystemTime {\n self.0\n }"}
{"repo":"fd","file":"src/filter/time.rs","line":89,"symbol":"drop","kind":"function","lang":"rust","code":"fn drop(&mut self) {\n // Stop using manually set times\n TESTTIME.with_borrow_mut(|t| *t = None);\n }"}
{"repo":"fd","file":"src/filter/time.rs","line":96,"symbol":"is_time_filter_applicable","kind":"function","lang":"rust","code":"fn is_time_filter_applicable() {\n let local_tz = TimeZone::system();\n let mut test_time = TestTime::new(\n local_tz\n .to_ambiguous_zoned(\"2010-10-10 10:10:10\".parse::<DateTime>().unwrap())\n .later()\n .unwrap(),\n );\n let mut ref_time = test_time.timestamp();\n\n assert!(TimeFilter::after(\"1min\").unwrap().applies_to(&ref_time));\n assert!(!TimeFilter::before(\"1min\").unwrap().applies_to(&ref_time));\n\n let t1m_ago = ref_time - Duration::from_secs(60);\n assert!(!TimeFilter::after(\"30sec\").unwrap().applies_to(&t1m_ago));\n assert!(TimeFilter::after(\"2min\").unwrap().applies_to(&t1m_ago));\n\n assert!(TimeFilter::before(\"30sec\").unwrap().applies_to(&t1m_ago));\n assert!(!TimeFilter::before(\"2min\").unwrap().applies_to(&t1m_ago));\n\n let t10s_before = \"2010-10-10 10:10:00\";\n assert!(\n !TimeFilter::before(t10s_before)\n .unwrap()\n .applies_to(&ref_time)\n );\n assert!(\n TimeFilter::before(t10s_before)\n .unwrap()\n .applies_to(&t1m_ago)\n );\n\n assert!(\n "}
{"repo":"fd","file":"src/filter/time.rs","line":204,"symbol":"out_of_range_unix_timestamp_is_rejected","kind":"function","lang":"rust","code":"fn out_of_range_unix_timestamp_is_rejected() {\n // A '@' timestamp large enough to overflow SystemTime must return\n // None rather than panicking.\n assert!(TimeFilter::before(&format!(\"@{}\", u64::MAX)).is_none());\n assert!(TimeFilter::after(&format!(\"@{}\", u64::MAX)).is_none());\n }"}
{"repo":"fd","file":"src/fmt/input.rs","line":7,"symbol":"basename","kind":"function","lang":"rust","doc":"Removes the parent component of the path","code":"pub fn basename(path: &Path) -> &OsStr {\n path.file_name().unwrap_or(path.as_os_str())\n}"}
{"repo":"fd","file":"src/fmt/input.rs","line":12,"symbol":"remove_extension","kind":"function","lang":"rust","doc":"Removes the extension from the path","code":"pub fn remove_extension(path: &Path) -> OsString {\n let dirname = dirname(path);\n let stem = path.file_stem().unwrap_or(path.as_os_str());\n\n let path = PathBuf::from(dirname).join(stem);\n\n strip_current_dir(&path).to_owned().into_os_string()\n}"}
{"repo":"fd","file":"src/fmt/input.rs","line":22,"symbol":"dirname","kind":"function","lang":"rust","doc":"Removes the basename from the path.","code":"pub fn dirname(path: &Path) -> OsString {\n path.parent()\n .map(|p| {\n if p == OsStr::new(\"\") {\n OsString::from(\".\")\n } else {\n p.as_os_str().to_owned()\n }\n })\n .unwrap_or_else(|| path.as_os_str().to_owned())\n}"}
{"repo":"fd","file":"src/fmt/input.rs","line":39,"symbol":"correct","kind":"function","lang":"rust","code":"fn correct(input: &str) -> String {\n input.replace('/', MAIN_SEPARATOR_STR)\n }"}
{"repo":"fd","file":"src/fmt/input.rs","line":77,"symbol":"dirname_root","kind":"function","lang":"rust","code":"fn dirname_root() {\n assert_eq!(dirname(&PathBuf::from(\"C:\")), OsString::from(\"C:\"));\n assert_eq!(dirname(&PathBuf::from(\"\\\\\")), OsString::from(\"\\\\\"));\n }"}
{"repo":"fd","file":"src/fmt/input.rs","line":84,"symbol":"dirname_root","kind":"function","lang":"rust","code":"fn dirname_root() {\n assert_eq!(dirname(&PathBuf::from(\"/\")), OsString::from(\"/\"));\n }"}
{"repo":"fd","file":"src/fmt/mod.rs","line":18,"symbol":"Token","kind":"type","lang":"rust","doc":"Designates what should be written to a buffer Each `Token` contains either text, or a placeholder variant, which will be used to generate commands after all tokens for a given command template have been collected.","code":"pub enum Token {\n Placeholder,\n Basename,\n Parent,\n NoExt,\n BasenameNoExt,\n Text(String),\n}"}
{"repo":"fd","file":"src/fmt/mod.rs","line":28,"symbol":"fmt","kind":"function","lang":"rust","code":"fn fmt(&self, f: &mut Formatter) -> fmt::Result {\n match *self {\n Token::Placeholder => f.write_str(\"{}\")?,\n Token::Basename => f.write_str(\"{/}\")?,\n Token::Parent => f.write_str(\"{//}\")?,\n Token::NoExt => f.write_str(\"{.}\")?,\n Token::BasenameNoExt => f.write_str(\"{/.}\")?,\n Token::Text(ref string) => f.write_str(string)?,\n }\n Ok(())\n }"}
{"repo":"fd","file":"src/fmt/mod.rs","line":46,"symbol":"FormatTemplate","kind":"type","lang":"rust","doc":"A parsed format string This is either a collection of `Token`s including at least one placeholder variant, or a fixed text.","code":"pub enum FormatTemplate {\n Tokens(Vec<Token>),\n Text(String),\n}"}
{"repo":"fd","file":"src/fmt/mod.rs","line":54,"symbol":"has_tokens","kind":"function","lang":"rust","code":"pub fn has_tokens(&self) -> bool {\n matches!(self, FormatTemplate::Tokens(_))\n }"}
{"repo":"fd","file":"src/fmt/mod.rs","line":58,"symbol":"parse","kind":"function","lang":"rust","code":"pub fn parse(fmt: &str) -> Self {\n // NOTE: we assume that { and } have the same length\n const BRACE_LEN: usize = '{'.len_utf8();\n let mut tokens = Vec::new();\n let mut remaining = fmt;\n let mut buf = String::new();\n let placeholders = PLACEHOLDERS.get_or_init(|| {\n AhoCorasick::new([\"{{\", \"}}\", \"{}\", \"{/}\", \"{//}\", \"{.}\", \"{/.}\"]).unwrap()\n });\n while let Some(m) = placeholders.find(remaining) {\n match m.pattern().as_u32() {\n 0 | 1 => {\n // we found an escaped {{ or }}, so add\n // everything up to the first char to the buffer\n // then skip the second one.\n buf += &remaining[..m.start() + BRACE_LEN];\n remaining = &remaining[m.end()..];\n }\n id if !remaining[m.end()..].starts_with('}') => {\n buf += &remaining[..m.start()];\n if !buf.is_empty() {\n tokens.push(Token::Text(std::mem::take(&mut buf)));\n }\n tokens.push(token_from_pattern_id(id));\n remaining = &"}
{"repo":"fd","file":"src/fmt/mod.rs","line":112,"symbol":"generate","kind":"function","lang":"rust","doc":"Generate a result string from this template. If path_separator is Some, then it will replace the path separator in all placeholder tokens. Fixed text and tokens are not affected by path separator substitution.","code":"pub fn generate(&self, path: impl AsRef<Path>, path_separator: Option<&str>) -> OsString {\n use Token::*;\n let path = path.as_ref();\n\n match *self {\n Self::Tokens(ref tokens) => {\n let mut s = OsString::new();\n for token in tokens {\n match token {\n Basename => s.push(Self::replace_separator(basename(path), path_separator)),\n BasenameNoExt => s.push(Self::replace_separator(\n &remove_extension(basename(path).as_ref()),\n path_separator,\n )),\n NoExt => s.push(Self::replace_separator(\n &remove_extension(path),\n path_separator,\n )),\n Parent => s.push(Self::replace_separator(&dirname(path), path_separator)),\n Placeholder => {\n s.push(Self::replace_separator(path.as_ref(), path_separator))\n }\n Text(string) => s.push(string),\n }\n }\n "}
{"repo":"fd","file":"src/fmt/mod.rs","line":147,"symbol":"replace_separator","kind":"function","lang":"rust","doc":"Replace the path separator in the input with the custom separator string. If path_separator is None, simply return a borrowed Cow<OsStr> of the input. Otherwise, the input is interpreted as a Path and its components are iterated through and re-joined into a new OsString.","code":"fn replace_separator<'a>(path: &'a OsStr, path_separator: Option<&str>) -> Cow<'a, OsStr> {\n // fast-path - no replacement necessary\n if path_separator.is_none() {\n return Cow::Borrowed(path);\n }\n\n let path_separator = path_separator.unwrap();\n let mut out = OsString::with_capacity(path.len());\n let mut components = Path::new(path).components().peekable();\n\n while let Some(comp) = components.next() {\n match comp {\n // Absolute paths on Windows are tricky. A Prefix component is usually a drive\n // letter or UNC path, and is usually followed by RootDir. There are also\n // \"verbatim\" prefixes beginning with \"\\\\?\\\" that skip normalization. We choose to\n // ignore verbatim path prefixes here because they're very rare, might be\n // impossible to reach here, and there's no good way to deal with them. If users\n // are doing something advanced involving verbatim windows paths, they can do their\n // own output filtering with a tool like sed.\n Component::Prefix(prefix) => {\n if let Pre"}
{"repo":"fd","file":"src/fmt/mod.rs","line":201,"symbol":"token_from_pattern_id","kind":"function","lang":"rust","doc":"Convert the id from an aho-corasick match to the appropriate token","code":"fn token_from_pattern_id(id: u32) -> Token {\n use Token::*;\n match id {\n 2 => Placeholder,\n 3 => Basename,\n 4 => Parent,\n 5 => NoExt,\n 6 => BasenameNoExt,\n _ => unreachable!(),\n }\n}"}
{"repo":"fd","file":"src/fmt/mod.rs","line":219,"symbol":"parse_no_placeholders","kind":"function","lang":"rust","code":"fn parse_no_placeholders() {\n let templ = FormatTemplate::parse(\"This string has no placeholders\");\n assert_eq!(\n templ,\n FormatTemplate::Text(\"This string has no placeholders\".into())\n );\n }"}
{"repo":"fd","file":"src/fmt/mod.rs","line":228,"symbol":"parse_only_brace_escapes","kind":"function","lang":"rust","code":"fn parse_only_brace_escapes() {\n let templ = FormatTemplate::parse(\"This string only has escapes like {{ and }}\");\n assert_eq!(\n templ,\n FormatTemplate::Text(\"This string only has escapes like { and }\".into())\n );\n }"}
{"repo":"fd","file":"src/fmt/mod.rs","line":237,"symbol":"all_placeholders","kind":"function","lang":"rust","code":"fn all_placeholders() {\n use Token::*;\n\n let templ = FormatTemplate::parse(\n \"{{path={} \\\n basename={/} \\\n parent={//} \\\n noExt={.} \\\n basenameNoExt={/.} \\\n }}\",\n );\n assert_eq!(\n templ,\n FormatTemplate::Tokens(vec![\n Text(\"{path=\".into()),\n Placeholder,\n Text(\" basename=\".into()),\n Basename,\n Text(\" parent=\".into()),\n Parent,\n Text(\" noExt=\".into()),\n NoExt,\n Text(\" basenameNoExt=\".into()),\n BasenameNoExt,\n Text(\" }\".into()),\n ])\n );\n\n let mut path = PathBuf::new();\n path.push(\"a\");\n path.push(\"folder\");\n path.push(\"file.txt\");\n\n let expanded = templ.generate(&path, Some(\"/\")).into_string().unwrap();\n\n assert_eq!(\n expanded,\n \"{path=a/folder/file.txt \\\n basename=file.txt \\\n parent=a/folder \\\n noExt=a/folder/file \\\n basenameNoExt=file }\"\n );\n }"}
{"repo":"fd","file":"src/hyperlink.rs","line":5,"symbol":"PathUrl","kind":"type","lang":"rust","code":"pub(crate) struct PathUrl(PathBuf);"}
{"repo":"fd","file":"src/hyperlink.rs","line":8,"symbol":"new","kind":"function","lang":"rust","code":"pub(crate) fn new(path: &Path) -> Option<PathUrl> {\n Some(PathUrl(absolute_path(path).ok()?))\n }"}
{"repo":"fd","file":"src/hyperlink.rs","line":14,"symbol":"fmt","kind":"function","lang":"rust","code":"fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {\n write!(f, \"file://{}\", host())?;\n let bytes = self.0.as_os_str().as_encoded_bytes();\n for &byte in bytes.iter() {\n encode(f, byte)?;\n }\n Ok(())\n }"}
{"repo":"fd","file":"src/hyperlink.rs","line":24,"symbol":"encode","kind":"function","lang":"rust","code":"fn encode(f: &mut Formatter, byte: u8) -> fmt::Result {\n // NOTE:\n // Most terminals can handle non-ascii unicode characters in a file url fine. But on some OSes (notably\n // windows), the encoded bytes of the path may not be valid UTF-8. Since we don't know if a\n // byte >= 128 is part of a valid UTF-8 encoding or not, we just percent encode any non-ascii\n // byte.\n // Percent encoding these bytes is probably safer anyway.\n match byte {\n b'0'..=b'9' | b'A'..=b'Z' | b'a'..=b'z' | b'/' | b':' | b'-' | b'.' | b'_' | b'~' => {\n f.write_char(byte.into())\n }\n #[cfg(windows)]\n b'\\\\' => f.write_char('/'),\n _ => {\n write!(f, \"%{byte:02X}\")\n }\n }\n}"}
{"repo":"fd","file":"src/hyperlink.rs","line":44,"symbol":"host","kind":"function","lang":"rust","code":"fn host() -> &'static str {\n use std::sync::OnceLock;\n\n static HOSTNAME: OnceLock<String> = OnceLock::new();\n\n HOSTNAME\n .get_or_init(|| {\n nix::unistd::gethostname()\n .ok()\n .and_then(|h| h.into_string().ok())\n .unwrap_or_default()\n })\n .as_ref()\n}"}
{"repo":"fd","file":"src/hyperlink.rs","line":60,"symbol":"host","kind":"function","lang":"rust","code":"const fn host() -> &'static str {\n \"/\"\n}"}
{"repo":"fd","file":"src/hyperlink.rs","line":69,"symbol":"Encoded","kind":"type","lang":"rust","doc":"This allows us to test the encoding without having to worry about the host, or absolute path","code":"struct Encoded(&'static str);"}
{"repo":"fd","file":"src/hyperlink.rs","line":72,"symbol":"fmt","kind":"function","lang":"rust","code":"fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {\n for byte in self.0.bytes() {\n encode(f, byte)?;\n }\n Ok(())\n }"}
{"repo":"fd","file":"src/hyperlink.rs","line":81,"symbol":"test_unicode_encoding","kind":"function","lang":"rust","code":"fn test_unicode_encoding() {\n assert_eq!(\n Encoded(\"$*\\x1bßé/∫😃\\x07\").to_string(),\n \"%24%2A%1B%C3%9F%C3%A9/%E2%88%AB%F0%9F%98%83%07\",\n );\n }"}
{"repo":"fd","file":"src/main.rs","line":65,"symbol":"main","kind":"function","lang":"rust","code":"fn main() {\n let result = run();\n match result {\n Ok(exit_code) => {\n exit_code.exit();\n }\n Err(err) => {\n // NB: we use eprintln directly instead of print_error!() because\n // we sanitize anyhow errors at the generation site\n eprintln!(\"[fd error]: {:#}\", err);\n ExitCode::GeneralError.exit();\n }\n }\n}"}
{"repo":"fd","file":"src/main.rs","line":80,"symbol":"run","kind":"function","lang":"rust","code":"fn run() -> Result<ExitCode> {\n let opts = Opts::parse();\n\n #[cfg(feature = \"completions\")]\n if let Some(shell) = opts.gen_completions()? {\n return print_completions(shell);\n }\n\n set_working_dir(&opts)?;\n let search_paths = opts.search_paths()?;\n if search_paths.is_empty() {\n bail!(\"No valid search paths given.\");\n }\n\n ensure_search_pattern_is_not_a_path(&opts)?;\n let pattern = &opts.pattern;\n let exprs = &opts.exprs;\n let empty = Vec::new();\n\n let pattern_regexps = exprs\n .as_ref()\n .unwrap_or(&empty)\n .iter()\n .chain([pattern])\n .map(|pat| build_pattern_regex(pat, &opts))\n .collect::<Result<Vec<String>>>()?;\n\n let config = construct_config(opts, &pattern_regexps)?;\n\n ensure_use_hidden_option_for_leading_dot_pattern(&config, &pattern_regexps)?;\n\n let regexps = pattern_regexps\n .into_iter()\n .map(|pat| build_regex(pat, &config))\n .collect::<Result<Vec<Regex>>>()?;\n\n walk::scan(&search_paths, regexps, config)\n}"}
{"repo":"fd","file":"src/main.rs","line":121,"symbol":"print_completions","kind":"function","lang":"rust","code":"fn print_completions(shell: clap_complete::Shell) -> Result<ExitCode> {\n // The program name is the first argument.\n let first_arg = env::args().next();\n let program_name = first_arg\n .as_ref()\n .map(Path::new)\n .and_then(|path| path.file_stem())\n .and_then(|file| file.to_str())\n .unwrap_or(\"fd\");\n let mut cmd = Opts::command();\n cmd.build();\n clap_complete::generate(shell, &mut cmd, program_name, &mut std::io::stdout());\n Ok(ExitCode::Success)\n}"}
{"repo":"fd","file":"src/main.rs","line":136,"symbol":"set_working_dir","kind":"function","lang":"rust","code":"fn set_working_dir(opts: &Opts) -> Result<()> {\n if let Some(ref base_directory) = opts.base_directory {\n if !filesystem::is_existing_directory(base_directory) {\n return Err(anyhow!(\n \"The '--base-directory' path {:?} is not a directory.\",\n base_directory.to_string_lossy().as_ref()\n ));\n }\n env::set_current_dir(base_directory).with_context(|| {\n format!(\n \"Could not set {:?} as the current working directory\",\n base_directory.to_string_lossy().as_ref()\n )\n })?;\n }\n Ok(())\n}"}
{"repo":"fd","file":"src/main.rs","line":174,"symbol":"ensure_search_pattern_is_not_a_path","kind":"function","lang":"rust","doc":"so valid regex patterns like `\\Ac` or `\\d+` must still run. Requiring that the pattern resolves to a real directory avoids those false positives while preserving the legacy diagnostic for operators who literally typed a directory path. See https://github.com/sharkdp/fd/issues/1873.","code":"fn ensure_search_pattern_is_not_a_path(opts: &Opts) -> Result<()> {\n if opts.full_path {\n return Ok(());\n }\n\n // Check the primary pattern and every `--and` pattern. They are all matched\n // against the file name (see `run`), so a path separator in any of them is\n // the same silent \"no results\" footgun.\n for pattern in std::iter::once(&opts.pattern).chain(opts.exprs.iter().flatten()) {\n ensure_single_search_pattern_is_not_a_path(pattern)?;\n }\n Ok(())\n}"}
{"repo":"fd","file":"src/main.rs","line":190,"symbol":"ensure_single_search_pattern_is_not_a_path","kind":"function","lang":"rust","doc":"Apply the path-separator diagnostic to a single pattern. See [`ensure_search_pattern_is_not_a_path`] for the rationale of each case.","code":"fn ensure_single_search_pattern_is_not_a_path(pattern: &str) -> Result<()> {\n // Start with the cheap check: '/' is always a path separator, including on\n // Windows, and has no regex meaning, so flagging it is safe and catches the\n // Linux/macOS mistake of pasting a full path as the pattern.\n #[cfg_attr(not(windows), allow(unused_mut))]\n let mut should_warn = pattern.contains('/');\n\n // On Windows we additionally accept the native `\\` separator, but only when\n // the pattern actually resolves to an existing directory - `\\` is also the\n // regex escape char there, so valid patterns like `\\Ac` or `\\d+` must still\n // run. The is_dir syscall is only needed when `should_warn` is still false,\n // so short-circuit via `||` to avoid the stat call on the happy path.\n #[cfg(windows)]\n {\n should_warn = should_warn\n || (pattern.contains(std::path::MAIN_SEPARATOR) && Path::new(pattern).is_dir());\n }\n\n if should_warn {\n Err(anyhow!(\n \"The search pattern '{pattern}' contains a path-separation character \\\n and will not lead to any search results.\\n\\n\\\n If you want to search for all files inside"}
{"repo":"fd","file":"src/main.rs","line":223,"symbol":"build_pattern_regex","kind":"function","lang":"rust","code":"fn build_pattern_regex(pattern: &str, opts: &Opts) -> Result<String> {\n Ok(if opts.glob && !pattern.is_empty() {\n let glob = GlobBuilder::new(pattern).literal_separator(true).build()?;\n glob.regex().to_owned()\n } else if opts.exact {\n // Anchor the escaped pattern so the full filename (or path) must match exactly.\n // Literal. No substring matching.\n format!(\"^{}$\", regex::escape(pattern))\n } else if opts.fixed_strings {\n // Treat pattern as literal string if '--fixed-strings' is used\n regex::escape(pattern)\n } else {\n String::from(pattern)\n })\n}"}
{"repo":"fd","file":"src/main.rs","line":239,"symbol":"check_path_separator_length","kind":"function","lang":"rust","code":"fn check_path_separator_length(path_separator: Option<&str>) -> Result<()> {\n match (cfg!(windows), path_separator) {\n (true, Some(sep)) if sep.len() > 1 => Err(anyhow!(\n \"A path separator must be exactly one byte, but \\\n the given separator is {} bytes: '{}'.\\n\\\n In some shells on Windows, '/' is automatically \\\n expanded. Try to use '//' instead.\",\n sep.len(),\n sep\n )),\n _ => Ok(()),\n }\n}"}
{"repo":"fd","file":"src/main.rs","line":253,"symbol":"construct_config","kind":"function","lang":"rust","code":"fn construct_config(mut opts: Opts, pattern_regexps: &[String]) -> Result<Config> {\n // The search will be case-sensitive if the command line flag is set or\n // if any of the patterns has an uppercase character (smart case).\n let case_sensitive = !opts.ignore_case\n && (opts.case_sensitive\n || pattern_regexps\n .iter()\n .any(|pat| pattern_has_uppercase_char(pat)));\n\n let path_separator = opts\n .path_separator\n .take()\n .or_else(filesystem::default_path_separator);\n let actual_path_separator = path_separator\n .clone()\n .unwrap_or_else(|| std::path::MAIN_SEPARATOR.to_string());\n check_path_separator_length(path_separator.as_deref())?;\n\n let size_limits = std::mem::take(&mut opts.size);\n let time_constraints = extract_time_constraints(&opts)?;\n #[cfg(unix)]\n let owner_constraint: Option<OwnerFilter> = opts.owner.and_then(OwnerFilter::filter_ignore);\n\n #[cfg(windows)]\n let ansi_colors_support =\n nu_ansi_term::enable_ansi_support().is_ok() || std::env::var_os(\"TERM\").is_some();\n #[cfg(not(windows))]\n let ansi_colors_support = true;\n\n let interactive_termin"}
{"repo":"fd","file":"src/main.rs","line":400,"symbol":"extract_command","kind":"function","lang":"rust","code":"fn extract_command(opts: &mut Opts, colored_output: bool) -> Result<Option<CommandSet>> {\n opts.exec\n .command\n .take()\n .map(Ok)\n .or_else(|| {\n if !opts.list_details {\n return None;\n }\n\n let res = determine_ls_command(colored_output)\n .map(|cmd| CommandSet::new_batch([cmd]).unwrap());\n Some(res)\n })\n .transpose()\n}"}
{"repo":"fd","file":"src/main.rs","line":417,"symbol":"determine_ls_command","kind":"function","lang":"rust","code":"fn determine_ls_command(colored_output: bool) -> Result<Vec<&'static str>> {\n #[allow(unused)]\n let gnu_ls = |command_name| {\n let color_arg = if colored_output {\n \"--color=always\"\n } else {\n \"--color=never\"\n };\n // Note: we use short options here (instead of --long-options) to support more\n // platforms (like BusyBox).\n vec![\n command_name,\n \"-l\", // long listing format\n \"-h\", // human readable file sizes\n \"-d\", // list directories themselves, not their contents\n color_arg,\n ]\n };\n let cmd: Vec<&str> = if cfg!(unix) {\n if !cfg!(any(\n target_os = \"macos\",\n target_os = \"dragonfly\",\n target_os = \"freebsd\",\n target_os = \"netbsd\",\n target_os = \"openbsd\"\n )) {\n // Assume ls is GNU ls\n gnu_ls(\"ls\")\n } else {\n // macOS, DragonFlyBSD, FreeBSD\n use std::process::{Command, Stdio};\n\n // Use GNU ls, if available (support for --color=auto, better LS_COLORS support)\n let gnu_ls_exists = Command::new(\"gls\")\n "}
{"repo":"fd","file":"src/main.rs","line":501,"symbol":"extract_time_constraints","kind":"function","lang":"rust","code":"fn extract_time_constraints(opts: &Opts) -> Result<Vec<TimeFilter>> {\n let mut time_constraints: Vec<TimeFilter> = Vec::new();\n if let Some(ref t) = opts.changed_within {\n if let Some(f) = TimeFilter::after(t) {\n time_constraints.push(f);\n } else {\n return Err(anyhow!(\n \"'{}' is not a valid date or duration. See 'fd --help'.\",\n t\n ));\n }\n }\n if let Some(ref t) = opts.changed_before {\n if let Some(f) = TimeFilter::before(t) {\n time_constraints.push(f);\n } else {\n return Err(anyhow!(\n \"'{}' is not a valid date or duration. See 'fd --help'.\",\n t\n ));\n }\n }\n Ok(time_constraints)\n}"}
{"repo":"fd","file":"src/main.rs","line":526,"symbol":"ensure_use_hidden_option_for_leading_dot_pattern","kind":"function","lang":"rust","code":"fn ensure_use_hidden_option_for_leading_dot_pattern(\n config: &Config,\n pattern_regexps: &[String],\n) -> Result<()> {\n if cfg!(unix)\n && config.ignore_hidden\n && pattern_regexps\n .iter()\n .any(|pat| pattern_matches_strings_with_leading_dot(pat))\n {\n Err(anyhow!(\n \"The pattern(s) seems to only match files with a leading dot, but hidden files are \\\n filtered by default. Consider adding -H/--hidden to search hidden files as well \\\n or adjust your search pattern(s).\"\n ))\n } else {\n Ok(())\n }\n}"}
{"repo":"fd","file":"src/main.rs","line":546,"symbol":"build_regex","kind":"function","lang":"rust","code":"fn build_regex(pattern_regex: String, config: &Config) -> Result<regex::bytes::Regex> {\n RegexBuilder::new(&pattern_regex)\n .case_insensitive(!config.case_sensitive)\n .dot_matches_new_line(true)\n .build()\n .map_err(|e| {\n anyhow!(\n \"{}\\n\\nNote: You can search for literal substrings with '--fixed-strings' \\\n or literal strings with '--exact' options (instead of a regular expression). \\\n Alternatively, you can \\\n also use the '--glob' option to match on a glob pattern.\",\n e\n )\n })\n}"}
{"repo":"fd","file":"src/output.rs","line":12,"symbol":"replace_path_separator","kind":"function","lang":"rust","code":"fn replace_path_separator(path: &str, new_path_separator: &str) -> String {\n path.replace(std::path::MAIN_SEPARATOR, new_path_separator)\n}"}
{"repo":"fd","file":"src/output.rs","line":17,"symbol":"print_entry","kind":"function","lang":"rust","doc":"TODO: this function is performance critical and can probably be optimized","code":"pub fn print_entry<W: Write>(stdout: &mut W, entry: &DirEntry, config: &Config) -> io::Result<()> {\n let mut has_hyperlink = false;\n if config.hyperlink\n && let Some(url) = PathUrl::new(entry.path())\n {\n write!(stdout, \"\\x1B]8;;{url}\\x1B\\\\\")?;\n has_hyperlink = true;\n }\n\n if let Some(ref format) = config.format {\n print_entry_format(stdout, entry, config, format)?;\n } else if let Some(ref ls_colors) = config.ls_colors {\n print_entry_colorized(stdout, entry, config, ls_colors)?;\n } else {\n print_entry_uncolorized(stdout, entry, config)?;\n };\n\n if has_hyperlink {\n write!(stdout, \"\\x1B]8;;\\x1B\\\\\")?;\n }\n\n if config.null_separator {\n write!(stdout, \"\\0\")\n } else {\n writeln!(stdout)\n }\n}"}
{"repo":"fd","file":"src/output.rs","line":49,"symbol":"print_trailing_slash","kind":"function","lang":"rust","doc":"Display a trailing slash if the path is a directory and the config option is enabled. If the path_separator option is set, display that instead. The trailing slash will not be colored.","code":"fn print_trailing_slash<W: Write>(\n stdout: &mut W,\n entry: &DirEntry,\n config: &Config,\n style: Option<&Style>,\n) -> io::Result<()> {\n if entry.file_type().is_some_and(|ft| ft.is_dir()) {\n write!(\n stdout,\n \"{}\",\n style\n .map(Style::to_nu_ansi_term_style)\n .unwrap_or_default()\n .paint(&config.actual_path_separator)\n )?;\n }\n Ok(())\n}"}
{"repo":"fd","file":"src/output.rs","line":69,"symbol":"print_entry_format","kind":"function","lang":"rust","doc":"TODO: this function is performance critical and can probably be optimized","code":"fn print_entry_format<W: Write>(\n stdout: &mut W,\n entry: &DirEntry,\n config: &Config,\n format: &FormatTemplate,\n) -> io::Result<()> {\n let output = format.generate(\n entry.stripped_path(config),\n config.path_separator.as_deref(),\n );\n // TODO: support writing raw bytes on unix?\n let s = output.to_string_lossy();\n write!(\n stdout,\n \"{}\",\n sanitize_for_term(&s, config.interactive_terminal)\n )\n}"}
{"repo":"fd","file":"src/output.rs","line":89,"symbol":"print_entry_colorized","kind":"function","lang":"rust","doc":"TODO: this function is performance critical and can probably be optimized","code":"fn print_entry_colorized<W: Write>(\n stdout: &mut W,\n entry: &DirEntry,\n config: &Config,\n ls_colors: &LsColors,\n) -> io::Result<()> {\n let mut offset = 0;\n let path = entry.stripped_path(config);\n let path_str = path.to_string_lossy();\n\n if let Some(parent) = path.parent() {\n offset = parent.to_string_lossy().len();\n for c in path_str[offset..].chars() {\n if std::path::is_separator(c) {\n offset += c.len_utf8();\n } else {\n break;\n }\n }\n }\n\n if offset > 0 {\n let mut parent_str = Cow::from(&path_str[..offset]);\n if let Some(ref separator) = config.path_separator {\n *parent_str.to_mut() = replace_path_separator(&parent_str, separator);\n }\n\n let style = ls_colors\n .style_for_indicator(Indicator::Directory)\n .map(Style::to_nu_ansi_term_style)\n .unwrap_or_default();\n let safe_parent = sanitize_for_term(&parent_str, config.interactive_terminal);\n // We explicitly use prefix/suffix instead of paint so that we can use Sanitized\n write!(\n stdout,\n \"{}{}{}\",\n "}
{"repo":"fd","file":"src/output.rs","line":156,"symbol":"print_entry_uncolorized_base","kind":"function","lang":"rust","doc":"TODO: this function is performance critical and can probably be optimized","code":"fn print_entry_uncolorized_base<W: Write>(\n stdout: &mut W,\n entry: &DirEntry,\n config: &Config,\n) -> io::Result<()> {\n let path = entry.stripped_path(config);\n\n let mut path_string = path.to_string_lossy();\n if let Some(ref separator) = config.path_separator {\n *path_string.to_mut() = replace_path_separator(&path_string, separator);\n }\n let safe = sanitize_for_term(&path_string, config.interactive_terminal);\n write!(stdout, \"{safe}\")?;\n print_trailing_slash(stdout, entry, config, None)\n}"}
{"repo":"fd","file":"src/output.rs","line":173,"symbol":"print_entry_uncolorized","kind":"function","lang":"rust","code":"fn print_entry_uncolorized<W: Write>(\n stdout: &mut W,\n entry: &DirEntry,\n config: &Config,\n) -> io::Result<()> {\n print_entry_uncolorized_base(stdout, entry, config)\n}"}
{"repo":"fd","file":"src/output.rs","line":182,"symbol":"print_entry_uncolorized","kind":"function","lang":"rust","code":"fn print_entry_uncolorized<W: Write>(\n stdout: &mut W,\n entry: &DirEntry,\n config: &Config,\n) -> io::Result<()> {\n use std::os::unix::ffi::OsStrExt;\n\n if config.interactive_terminal || config.path_separator.is_some() {\n print_entry_uncolorized_base(stdout, entry, config)\n } else {\n // Piped output: raw bytes so invalid UTF-8 filenames reach downstream tools intact.\n stdout.write_all(entry.stripped_path(config).as_os_str().as_bytes())?;\n print_trailing_slash(stdout, entry, config, None)\n }\n}"}
{"repo":"fd","file":"src/regex_helper.rs","line":5,"symbol":"pattern_has_uppercase_char","kind":"function","lang":"rust","doc":"Determine if a regex pattern contains a literal uppercase character.","code":"pub fn pattern_has_uppercase_char(pattern: &str) -> bool {\n let mut parser = ParserBuilder::new().utf8(false).build();\n\n parser\n .parse(pattern)\n .map(|hir| hir_has_uppercase_char(&hir))\n .unwrap_or(false)\n}"}
{"repo":"fd","file":"src/regex_helper.rs","line":15,"symbol":"hir_has_uppercase_char","kind":"function","lang":"rust","doc":"Determine if a regex expression contains a literal uppercase character.","code":"fn hir_has_uppercase_char(hir: &Hir) -> bool {\n use regex_syntax::hir::*;\n\n match hir.kind() {\n HirKind::Literal(Literal(bytes)) => match std::str::from_utf8(bytes) {\n Ok(s) => s.chars().any(|c| c.is_uppercase()),\n Err(_) => bytes.iter().any(|b| char::from(*b).is_uppercase()),\n },\n HirKind::Class(Class::Unicode(ranges)) => ranges\n .iter()\n .any(|r| r.start().is_uppercase() || r.end().is_uppercase()),\n HirKind::Class(Class::Bytes(ranges)) => ranges\n .iter()\n .any(|r| char::from(r.start()).is_uppercase() || char::from(r.end()).is_uppercase()),\n HirKind::Capture(Capture { sub, .. }) | HirKind::Repetition(Repetition { sub, .. }) => {\n hir_has_uppercase_char(sub)\n }\n HirKind::Concat(hirs) | HirKind::Alternation(hirs) => {\n hirs.iter().any(hir_has_uppercase_char)\n }\n _ => false,\n }\n}"}
{"repo":"fd","file":"src/regex_helper.rs","line":40,"symbol":"pattern_matches_strings_with_leading_dot","kind":"function","lang":"rust","doc":"Determine if a regex pattern only matches strings starting with a literal dot (hidden files)","code":"pub fn pattern_matches_strings_with_leading_dot(pattern: &str) -> bool {\n let mut parser = ParserBuilder::new().utf8(false).build();\n\n parser\n .parse(pattern)\n .map(|hir| hir_matches_strings_with_leading_dot(&hir))\n .unwrap_or(false)\n}"}
{"repo":"fd","file":"src/regex_helper.rs","line":50,"symbol":"hir_matches_strings_with_leading_dot","kind":"function","lang":"rust","doc":"See above.","code":"fn hir_matches_strings_with_leading_dot(hir: &Hir) -> bool {\n use regex_syntax::hir::*;\n\n // Note: this only really detects the simplest case where a regex starts with\n // \"^\\\\.\", i.e. a start text anchor and a literal dot character. There are a lot\n // of other patterns that ONLY match hidden files, e.g. ^(\\\\.foo|\\\\.bar) which are\n // not (yet) detected by this algorithm.\n match hir.kind() {\n HirKind::Concat(hirs) => {\n let mut hirs = hirs.iter();\n if let Some(hir) = hirs.next() {\n if hir.kind() != &HirKind::Look(Look::Start) {\n return false;\n }\n } else {\n return false;\n }\n\n if let Some(hir) = hirs.next() {\n match hir.kind() {\n HirKind::Literal(Literal(bytes)) => bytes.starts_with(b\".\"),\n _ => false,\n }\n } else {\n false\n }\n }\n _ => false,\n }\n}"}
{"repo":"fd","file":"src/regex_helper.rs","line":82,"symbol":"pattern_has_uppercase_char_simple","kind":"function","lang":"rust","code":"fn pattern_has_uppercase_char_simple() {\n assert!(pattern_has_uppercase_char(\"A\"));\n assert!(pattern_has_uppercase_char(\"foo.EXE\"));\n\n assert!(!pattern_has_uppercase_char(\"a\"));\n assert!(!pattern_has_uppercase_char(\"foo.exe123\"));\n}"}
{"repo":"fd","file":"src/regex_helper.rs","line":91,"symbol":"pattern_has_uppercase_char_advanced","kind":"function","lang":"rust","code":"fn pattern_has_uppercase_char_advanced() {\n assert!(pattern_has_uppercase_char(\"foo.[a-zA-Z]\"));\n\n assert!(!pattern_has_uppercase_char(r\"\\Acargo\"));\n assert!(!pattern_has_uppercase_char(r\"carg\\x6F\"));\n}"}
{"repo":"fd","file":"src/regex_helper.rs","line":99,"symbol":"matches_strings_with_leading_dot_simple","kind":"function","lang":"rust","code":"fn matches_strings_with_leading_dot_simple() {\n assert!(pattern_matches_strings_with_leading_dot(\"^\\\\.gitignore\"));\n\n assert!(!pattern_matches_strings_with_leading_dot(\"^.gitignore\"));\n assert!(!pattern_matches_strings_with_leading_dot(\"\\\\.gitignore\"));\n assert!(!pattern_matches_strings_with_leading_dot(\"^gitignore\"));\n}"}
{"repo":"fd","file":"src/sanitize.rs","line":8,"symbol":"needs_escape","kind":"function","lang":"rust","doc":"True for any char that is neither printable nor permitted whitespace (only HT). Covers C0/C1/DEL, bidi overrides, zero-width and format chars, and tag chars.","code":"fn needs_escape(c: char) -> bool {\n if c == '\\t' {\n return false;\n }\n c.is_control()\n || matches!(c,\n '\\u{00AD}' // soft hyphen (invisible)\n | '\\u{180E}' // Mongolian vowel separator\n | '\\u{200B}'..='\\u{200F}' // zero-width + LRM/RLM\n | '\\u{202A}'..='\\u{202E}' // bidi embedding/override\n | '\\u{2060}'..='\\u{206F}' // word joiner, invisibles, deprecated formats\n | '\\u{FEFF}' // BOM / zero-width no-break space\n | '\\u{FFF9}'..='\\u{FFFB}' // interlinear annotation\n | '\\u{E0000}'..='\\u{E007F}' // language tags\n )\n}"}
{"repo":"fd","file":"src/sanitize.rs","line":26,"symbol":"write_sanitized","kind":"function","lang":"rust","doc":"Write the sanitized contents of `raw` to `f`.","code":"pub fn write_sanitized(f: &mut std::fmt::Formatter<'_>, raw: &str) -> std::fmt::Result {\n // Would it be faster to do a pass to see if we don't need an escape and write\n // the whole string first? Maybe with a faster check just for non-control ASCII?\n for c in raw.chars() {\n if needs_escape(c) {\n let v = c as u32;\n if v <= 0xFF {\n write!(f, \"\\\\x{v:02X}\")?;\n } else {\n write!(f, \"\\\\u{{{v:04X}}}\")?;\n }\n } else {\n f.write_char(c)?;\n }\n }\n Ok(())\n}"}
{"repo":"fd","file":"src/sanitize.rs","line":47,"symbol":"SanitizedStr","kind":"type","lang":"rust","doc":"A wrapper type that sanitizes the output to Display","code":"pub(crate) struct SanitizedStr<'a> {\n raw: &'a str,\n /// If true, the content is safe to output without sanitizing,\n /// either because it is trusted, or because it isn't going to a terminal.\n is_safe: bool,\n}"}
{"repo":"fd","file":"src/sanitize.rs","line":55,"symbol":"fmt","kind":"function","lang":"rust","code":"fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {\n if self.is_safe {\n // We don't need to sanitize anything, just forward\n self.raw.fmt(f)\n } else {\n write_sanitized(f, self.raw)\n }\n }"}
{"repo":"fd","file":"src/sanitize.rs","line":66,"symbol":"sanitize_for_term","kind":"function","lang":"rust","doc":"Sanitize for terminal output only; raw bytes pass through on pipes/files.","code":"pub fn sanitize_for_term(raw: &str, is_terminal: bool) -> SanitizedStr<'_> {\n SanitizedStr {\n raw,\n is_safe: !is_terminal,\n }\n}"}
{"repo":"fd","file":"src/sanitize.rs","line":77,"symbol":"sanitize_string","kind":"function","lang":"rust","code":"fn sanitize_string(s: &str) -> String {\n SanitizedStr {\n raw: s,\n is_safe: false,\n }\n .to_string()\n }"}
{"repo":"fd","file":"src/sanitize.rs","line":86,"symbol":"preserves_safe_content","kind":"function","lang":"rust","code":"fn preserves_safe_content() {\n for s in [\n \"hello.txt\",\n \"résumé.pdf\",\n \"文档.txt\",\n \"🦀.rs\",\n \"a\\tb\",\n \"a\\u{FFFD}b\",\n ] {\n assert_eq!(sanitize_string(s), s);\n }\n }"}
{"repo":"fd","file":"src/sanitize.rs","line":100,"symbol":"strips_osc52_clipboard_payload","kind":"function","lang":"rust","code":"fn strips_osc52_clipboard_payload() {\n let attack = \"innocent\\x1b]52;c;cHduZWQ=\\x1b\\\\.txt\";\n let safe = sanitize_string(attack);\n assert!(!safe.contains('\\x1b'));\n assert_eq!(safe, \"innocent\\\\x1B]52;c;cHduZWQ=\\\\x1B\\\\.txt\");\n }"}
{"repo":"fd","file":"src/sanitize.rs","line":108,"symbol":"strips_cr_output_forgery","kind":"function","lang":"rust","code":"fn strips_cr_output_forgery() {\n assert_eq!(sanitize_string(\"A\\rFAKE OUTPUT\"), \"A\\\\x0DFAKE OUTPUT\");\n }"}
{"repo":"fd","file":"src/sanitize.rs","line":113,"symbol":"strips_osc8_hyperlink_injection","kind":"function","lang":"rust","code":"fn strips_osc8_hyperlink_injection() {\n let attack = \"phish\\x1b]8;;https:evil.example\\x1b\\\\phony.txt\";\n assert!(!sanitize_string(attack).contains('\\x1b'));\n }"}
{"repo":"fd","file":"src/sanitize.rs","line":119,"symbol":"strips_del","kind":"function","lang":"rust","code":"fn strips_del() {\n assert_eq!(sanitize_string(\"a\\x7fb\"), \"a\\\\x7Fb\");\n }"}
{"repo":"fd","file":"src/sanitize.rs","line":124,"symbol":"strips_bel_and_null","kind":"function","lang":"rust","code":"fn strips_bel_and_null() {\n assert_eq!(sanitize_string(\"a\\x07b\"), \"a\\\\x07b\");\n assert_eq!(sanitize_string(\"a\\0b\"), \"a\\\\x00b\");\n }"}
{"repo":"fd","file":"src/sanitize.rs","line":130,"symbol":"escape_preserves_information","kind":"function","lang":"rust","code":"fn escape_preserves_information() {\n let s = \"name\\x1bX\\x07Y.txt\";\n assert_eq!(sanitize_string(s), \"name\\\\x1BX\\\\x07Y.txt\");\n }"}
{"repo":"fd","file":"src/sanitize.rs","line":136,"symbol":"strips_c1_csi_and_osc_initiators","kind":"function","lang":"rust","code":"fn strips_c1_csi_and_osc_initiators() {\n // U+009B is CSI, U+009D is OSC; dangerous on 8-bit-control terminals.\n assert_eq!(sanitize_string(\"\\u{9b}31m\"), \"\\\\x9B31m\");\n assert_eq!(sanitize_string(\"\\u{9d}0;pwned\\u{9c}\"), \"\\\\x9D0;pwned\\\\x9C\");\n }"}
{"repo":"fd","file":"src/sanitize.rs","line":143,"symbol":"strips_bidi_overrides_and_zero_width","kind":"function","lang":"rust","code":"fn strips_bidi_overrides_and_zero_width() {\n // Trojan-Source style RLO/LRO that flip rendered order of filename text.\n assert_eq!(\n sanitize_string(\"safe\\u{202E}fil\\u{202D}gnp.exe\"),\n \"safe\\\\u{202E}fil\\\\u{202D}gnp.exe\"\n );\n // Zero-width space and BOM are also format chars used to disguise filenames.\n assert_eq!(sanitize_string(\"a\\u{200B}b\"), \"a\\\\u{200B}b\");\n assert_eq!(sanitize_string(\"\\u{FEFF}name\"), \"\\\\u{FEFF}name\");\n }"}
{"repo":"fd","file":"src/sanitize.rs","line":155,"symbol":"keeps_legitimate_unicode_features","kind":"function","lang":"rust","code":"fn keeps_legitimate_unicode_features() {\n // Variation selectors (U+FE0F, U+E0100..) modify preceding glyphs in CJK/emoji\n // and are legitimate in filenames. Private-use chars are used by icon fonts.\n for s in [\n \"heart\\u{2764}\\u{FE0F}.txt\",\n \"icon\\u{E000}.cfg\",\n \"cjk\\u{6F22}\\u{E0101}.txt\",\n ] {\n assert_eq!(sanitize_string(s), s);\n }\n }"}
{"repo":"fd","file":"src/sanitize.rs","line":168,"symbol":"maybe_sanitize_passthrough_when_not_terminal","kind":"function","lang":"rust","code":"fn maybe_sanitize_passthrough_when_not_terminal() {\n let attack = \"x\\x1by\";\n // Pipe context: bytes pass through unchanged (zero-copy).\n let out = sanitize_for_term(attack, false).to_string();\n assert_eq!(out, attack);\n // TTY context: escapes apply.\n assert_eq!(sanitize_for_term(attack, true).to_string(), \"x\\\\x1By\");\n }"}
{"repo":"fd","file":"src/walk.rs","line":27,"symbol":"ReceiverMode","kind":"type","lang":"rust","doc":"The receiver thread can either be buffering results or directly streaming to the console.","code":"enum ReceiverMode {\n /// Receiver is still buffering in order to sort the results, if the search finishes fast\n /// enough.\n Buffering,\n\n /// Receiver is directly printing results to the output.\n Streaming,\n}"}
{"repo":"fd","file":"src/walk.rs","line":39,"symbol":"WorkerResult","kind":"type","lang":"rust","doc":"The Worker threads can result in a valid entry having PathBuf or an error.","code":"pub enum WorkerResult {\n // Errors should be rare, so it's probably better to allow large_enum_variant than\n // to box the Entry variant\n Entry(DirEntry),\n Error(ignore::Error),\n}"}
{"repo":"fd","file":"src/walk.rs","line":48,"symbol":"Batch","kind":"type","lang":"rust","doc":"A batch of WorkerResults to send over a channel.","code":"struct Batch {\n items: Arc<Mutex<Option<Vec<WorkerResult>>>>,\n}"}
{"repo":"fd","file":"src/walk.rs","line":53,"symbol":"new","kind":"function","lang":"rust","code":"fn new() -> Self {\n Self {\n items: Arc::new(Mutex::new(Some(vec![]))),\n }\n }"}
{"repo":"fd","file":"src/walk.rs","line":59,"symbol":"lock","kind":"function","lang":"rust","code":"fn lock(&self) -> MutexGuard<'_, Option<Vec<WorkerResult>>> {\n self.items.lock().unwrap()\n }"}
{"repo":"fd","file":"src/walk.rs","line":68,"symbol":"into_iter","kind":"function","lang":"rust","code":"fn into_iter(self) -> Self::IntoIter {\n self.lock().take().unwrap().into_iter()\n }"}
{"repo":"fd","file":"src/walk.rs","line":74,"symbol":"BatchSender","kind":"type","lang":"rust","doc":"Wrapper that sends batches of items at once over a channel.","code":"struct BatchSender {\n batch: Batch,\n tx: Sender<Batch>,\n limit: usize,\n}"}
{"repo":"fd","file":"src/walk.rs","line":81,"symbol":"new","kind":"function","lang":"rust","code":"fn new(tx: Sender<Batch>, limit: usize) -> Self {\n Self {\n batch: Batch::new(),\n tx,\n limit,\n }\n }"}
{"repo":"fd","file":"src/walk.rs","line":90,"symbol":"needs_flush","kind":"function","lang":"rust","doc":"Check if we need to flush a batch.","code":"fn needs_flush(&self, batch: Option<&Vec<WorkerResult>>) -> bool {\n match batch {\n // Limit the batch size to provide some backpressure\n Some(vec) => vec.len() >= self.limit,\n // Batch was already taken by the receiver, so make a new one\n None => true,\n }\n }"}
{"repo":"fd","file":"src/walk.rs","line":100,"symbol":"send","kind":"function","lang":"rust","doc":"Add an item to a batch.","code":"fn send(&mut self, item: WorkerResult) -> Result<(), SendError<()>> {\n let mut batch = self.batch.lock();\n\n if self.needs_flush(batch.as_ref()) {\n drop(batch);\n self.batch = Batch::new();\n batch = self.batch.lock();\n }\n\n let items = batch.as_mut().unwrap();\n items.push(item);\n\n if items.len() == 1 {\n // New batch, send it over the channel\n self.tx\n .send(self.batch.clone())\n .map_err(|_| SendError(()))?;\n }\n\n Ok(())\n }"}
{"repo":"fd","file":"src/walk.rs","line":129,"symbol":"ReceiverBuffer","kind":"type","lang":"rust","doc":"Wrapper for the receiver thread's buffering behavior.","code":"struct ReceiverBuffer<'a, W> {\n /// The configuration.\n config: &'a Config,\n /// For shutting down the senders.\n quit_flag: &'a AtomicBool,\n /// The ^C notifier.\n interrupt_flag: &'a AtomicBool,\n /// Receiver for worker results.\n rx: Receiver<Batch>,\n /// Standard output.\n stdout: W,\n /// The current buffer mode.\n mode: ReceiverMode,\n /// The deadline to switch to streaming mode.\n deadline: Instant,\n /// The buffer of quickly received paths.\n buffer: Vec<DirEntry>,\n /// Result count.\n num_results: usize,\n}"}
{"repo":"fd","file":"src/walk.rs","line":152,"symbol":"new","kind":"function","lang":"rust","doc":"Create a new receiver buffer.","code":"fn new(state: &'a WorkerState, rx: Receiver<Batch>, stdout: W) -> Self {\n let config = &state.config;\n let quit_flag = state.quit_flag.as_ref();\n let interrupt_flag = state.interrupt_flag.as_ref();\n let max_buffer_time = config.max_buffer_time.unwrap_or(DEFAULT_MAX_BUFFER_TIME);\n let deadline = Instant::now() + max_buffer_time;\n\n Self {\n config,\n quit_flag,\n interrupt_flag,\n rx,\n stdout,\n mode: ReceiverMode::Buffering,\n deadline,\n buffer: Vec::with_capacity(MAX_BUFFER_LENGTH),\n num_results: 0,\n }\n }"}
{"repo":"fd","file":"src/walk.rs","line":173,"symbol":"process","kind":"function","lang":"rust","doc":"Process results until finished.","code":"fn process(&mut self) -> ExitCode {\n loop {\n if let Err(ec) = self.poll() {\n self.quit_flag.store(true, Ordering::Relaxed);\n return ec;\n }\n }\n }"}
{"repo":"fd","file":"src/walk.rs","line":183,"symbol":"recv","kind":"function","lang":"rust","doc":"Receive the next worker result.","code":"fn recv(&self) -> Result<Batch, RecvTimeoutError> {\n match self.mode {\n ReceiverMode::Buffering => {\n // Wait at most until we should switch to streaming\n self.rx.recv_deadline(self.deadline)\n }\n ReceiverMode::Streaming => {\n // Wait however long it takes for a result\n Ok(self.rx.recv()?)\n }\n }\n }"}
{"repo":"fd","file":"src/walk.rs","line":197,"symbol":"poll","kind":"function","lang":"rust","doc":"Wait for a result or state change.","code":"fn poll(&mut self) -> Result<(), ExitCode> {\n match self.recv() {\n Ok(batch) => {\n for result in batch {\n match result {\n WorkerResult::Entry(dir_entry) => {\n if self.config.quiet {\n return Err(ExitCode::HasResults(true));\n }\n\n match self.mode {\n ReceiverMode::Buffering => {\n self.buffer.push(dir_entry);\n if self.buffer.len() > MAX_BUFFER_LENGTH {\n self.stream()?;\n }\n }\n ReceiverMode::Streaming => {\n self.print(&dir_entry)?;\n }\n }\n\n self.num_results += 1;\n if let Some(max_results) = self.config.max_results\n && self.num_results >= max_results\n {\n "}
{"repo":"fd","file":"src/walk.rs","line":251,"symbol":"print","kind":"function","lang":"rust","doc":"Output a path.","code":"fn print(&mut self, entry: &DirEntry) -> Result<(), ExitCode> {\n if let Err(e) = output::print_entry(&mut self.stdout, entry, self.config)\n && e.kind() != ::std::io::ErrorKind::BrokenPipe\n {\n print_error!(\"Could not write to output: {}\", e);\n return Err(ExitCode::GeneralError);\n }\n\n if self.interrupt_flag.load(Ordering::Relaxed) {\n // Ignore any errors on flush, because we're about to exit anyway\n let _ = self.flush();\n return Err(ExitCode::KilledBySigint);\n }\n\n Ok(())\n }"}
{"repo":"fd","file":"src/walk.rs","line":269,"symbol":"stream","kind":"function","lang":"rust","doc":"Switch ourselves into streaming mode.","code":"fn stream(&mut self) -> Result<(), ExitCode> {\n self.mode = ReceiverMode::Streaming;\n\n let buffer = mem::take(&mut self.buffer);\n for path in buffer {\n self.print(&path)?;\n }\n\n self.flush()\n }"}
{"repo":"fd","file":"src/walk.rs","line":281,"symbol":"stop","kind":"function","lang":"rust","doc":"Stop looping.","code":"fn stop(&mut self) -> Result<(), ExitCode> {\n if self.mode == ReceiverMode::Buffering {\n self.buffer.sort();\n self.stream()?;\n }\n\n if self.config.quiet {\n Err(ExitCode::HasResults(self.num_results > 0))\n } else {\n Err(ExitCode::Success)\n }\n }"}
{"repo":"fd","file":"src/walk.rs","line":295,"symbol":"flush","kind":"function","lang":"rust","doc":"Flush stdout if necessary.","code":"fn flush(&mut self) -> Result<(), ExitCode> {\n if self.stdout.flush().is_err() {\n // Probably a broken pipe. Exit gracefully.\n return Err(ExitCode::GeneralError);\n }\n Ok(())\n }"}
{"repo":"fd","file":"src/walk.rs","line":305,"symbol":"WorkerState","kind":"type","lang":"rust","doc":"State shared by the sender and receiver threads.","code":"struct WorkerState {\n /// The search patterns.\n patterns: Vec<Regex>,\n /// The command line configuration.\n config: Config,\n /// Flag for cleanly shutting down the parallel walk\n quit_flag: Arc<AtomicBool>,\n /// Flag specifically for quitting due to ^C\n interrupt_flag: Arc<AtomicBool>,\n}"}
{"repo":"fd","file":"src/walk.rs","line":317,"symbol":"new","kind":"function","lang":"rust","code":"fn new(patterns: Vec<Regex>, config: Config) -> Self {\n let quit_flag = Arc::new(AtomicBool::new(false));\n let interrupt_flag = Arc::new(AtomicBool::new(false));\n\n Self {\n patterns,\n config,\n quit_flag,\n interrupt_flag,\n }\n }"}
{"repo":"fd","file":"src/walk.rs","line":329,"symbol":"build_overrides","kind":"function","lang":"rust","code":"fn build_overrides(&self, paths: &[PathBuf]) -> Result<Override> {\n let first_path = &paths[0];\n let config = &self.config;\n\n let mut builder = OverrideBuilder::new(first_path);\n\n for pattern in &config.exclude_patterns {\n builder\n .add(pattern)\n .map_err(|e| anyhow!(\"Malformed exclude pattern: {}\", e))?;\n }\n\n builder\n .build()\n .map_err(|_| anyhow!(\"Mismatch in exclude patterns\"))\n }"}
{"repo":"fd","file":"src/walk.rs","line":346,"symbol":"build_walker","kind":"function","lang":"rust","code":"fn build_walker(&self, paths: &[PathBuf]) -> Result<WalkParallel> {\n let first_path = &paths[0];\n let config = &self.config;\n let overrides = self.build_overrides(paths)?;\n\n let mut builder = WalkBuilder::new(first_path);\n builder\n .hidden(config.ignore_hidden)\n .ignore(config.read_fdignore)\n .parents(config.read_parent_ignore && (config.read_fdignore || config.read_vcsignore))\n .git_ignore(config.read_vcsignore)\n .git_global(config.read_vcsignore)\n .git_exclude(config.read_vcsignore)\n .require_git(config.require_git_to_read_vcsignore)\n .overrides(overrides)\n .follow_links(config.follow_links)\n // No need to check for supported platforms, option is unavailable on unsupported ones\n .same_file_system(config.one_file_system)\n .max_depth(config.max_depth);\n\n if config.read_fdignore {\n builder.add_custom_ignore_filename(\".fdignore\");\n }\n\n if config.read_global_ignore\n && let Ok(basedirs) = etcetera::choose_base_strategy()\n {\n let global_ignore_file = basedirs.con"}
{"repo":"fd","file":"src/walk.rs","line":407,"symbol":"receive","kind":"function","lang":"rust","doc":"Run the receiver work, either on this thread or a pool of background threads (for --exec).","code":"fn receive(&self, rx: Receiver<Batch>) -> ExitCode {\n let config = &self.config;\n\n // This will be set to `Some` if the `--exec` argument was supplied.\n if let Some(ref cmd) = config.command {\n if cmd.in_batch_mode() {\n exec::batch(rx.into_iter().flatten(), cmd, config)\n } else {\n thread::scope(|scope| {\n // Each spawned job will store its thread handle in here.\n let threads = config.threads;\n let mut handles = Vec::with_capacity(threads);\n for _ in 0..threads {\n let rx = rx.clone();\n\n // Spawn a job thread that will listen for and execute inputs.\n let handle =\n scope.spawn(|| exec::job(rx.into_iter().flatten(), cmd, config));\n\n // Push the handle of the spawned thread into the vector for later joining.\n handles.push(handle);\n }\n let exit_codes = handles.into_iter().map(|handle| handle.join().unwrap());\n merge_exitcodes(exit_codes)\n "}
{"repo":"fd","file":"src/walk.rs","line":442,"symbol":"spawn_senders","kind":"function","lang":"rust","doc":"Spawn the sender threads.","code":"fn spawn_senders(&self, walker: WalkParallel, tx: Sender<Batch>) {\n walker.run(|| {\n let patterns = &self.patterns;\n let config = &self.config;\n let quit_flag = self.quit_flag.as_ref();\n\n let mut limit = 0x100;\n if let Some(cmd) = &config.command\n && !cmd.in_batch_mode()\n && config.threads > 1\n {\n // Evenly distribute work between multiple receivers\n limit = 1;\n }\n let mut tx = BatchSender::new(tx.clone(), limit);\n\n Box::new(move |entry| {\n if quit_flag.load(Ordering::Relaxed) {\n return WalkState::Quit;\n }\n\n if let Ok(e) = &entry {\n // If the entry is a directory that contains a\n // \"ignore contain\" file\", we want to skip this\n // directory.\n // Check the filetype first to avoid unnecessary\n // syscalls.\n if e.file_type().is_some_and(|t| t.is_dir()) {\n let entry_path = e.path();\n if config\n "}
{"repo":"fd","file":"src/walk.rs","line":616,"symbol":"scan","kind":"function","lang":"rust","doc":"Perform the recursive scan.","code":"fn scan(&self, paths: &[PathBuf]) -> Result<ExitCode> {\n let config = &self.config;\n let walker = self.build_walker(paths)?;\n\n if config.ls_colors.is_some() && config.is_printing() {\n let quit_flag = Arc::clone(&self.quit_flag);\n let interrupt_flag = Arc::clone(&self.interrupt_flag);\n\n ctrlc::set_handler(move || {\n quit_flag.store(true, Ordering::Relaxed);\n\n if interrupt_flag.fetch_or(true, Ordering::Relaxed) {\n // Ctrl-C has been pressed twice, exit NOW\n ExitCode::KilledBySigint.exit();\n }\n })\n .unwrap();\n }\n\n let (tx, rx) = bounded(2 * config.threads);\n\n let exit_code = thread::scope(|scope| {\n // Spawn the receiver thread(s)\n let receiver = scope.spawn(|| self.receive(rx));\n\n // Spawn the sender threads.\n self.spawn_senders(walker, tx);\n\n receiver.join().unwrap()\n });\n\n if self.interrupt_flag.load(Ordering::Relaxed) {\n Ok(ExitCode::KilledBySigint)\n } else {\n Ok(exit_code)\n }\n }"}
{"repo":"fd","file":"src/walk.rs","line":661,"symbol":"is_broken_symlink","kind":"function","lang":"rust","doc":"Whether a walk error is really a broken symlink rather than a failure worth reporting. A symlink whose target is missing is surfaced by the walker as a NotFound error against the link's own path, so it never arrives as an entry. fd still wants to match and print it (see issue #1017), which means recovering it here.","code":"fn is_broken_symlink(path: &Path, err: &ignore::Error) -> bool {\n err.io_error()\n .is_some_and(|io_error| io_error.kind() == io::ErrorKind::NotFound)\n && path\n .symlink_metadata()\n .ok()\n .is_some_and(|m| m.file_type().is_symlink())\n}"}
{"repo":"fd","file":"src/walk.rs","line":670,"symbol":"search_str_for_entry","kind":"function","lang":"rust","code":"fn search_str_for_entry<'a>(\n entry_path: &'a std::path::Path,\n full_path_base: Option<&std::path::Path>,\n) -> Cow<'a, OsStr> {\n if let Some(cwd) = full_path_base {\n // If full_path_base is some, that means that we need to return\n // the absolute path\n if entry_path.is_absolute() {\n return Cow::Borrowed(entry_path.as_os_str());\n }\n let path = entry_path.strip_prefix(\".\").unwrap_or(entry_path);\n Cow::Owned(cwd.join(path).into())\n } else {\n match entry_path.file_name() {\n Some(filename) => Cow::Borrowed(filename),\n None => unreachable!(\n \"Encountered file system entry without a file name. This should only \\\n happen for paths like 'foo/bar/..' or '/' which are not supposed to \\\n appear in a file system traversal.\"\n ),\n }\n }\n}"}
{"repo":"fd","file":"src/walk.rs","line":699,"symbol":"scan","kind":"function","lang":"rust","doc":"Recursively scan the given search path for files / pathnames matching the patterns. If the `--exec` argument was supplied, this will create a thread pool for executing jobs in parallel from a given command line and the discovered paths. Otherwise, each path will simply be written to standard output.","code":"pub fn scan(paths: &[PathBuf], patterns: Vec<Regex>, config: Config) -> Result<ExitCode> {\n WorkerState::new(patterns, config).scan(paths)\n}"}
{"repo":"fd","file":"src/walk.rs","line":709,"symbol":"search_str_for_entry_with_relative_path","kind":"function","lang":"rust","code":"fn search_str_for_entry_with_relative_path() {\n let full_path_base = Some(Path::new(\"/home/user\"));\n assert_eq!(\n search_str_for_entry(Path::new(\"foo/bar\"), full_path_base),\n PathBuf::from(\"/home/user/foo/bar\")\n );\n }"}
{"repo":"fd","file":"src/walk.rs","line":718,"symbol":"search_str_for_entry_strips_dot_prefix","kind":"function","lang":"rust","code":"fn search_str_for_entry_strips_dot_prefix() {\n let full_path_base = Some(Path::new(\"/home/user\"));\n assert_eq!(\n search_str_for_entry(Path::new(\"./foo/bar\"), full_path_base),\n PathBuf::from(\"/home/user/foo/bar\")\n );\n }"}
{"repo":"fd","file":"src/walk.rs","line":727,"symbol":"search_str_for_entry_with_absolute_path","kind":"function","lang":"rust","code":"fn search_str_for_entry_with_absolute_path() {\n let full_path_base = Some(Path::new(\"/home/user\"));\n assert_eq!(\n search_str_for_entry(Path::new(\"/absolute/path\"), full_path_base),\n PathBuf::from(\"/absolute/path\")\n );\n }"}
{"repo":"fd","file":"src/walk.rs","line":736,"symbol":"search_str_no_base_dir","kind":"function","lang":"rust","code":"fn search_str_no_base_dir() {\n assert_eq!(\n search_str_for_entry(Path::new(\"./foo/bar\"), None),\n PathBuf::from(\"bar\")\n );\n }"}
{"repo":"fd","file":"src/walk.rs","line":744,"symbol":"search_str_no_base_dir_with_plain_relative_path","kind":"function","lang":"rust","code":"fn search_str_no_base_dir_with_plain_relative_path() {\n assert_eq!(\n search_str_for_entry(Path::new(\"foo/bar\"), None),\n PathBuf::from(\"bar\")\n );\n }"}
{"repo":"fd","file":"src/walk.rs","line":752,"symbol":"search_str_no_base_dir_with_file_in_current_dir","kind":"function","lang":"rust","code":"fn search_str_no_base_dir_with_file_in_current_dir() {\n assert_eq!(\n search_str_for_entry(Path::new(\"foo\"), None),\n PathBuf::from(\"foo\")\n );\n }"}
{"repo":"fd","file":"tests/testenv/mod.rs","line":14,"symbol":"TestEnv","kind":"type","lang":"rust","doc":"Environment for the integration tests.","code":"pub struct TestEnv {\n /// Temporary working directory.\n temp_dir: TempDir,\n\n /// Path to the *fd* executable.\n fd_exe: PathBuf,\n\n /// Normalize each line by sorting the whitespace-separated words\n normalize_line: bool,\n\n /// Temporary directory for storing test config (global ignore file)\n config_dir: Option<TempDir>,\n}"}
{"repo":"fd","file":"tests/testenv/mod.rs","line":29,"symbol":"create_working_directory","kind":"function","lang":"rust","doc":"Create the working directory and the test files.","code":"fn create_working_directory(\n directories: &[&'static str],\n files: &[&'static str],\n) -> Result<TempDir, io::Error> {\n let temp_dir = tempfile::Builder::new().prefix(\"fd-tests\").tempdir()?;\n\n {\n let root = temp_dir.path();\n\n // Pretend that this is a Git repository in order for `.gitignore` files to be respected\n fs::create_dir_all(root.join(\".git\"))?;\n\n for directory in directories {\n fs::create_dir_all(root.join(directory))?;\n }\n\n for file in files {\n fs::File::create(root.join(file))?;\n }\n\n #[cfg(unix)]\n unix::fs::symlink(root.join(\"one/two\"), root.join(\"symlink\"))?;\n\n // Note: creating symlinks on Windows requires the `SeCreateSymbolicLinkPrivilege` which\n // is by default only granted for administrators.\n #[cfg(windows)]\n windows::fs::symlink_dir(root.join(\"one/two\"), root.join(\"symlink\"))?;\n\n fs::File::create(root.join(\".fdignore\"))?.write_all(b\"fdignored.foo\")?;\n\n fs::File::create(root.join(\".gitignore\"))?.write_all(b\"gitignored.foo\")?;\n }\n\n Ok(temp_dir)\n}"}
{"repo":"fd","file":"tests/testenv/mod.rs","line":65,"symbol":"create_config_directory_with_global_ignore","kind":"function","lang":"rust","code":"fn create_config_directory_with_global_ignore(ignore_file_content: &str) -> io::Result<TempDir> {\n let config_dir = tempfile::Builder::new().prefix(\"fd-config\").tempdir()?;\n let fd_dir = config_dir.path().join(\"fd\");\n fs::create_dir(&fd_dir)?;\n let mut ignore_file = fs::File::create(fd_dir.join(\"ignore\"))?;\n ignore_file.write_all(ignore_file_content.as_bytes())?;\n\n Ok(config_dir)\n}"}
{"repo":"fd","file":"tests/testenv/mod.rs","line":76,"symbol":"find_fd_exe","kind":"function","lang":"rust","doc":"Find the *fd* executable.","code":"fn find_fd_exe() -> PathBuf {\n // Read the location of the fd executable from the environment\n PathBuf::from(env::var(\"CARGO_BIN_EXE_fd\").unwrap_or(env!(\"CARGO_BIN_EXE_fd\").to_string()))\n}"}
{"repo":"fd","file":"tests/testenv/mod.rs","line":82,"symbol":"format_exit_error","kind":"function","lang":"rust","doc":"Format an error message for when *fd* did not exit successfully.","code":"fn format_exit_error(args: &[&str], output: &process::Output) -> String {\n format!(\n \"`fd {}` did not exit successfully.\\nstdout:\\n---\\n{}---\\nstderr:\\n---\\n{}---\",\n args.join(\" \"),\n String::from_utf8_lossy(&output.stdout),\n String::from_utf8_lossy(&output.stderr)\n )\n}"}
{"repo":"fd","file":"tests/testenv/mod.rs","line":92,"symbol":"format_output_error","kind":"function","lang":"rust","doc":"Format an error message for when the output of *fd* did not match the expected output.","code":"fn format_output_error(args: &[&str], expected: &str, actual: &str) -> String {\n // Generate diff text.\n let diff_text = diff::lines(expected, actual)\n .into_iter()\n .map(|diff| match diff {\n diff::Result::Left(l) => format!(\"-{l}\"),\n diff::Result::Both(l, _) => format!(\" {l}\"),\n diff::Result::Right(r) => format!(\"+{r}\"),\n })\n .collect::<Vec<_>>()\n .join(\"\\n\");\n\n format!(\n concat!(\n \"`fd {}` did not produce the expected output.\\n\",\n \"Showing diff between expected and actual:\\n{}\\n\"\n ),\n args.join(\" \"),\n diff_text\n )\n}"}
{"repo":"fd","file":"tests/testenv/mod.rs","line":115,"symbol":"normalize_output","kind":"function","lang":"rust","doc":"Normalize the output for comparison.","code":"fn normalize_output(s: &str, trim_start: bool, normalize_line: bool) -> String {\n // Split into lines and normalize separators.\n let mut lines = s\n .replace('\\0', \"NULL\\n\")\n .lines()\n .map(|line| {\n let line = if trim_start { line.trim_start() } else { line };\n let line = line.replace('/', std::path::MAIN_SEPARATOR_STR);\n if normalize_line {\n let mut words: Vec<_> = line.split_whitespace().collect();\n words.sort_unstable();\n return words.join(\" \");\n }\n line\n })\n .collect::<Vec<_>>();\n\n lines.sort();\n lines.join(\"\\n\")\n}"}
{"repo":"fd","file":"tests/testenv/mod.rs","line":137,"symbol":"trim_lines","kind":"function","lang":"rust","doc":"Trim whitespace from the beginning of each line.","code":"fn trim_lines(s: &str) -> String {\n s.lines()\n .map(|line| line.trim_start())\n .fold(String::new(), |mut str, line| {\n str.push_str(line);\n str.push('\\n');\n str\n })\n}"}
{"repo":"fd","file":"tests/testenv/mod.rs","line":148,"symbol":"new","kind":"function","lang":"rust","code":"pub fn new(directories: &[&'static str], files: &[&'static str]) -> TestEnv {\n let temp_dir = create_working_directory(directories, files).expect(\"working directory\");\n let fd_exe = find_fd_exe();\n\n TestEnv {\n temp_dir,\n fd_exe,\n normalize_line: false,\n config_dir: None,\n }\n }"}
{"repo":"fd","file":"tests/testenv/mod.rs","line":160,"symbol":"normalize_line","kind":"function","lang":"rust","code":"pub fn normalize_line(self, normalize: bool) -> TestEnv {\n TestEnv {\n temp_dir: self.temp_dir,\n fd_exe: self.fd_exe,\n normalize_line: normalize,\n config_dir: self.config_dir,\n }\n }"}
{"repo":"fd","file":"tests/testenv/mod.rs","line":169,"symbol":"global_ignore_file","kind":"function","lang":"rust","code":"pub fn global_ignore_file(self, content: &str) -> TestEnv {\n let config_dir =\n create_config_directory_with_global_ignore(content).expect(\"config directory\");\n TestEnv {\n config_dir: Some(config_dir),\n ..self\n }\n }"}
{"repo":"fd","file":"tests/testenv/mod.rs","line":179,"symbol":"create_broken_symlink","kind":"function","lang":"rust","doc":"Create a broken symlink at the given path in the temp_dir.","code":"pub fn create_broken_symlink<P: AsRef<Path>>(\n &mut self,\n link_path: P,\n ) -> Result<PathBuf, io::Error> {\n let root = self.test_root();\n let broken_symlink_link = root.join(link_path);\n {\n let temp_target_dir = tempfile::Builder::new()\n .prefix(\"fd-tests-broken-symlink\")\n .tempdir()?;\n let broken_symlink_target = temp_target_dir.path().join(\"broken_symlink_target\");\n fs::File::create(&broken_symlink_target)?;\n #[cfg(unix)]\n unix::fs::symlink(&broken_symlink_target, &broken_symlink_link)?;\n #[cfg(windows)]\n windows::fs::symlink_file(&broken_symlink_target, &broken_symlink_link)?;\n }\n Ok(broken_symlink_link)\n }"}
{"repo":"fd","file":"tests/testenv/mod.rs","line":199,"symbol":"create_symlink","kind":"function","lang":"rust","code":"pub fn create_symlink<P: AsRef<Path>>(\n &mut self,\n target: P,\n link_path: P,\n ) -> io::Result<PathBuf> {\n let root = self.test_root();\n let target_path = root.join(target);\n let link_path = root.join(link_path);\n #[cfg(unix)]\n unix::fs::symlink(&target_path, &link_path)?;\n #[cfg(windows)]\n windows::fs::symlink_file(&target_path, &link_path)?;\n\n Ok(link_path)\n }"}
{"repo":"fd","file":"tests/testenv/mod.rs","line":216,"symbol":"test_root","kind":"function","lang":"rust","doc":"Get the root directory for the tests.","code":"pub fn test_root(&self) -> PathBuf {\n self.temp_dir.path().to_path_buf()\n }"}
{"repo":"fd","file":"tests/testenv/mod.rs","line":222,"symbol":"test_exe","kind":"function","lang":"rust","doc":"Get the path of the fd executable.","code":"pub fn test_exe(&self) -> &PathBuf {\n &self.fd_exe\n }"}
{"repo":"fd","file":"tests/testenv/mod.rs","line":227,"symbol":"system_root","kind":"function","lang":"rust","doc":"Get the root directory of the file system.","code":"pub fn system_root(&self) -> PathBuf {\n let mut components = self.temp_dir.path().components();\n PathBuf::from(components.next().expect(\"root directory\").as_os_str())\n }"}
{"repo":"fd","file":"tests/testenv/mod.rs","line":234,"symbol":"assert_success_and_get_output","kind":"function","lang":"rust","doc":"Assert that calling *fd* in the specified path under the root working directory, and with the specified arguments produces the expected output.","code":"pub fn assert_success_and_get_output<P: AsRef<Path>>(\n &self,\n path: P,\n args: &[&str],\n ) -> process::Output {\n // Run *fd*.\n let output = self.run_command(path.as_ref(), args);\n\n // Check for exit status.\n if !output.status.success() {\n panic!(\"{}\", format_exit_error(args, &output));\n }\n\n output\n }"}
{"repo":"fd","file":"tests/testenv/mod.rs","line":250,"symbol":"assert_success_and_get_normalized_output","kind":"function","lang":"rust","code":"pub fn assert_success_and_get_normalized_output<P: AsRef<Path>>(\n &self,\n path: P,\n args: &[&str],\n ) -> String {\n let output = self.assert_success_and_get_output(path, args);\n normalize_output(\n &String::from_utf8_lossy(&output.stdout),\n false,\n self.normalize_line,\n )\n }"}
{"repo":"fd","file":"tests/testenv/mod.rs","line":264,"symbol":"assert_output","kind":"function","lang":"rust","doc":"Assert that calling *fd* with the specified arguments produces the expected output.","code":"pub fn assert_output(&self, args: &[&str], expected: &str) {\n self.assert_output_subdirectory(\".\", args, expected)\n }"}
{"repo":"fd","file":"tests/testenv/mod.rs","line":270,"symbol":"assert_output_raw","kind":"function","lang":"rust","doc":"Similar to assert_output, but able to handle non-utf8 output","code":"pub fn assert_output_raw(&self, args: &[&str], expected: &[u8]) {\n let output = self.assert_success_and_get_output(\".\", args);\n\n assert_eq!(expected, &output.stdout[..]);\n }"}
{"repo":"fd","file":"tests/testenv/mod.rs","line":278,"symbol":"assert_output_subdirectory","kind":"function","lang":"rust","doc":"Assert that calling *fd* in the specified path under the root working directory, and with the specified arguments produces the expected output.","code":"pub fn assert_output_subdirectory<P: AsRef<Path>>(\n &self,\n path: P,\n args: &[&str],\n expected: &str,\n ) {\n // Normalize both expected and actual output.\n let expected = normalize_output(expected, true, self.normalize_line);\n let actual = self.assert_success_and_get_normalized_output(path, args);\n\n // Compare actual output to expected output.\n if expected != actual {\n panic!(\"{}\", format_output_error(args, &expected, &actual));\n }\n }"}
{"repo":"fd","file":"tests/testenv/mod.rs","line":296,"symbol":"assert_failure_with_error","kind":"function","lang":"rust","doc":"Assert that calling *fd* with the specified arguments produces the expected error, and does not succeed.","code":"pub fn assert_failure_with_error(&self, args: &[&str], expected: &str) {\n let status = self.assert_error_subdirectory(\".\", args, Some(expected));\n if status.success() {\n panic!(\"error '{expected}' did not occur.\");\n }\n }"}
{"repo":"fd","file":"tests/testenv/mod.rs","line":304,"symbol":"assert_failure","kind":"function","lang":"rust","doc":"Assert that calling *fd* with the specified arguments does not succeed.","code":"pub fn assert_failure(&self, args: &[&str]) {\n let status = self.assert_error_subdirectory(\".\", args, None);\n if status.success() {\n panic!(\"Failure did not occur as expected.\");\n }\n }"}
{"repo":"fd","file":"tests/testenv/mod.rs","line":312,"symbol":"assert_error","kind":"function","lang":"rust","doc":"Assert that calling *fd* with the specified arguments produces the expected error.","code":"pub fn assert_error(&self, args: &[&str], expected: &str) -> process::ExitStatus {\n self.assert_error_subdirectory(\".\", args, Some(expected))\n }"}
{"repo":"fd","file":"tests/testenv/mod.rs","line":316,"symbol":"run_command","kind":"function","lang":"rust","code":"fn run_command(&self, path: &Path, args: &[&str]) -> process::Output {\n // Setup *fd* command.\n let mut cmd = process::Command::new(&self.fd_exe);\n cmd.current_dir(self.temp_dir.path().join(path));\n if let Some(config_dir) = &self.config_dir {\n cmd.env(\"XDG_CONFIG_HOME\", config_dir.path());\n } else {\n cmd.arg(\"--no-global-ignore-file\");\n }\n // Make sure LS_COLORS is unset to ensure consistent\n // color output\n cmd.env(\"LS_COLORS\", \"\");\n cmd.args(args);\n\n // Run *fd*.\n cmd.output().expect(\"fd output\")\n }"}
{"repo":"fd","file":"tests/testenv/mod.rs","line":336,"symbol":"assert_error_subdirectory","kind":"function","lang":"rust","doc":"Assert that calling *fd* in the specified path under the root working directory, and with the specified arguments produces an error with the expected message.","code":"fn assert_error_subdirectory<P: AsRef<Path>>(\n &self,\n path: P,\n args: &[&str],\n expected: Option<&str>,\n ) -> process::ExitStatus {\n let output = self.run_command(path.as_ref(), args);\n\n if let Some(expected) = expected {\n // Normalize both expected and actual output.\n let expected_error = trim_lines(expected);\n let actual_err = trim_lines(&String::from_utf8_lossy(&output.stderr));\n\n // Compare actual output to expected output.\n if !actual_err.trim_start().starts_with(&expected_error) {\n panic!(\n \"{}\",\n format_output_error(args, &expected_error, &actual_err)\n );\n }\n }\n\n output.status\n }"}
{"repo":"fd","file":"tests/tests.rs","line":32,"symbol":"get_absolute_root_path","kind":"function","lang":"rust","code":"fn get_absolute_root_path(env: &TestEnv) -> String {\n let path = env\n .test_root()\n .normalize()\n .expect(\"absolute path\")\n .as_path()\n .to_str()\n .expect(\"string\")\n .to_string();\n\n #[cfg(windows)]\n let path = path.trim_start_matches(r\"\\\\?\\\").to_string();\n\n path\n}"}
{"repo":"fd","file":"tests/tests.rs","line":49,"symbol":"get_test_env_with_abs_path","kind":"function","lang":"rust","code":"fn get_test_env_with_abs_path(dirs: &[&'static str], files: &[&'static str]) -> (TestEnv, String) {\n let env = TestEnv::new(dirs, files);\n let root_path = get_absolute_root_path(&env);\n (env, root_path)\n}"}
{"repo":"fd","file":"tests/tests.rs","line":56,"symbol":"create_file_with_size","kind":"function","lang":"rust","code":"fn create_file_with_size<P: AsRef<Path>>(path: P, size_in_bytes: usize) {\n let content = \"#\".repeat(size_in_bytes);\n let mut f = fs::File::create::<P>(path).unwrap();\n f.write_all(content.as_bytes()).unwrap();\n}"}
{"repo":"fd","file":"tests/tests.rs","line":64,"symbol":"test_simple","kind":"function","lang":"rust","doc":"Simple test","code":"fn test_simple() {\n let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n\n te.assert_output(&[\"a.foo\"], \"a.foo\");\n te.assert_output(&[\"b.foo\"], \"one/b.foo\");\n te.assert_output(&[\"d.foo\"], \"one/two/three/d.foo\");\n\n te.assert_output(\n &[\"foo\"],\n \"a.foo\n one/b.foo\n one/two/c.foo\n one/two/C.Foo2\n one/two/three/d.foo\n one/two/three/directory_foo/\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":104,"symbol":"test_and_basic","kind":"function","lang":"rust","doc":"AND test","code":"fn test_and_basic() {\n let te = TestEnv::new(DEFAULT_DIRS, AND_EXTRA_FILES);\n\n te.assert_output(\n &[\"foo\", \"--and\", \"c\"],\n \"one/two/C.Foo2\n one/two/c.foo\n one/two/three/directory_foo/\",\n );\n\n te.assert_output(\n &[\"f\", \"--and\", \"[ad]\", \"--and\", \"[_]\"],\n \"one/two/three/directory_foo/\",\n );\n\n te.assert_output(\n &[\"f\", \"--and\", \"[ad]\", \"--and\", \"[.]\"],\n \"a.foo\n one/two/three/d.foo\",\n );\n\n te.assert_output(&[\"Foo\", \"--and\", \"C\"], \"one/two/C.Foo2\");\n\n te.assert_output(&[\"foo\", \"--and\", \"asdasdasdsadasd\"], \"\");\n}"}
{"repo":"fd","file":"tests/tests.rs","line":131,"symbol":"test_and_empty_pattern","kind":"function","lang":"rust","code":"fn test_and_empty_pattern() {\n let te = TestEnv::new(DEFAULT_DIRS, AND_EXTRA_FILES);\n te.assert_output(&[\"Foo\", \"--and\", \"2\", \"--and\", \"\"], \"one/two/C.Foo2\");\n}"}
{"repo":"fd","file":"tests/tests.rs","line":137,"symbol":"test_and_bad_pattern","kind":"function","lang":"rust","code":"fn test_and_bad_pattern() {\n let te = TestEnv::new(DEFAULT_DIRS, AND_EXTRA_FILES);\n\n te.assert_failure(&[\"Foo\", \"--and\", \"2\", \"--and\", \"[\", \"--and\", \"C\"]);\n te.assert_failure(&[\"Foo\", \"--and\", \"[\", \"--and\", \"2\", \"--and\", \"C\"]);\n te.assert_failure(&[\"Foo\", \"--and\", \"2\", \"--and\", \"C\", \"--and\", \"[\"]);\n te.assert_failure(&[\"[\", \"--and\", \"2\", \"--and\", \"C\", \"--and\", \"Foo\"]);\n}"}
{"repo":"fd","file":"tests/tests.rs","line":147,"symbol":"test_and_pattern_starts_with_dash","kind":"function","lang":"rust","code":"fn test_and_pattern_starts_with_dash() {\n let te = TestEnv::new(DEFAULT_DIRS, AND_EXTRA_FILES);\n\n te.assert_output(\n &[\"baz\", \"--and\", \"quux\"],\n \"one/two/three/Baz-Quux2\n one/two/three/baz-quux\",\n );\n te.assert_output(\n &[\"baz\", \"--and\", \"-\"],\n \"one/two/three/Baz-Quux2\n one/two/three/baz-quux\",\n );\n te.assert_output(\n &[\"Quu\", \"--and\", \"x\", \"--and\", \"-\"],\n \"one/two/three/Baz-Quux2\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":167,"symbol":"test_and_plus_extension","kind":"function","lang":"rust","code":"fn test_and_plus_extension() {\n let te = TestEnv::new(DEFAULT_DIRS, AND_EXTRA_FILES);\n\n te.assert_output(\n &[\n \"A\",\n \"--and\",\n \"B\",\n \"--extension\",\n \"jpg\",\n \"--extension\",\n \"png\",\n ],\n \"A-B.jpg\n B-A.png\",\n );\n\n te.assert_output(\n &[\n \"A\",\n \"--extension\",\n \"jpg\",\n \"--and\",\n \"B\",\n \"--extension\",\n \"png\",\n ],\n \"A-B.jpg\n B-A.png\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":200,"symbol":"test_and_plus_type","kind":"function","lang":"rust","code":"fn test_and_plus_type() {\n let te = TestEnv::new(DEFAULT_DIRS, AND_EXTRA_FILES);\n\n te.assert_output(\n &[\"c\", \"--type\", \"d\", \"--and\", \"foo\"],\n \"one/two/three/directory_foo/\",\n );\n\n te.assert_output(\n &[\"c\", \"--type\", \"f\", \"--and\", \"foo\"],\n \"one/two/C.Foo2\n one/two/c.foo\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":216,"symbol":"test_and_plus_glob","kind":"function","lang":"rust","code":"fn test_and_plus_glob() {\n let te = TestEnv::new(DEFAULT_DIRS, AND_EXTRA_FILES);\n\n te.assert_output(&[\"*foo\", \"--glob\", \"--and\", \"c*\"], \"one/two/c.foo\");\n}"}
{"repo":"fd","file":"tests/tests.rs","line":223,"symbol":"test_and_plus_fixed_strings","kind":"function","lang":"rust","code":"fn test_and_plus_fixed_strings() {\n let te = TestEnv::new(DEFAULT_DIRS, AND_EXTRA_FILES);\n\n te.assert_output(\n &[\"foo\", \"--fixed-strings\", \"--and\", \"c\", \"--and\", \".\"],\n \"one/two/c.foo\n one/two/C.Foo2\",\n );\n\n te.assert_output(\n &[\"foo\", \"--fixed-strings\", \"--and\", \"[c]\", \"--and\", \".\"],\n \"\",\n );\n\n te.assert_output(\n &[\"Foo\", \"--fixed-strings\", \"--and\", \"C\", \"--and\", \".\"],\n \"one/two/C.Foo2\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":244,"symbol":"test_and_plus_ignore_case","kind":"function","lang":"rust","code":"fn test_and_plus_ignore_case() {\n let te = TestEnv::new(DEFAULT_DIRS, AND_EXTRA_FILES);\n\n te.assert_output(\n &[\"Foo\", \"--ignore-case\", \"--and\", \"C\", \"--and\", \"[.]\"],\n \"one/two/C.Foo2\n one/two/c.foo\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":255,"symbol":"test_and_plus_case_sensitive","kind":"function","lang":"rust","code":"fn test_and_plus_case_sensitive() {\n let te = TestEnv::new(DEFAULT_DIRS, AND_EXTRA_FILES);\n\n te.assert_output(\n &[\"foo\", \"--case-sensitive\", \"--and\", \"c\", \"--and\", \"[.]\"],\n \"one/two/c.foo\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":265,"symbol":"test_and_plus_full_path","kind":"function","lang":"rust","code":"fn test_and_plus_full_path() {\n let te = TestEnv::new(DEFAULT_DIRS, AND_EXTRA_FILES);\n\n te.assert_output(\n &[\n \"three\",\n \"--full-path\",\n \"--and\",\n \"_foo\",\n \"--and\",\n r\"[/\\\\]dir\",\n ],\n \"one/two/three/directory_foo/\",\n );\n\n te.assert_output(\n &[\n \"three\",\n \"--full-path\",\n \"--and\",\n r\"[/\\\\]two\",\n \"--and\",\n r\"[/\\\\]dir\",\n ],\n \"one/two/three/directory_foo/\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":295,"symbol":"test_empty_pattern","kind":"function","lang":"rust","doc":"Test each pattern type with an empty pattern.","code":"fn test_empty_pattern() {\n let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n let expected = \"a.foo\n e1 e2\n one/\n one/b.foo\n one/two/\n one/two/c.foo\n one/two/C.Foo2\n one/two/three/\n one/two/three/d.foo\n one/two/three/directory_foo/\n symlink\";\n\n te.assert_output(&[\"--regex\"], expected);\n te.assert_output(&[\"--fixed-strings\"], expected);\n te.assert_output(&[\"--glob\"], expected);\n}"}
{"repo":"fd","file":"tests/tests.rs","line":316,"symbol":"test_multi_file","kind":"function","lang":"rust","doc":"Test multiple directory searches","code":"fn test_multi_file() {\n let dirs = &[\"test1\", \"test2\"];\n let files = &[\"test1/a.foo\", \"test1/b.foo\", \"test2/a.foo\"];\n let te = TestEnv::new(dirs, files);\n te.assert_output(\n &[\"a.foo\", \"test1\", \"test2\"],\n \"test1/a.foo\n test2/a.foo\",\n );\n\n te.assert_output(\n &[\"\", \"test1\", \"test2\"],\n \"test1/a.foo\n test2/a.foo\n test1/b.foo\",\n );\n\n te.assert_output(&[\"a.foo\", \"test1\"], \"test1/a.foo\");\n\n te.assert_output(&[\"b.foo\", \"test1\", \"test2\"], \"test1/b.foo\");\n}"}
{"repo":"fd","file":"tests/tests.rs","line":340,"symbol":"test_multi_file_with_missing","kind":"function","lang":"rust","doc":"Test search over multiple directory with missing","code":"fn test_multi_file_with_missing() {\n let dirs = &[\"real\"];\n let files = &[\"real/a.foo\", \"real/b.foo\"];\n let te = TestEnv::new(dirs, files);\n te.assert_output(&[\"a.foo\", \"real\", \"fake\"], \"real/a.foo\");\n\n te.assert_error(\n &[\"a.foo\", \"real\", \"fake\"],\n \"[fd error]: Search path \\\"fake\\\" is not a directory.\",\n );\n\n te.assert_output(\n &[\"\", \"real\", \"fake\"],\n \"real/a.foo\n real/b.foo\",\n );\n\n te.assert_output(\n &[\"\", \"real\", \"fake1\", \"fake2\"],\n \"real/a.foo\n real/b.foo\",\n );\n\n te.assert_error(\n &[\"\", \"real\", \"fake1\", \"fake2\"],\n \"[fd error]: Search path \\\"fake1\\\" is not a directory.\n [fd error]: Search path \\\"fake2\\\" is not a directory.\",\n );\n\n te.assert_failure_with_error(\n &[\"\", \"fake1\", \"fake2\"],\n \"[fd error]: Search path \\\"fake1\\\" is not a directory.\n [fd error]: Search path \\\"fake2\\\" is not a directory.\n [fd error]: No valid search paths given.\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":383,"symbol":"test_pattern_with_forward_slash_is_rejected","kind":"function","lang":"rust","doc":"Without --full-path, a pattern containing '/' should always produce the path-separator diagnostic, even if the pattern does not name an existing directory. Before the fix for sharkdp/fd#1873 this only fired when the pattern happened to resolve to a real directory, so the common typo of pasting a full path silently returned zero matches.","code":"fn test_pattern_with_forward_slash_is_rejected() {\n let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n\n // Pattern that is NOT a real directory; old behaviour: no warning.\n te.assert_failure_with_error(\n &[\"nonexistent/path\"],\n \"[fd error]: The search pattern 'nonexistent/path' contains a path-separation character and will not lead to any search results.\",\n );\n\n // Pattern that IS a real directory; old behaviour: warning. Must still fire.\n te.assert_failure_with_error(\n &[\"one/two/three\"],\n \"[fd error]: The search pattern 'one/two/three' contains a path-separation character and will not lead to any search results.\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":410,"symbol":"test_pattern_with_forward_slash_allowed_with_full_path","kind":"function","lang":"rust","doc":"Gated off Windows: the actual match is regex-over-the-full-path, so a forward-slash pattern only matches Unix-style paths. On Windows the OS uses `\\` and `one/two/c` (as a literal regex) does not match a real entry — the behaviour this test is pinning (the diagnostic does not fire) is covered by the fact that the invocation does not error.","code":"fn test_pattern_with_forward_slash_allowed_with_full_path() {\n let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n\n te.assert_output(\n &[\"--full-path\", \"one/two/c\"],\n \"one/two/c.foo\n one/two/C.Foo2\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":425,"symbol":"test_and_pattern_with_forward_slash_is_rejected","kind":"function","lang":"rust","doc":"`--and` patterns are matched against the file name exactly like the primary pattern, so a path separator in any of them is the same silent \"no results\" footgun and must trigger the same diagnostic. Regression for the sibling of #1873 left unchecked by #1975 (only the positional pattern was validated).","code":"fn test_and_pattern_with_forward_slash_is_rejected() {\n let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n\n // Clean primary pattern, but a `--and` pattern carrying a path separator.\n te.assert_failure_with_error(\n &[\"foo\", \"--and\", \"nonexistent/path\"],\n \"[fd error]: The search pattern 'nonexistent/path' contains a path-separation character and will not lead to any search results.\",\n );\n\n // `--full-path` is the explicit opt-in and must still suppress the\n // diagnostic for `--and` patterns too (the invocation runs and matches\n // instead of erroring on the path separator).\n #[cfg(not(windows))]\n te.assert_output(\n &[\"--full-path\", \"one/two/c\", \"--and\", \"two/c\"],\n \"one/two/c.foo\n one/two/C.Foo2\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":447,"symbol":"test_explicit_root_path","kind":"function","lang":"rust","doc":"Explicit root path","code":"fn test_explicit_root_path() {\n let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n\n te.assert_output(\n &[\"foo\", \"one\"],\n \"one/b.foo\n one/two/c.foo\n one/two/C.Foo2\n one/two/three/d.foo\n one/two/three/directory_foo/\",\n );\n\n te.assert_output(\n &[\"foo\", \"one/two/three\"],\n \"one/two/three/d.foo\n one/two/three/directory_foo/\",\n );\n\n te.assert_output_subdirectory(\n \"one/two/\",\n &[\"foo\", \"../../\"],\n \"../../a.foo\n ../../one/b.foo\n ../../one/two/c.foo\n ../../one/two/C.Foo2\n ../../one/two/three/d.foo\n ../../one/two/three/directory_foo/\",\n );\n\n te.assert_output_subdirectory(\n \"one/two/three\",\n &[\"\", \"..\"],\n \"../c.foo\n ../C.Foo2\n ../three/\n ../three/d.foo\n ../three/directory_foo/\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":488,"symbol":"test_single_dash_root_path","kind":"function","lang":"rust","code":"fn test_single_dash_root_path() {\n let te = TestEnv::new(&[\"-\"], &[\"-/foo\"]);\n\n te.assert_output(&[\".\", \"-\"], \"./-/foo\");\n}"}
{"repo":"fd","file":"tests/tests.rs","line":496,"symbol":"test_regex_searches","kind":"function","lang":"rust","doc":"Regex searches","code":"fn test_regex_searches() {\n let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n\n te.assert_output(\n &[\"[a-c].foo\"],\n \"a.foo\n one/b.foo\n one/two/c.foo\n one/two/C.Foo2\",\n );\n\n te.assert_output(\n &[\"--case-sensitive\", \"[a-c].foo\"],\n \"a.foo\n one/b.foo\n one/two/c.foo\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":517,"symbol":"test_smart_case","kind":"function","lang":"rust","doc":"Smart case","code":"fn test_smart_case() {\n let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n\n te.assert_output(\n &[\"c.foo\"],\n \"one/two/c.foo\n one/two/C.Foo2\",\n );\n\n te.assert_output(&[\"C.Foo\"], \"one/two/C.Foo2\");\n\n te.assert_output(&[\"Foo\"], \"one/two/C.Foo2\");\n\n // Only literal uppercase chars should trigger case sensitivity.\n te.assert_output(\n &[\"\\\\Ac\"],\n \"one/two/c.foo\n one/two/C.Foo2\",\n );\n te.assert_output(&[\"\\\\AC\"], \"one/two/C.Foo2\");\n}"}
{"repo":"fd","file":"tests/tests.rs","line":541,"symbol":"test_case_sensitive","kind":"function","lang":"rust","doc":"Case sensitivity (--case-sensitive)","code":"fn test_case_sensitive() {\n let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n\n te.assert_output(&[\"--case-sensitive\", \"c.foo\"], \"one/two/c.foo\");\n\n te.assert_output(&[\"--case-sensitive\", \"C.Foo\"], \"one/two/C.Foo2\");\n\n te.assert_output(\n &[\"--ignore-case\", \"--case-sensitive\", \"C.Foo\"],\n \"one/two/C.Foo2\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":556,"symbol":"test_case_insensitive","kind":"function","lang":"rust","doc":"Case insensitivity (--ignore-case)","code":"fn test_case_insensitive() {\n let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n\n te.assert_output(\n &[\"--ignore-case\", \"C.Foo\"],\n \"one/two/c.foo\n one/two/C.Foo2\",\n );\n\n te.assert_output(\n &[\"--case-sensitive\", \"--ignore-case\", \"C.Foo\"],\n \"one/two/c.foo\n one/two/C.Foo2\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":574,"symbol":"test_glob_searches","kind":"function","lang":"rust","doc":"Glob-based searches (--glob)","code":"fn test_glob_searches() {\n let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n\n te.assert_output(\n &[\"--glob\", \"*.foo\"],\n \"a.foo\n one/b.foo\n one/two/c.foo\n one/two/three/d.foo\",\n );\n\n te.assert_output(\n &[\"--glob\", \"[a-c].foo\"],\n \"a.foo\n one/b.foo\n one/two/c.foo\",\n );\n\n te.assert_output(\n &[\"--glob\", \"[a-c].foo*\"],\n \"a.foo\n one/b.foo\n one/two/C.Foo2\n one/two/c.foo\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":604,"symbol":"test_full_path_glob_searches","kind":"function","lang":"rust","doc":"Glob-based searches (--glob) in combination with full path searches (--full-path)","code":"fn test_full_path_glob_searches() {\n let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n\n te.assert_output(\n &[\"--glob\", \"--full-path\", \"**/one/**/*.foo\"],\n \"one/b.foo\n one/two/c.foo\n one/two/three/d.foo\",\n );\n\n te.assert_output(\n &[\"--glob\", \"--full-path\", \"**/one/*/*.foo\"],\n \" one/two/c.foo\",\n );\n\n te.assert_output(\n &[\"--glob\", \"--full-path\", \"**/one/*/*/*.foo\"],\n \" one/two/three/d.foo\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":626,"symbol":"test_smart_case_glob_searches","kind":"function","lang":"rust","code":"fn test_smart_case_glob_searches() {\n let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n\n te.assert_output(\n &[\"--glob\", \"c.foo*\"],\n \"one/two/C.Foo2\n one/two/c.foo\",\n );\n\n te.assert_output(&[\"--glob\", \"C.Foo*\"], \"one/two/C.Foo2\");\n}"}
{"repo":"fd","file":"tests/tests.rs","line":640,"symbol":"test_case_sensitive_glob_searches","kind":"function","lang":"rust","doc":"Glob-based searches (--glob) in combination with --case-sensitive","code":"fn test_case_sensitive_glob_searches() {\n let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n\n te.assert_output(&[\"--glob\", \"--case-sensitive\", \"c.foo*\"], \"one/two/c.foo\");\n}"}
{"repo":"fd","file":"tests/tests.rs","line":648,"symbol":"test_glob_searches_with_extension","kind":"function","lang":"rust","doc":"Glob-based searches (--glob) in combination with --extension","code":"fn test_glob_searches_with_extension() {\n let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n\n te.assert_output(\n &[\"--glob\", \"--extension\", \"foo2\", \"[a-z].*\"],\n \"one/two/C.Foo2\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":659,"symbol":"test_regex_overrides_glob","kind":"function","lang":"rust","doc":"Make sure that --regex overrides --glob","code":"fn test_regex_overrides_glob() {\n let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n\n te.assert_output(&[\"--glob\", \"--regex\", \"Foo2$\"], \"one/two/C.Foo2\");\n}"}
{"repo":"fd","file":"tests/tests.rs","line":667,"symbol":"test_full_path","kind":"function","lang":"rust","doc":"Full path search (--full-path)","code":"fn test_full_path() {\n let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n\n let root = te.system_root();\n let prefix = escape(&root.to_string_lossy());\n\n te.assert_output(\n &[\"--full-path\", &format!(\"^{prefix}.*three.*foo$\")],\n \"one/two/three/d.foo\n one/two/three/directory_foo/\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":682,"symbol":"test_hidden","kind":"function","lang":"rust","doc":"Hidden files (--hidden)","code":"fn test_hidden() {\n let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n\n te.assert_output(\n &[\"--hidden\", \"foo\"],\n \".hidden.foo\n a.foo\n one/b.foo\n one/two/c.foo\n one/two/C.Foo2\n one/two/three/d.foo\n one/two/three/directory_foo/\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":700,"symbol":"test_hidden_file_attribute","kind":"function","lang":"rust","doc":"Hidden file attribute on Windows","code":"fn test_hidden_file_attribute() {\n use std::os::windows::fs::OpenOptionsExt;\n\n let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n\n // https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-setfileattributesa\n const FILE_ATTRIBUTE_HIDDEN: u32 = 2;\n\n fs::OpenOptions::new()\n .create(true)\n .write(true)\n .attributes(FILE_ATTRIBUTE_HIDDEN)\n .open(te.test_root().join(\"hidden-file.txt\"))\n .unwrap();\n\n te.assert_output(&[\"--hidden\", \"hidden-file.txt\"], \"hidden-file.txt\");\n te.assert_output(&[\"hidden-file.txt\"], \"\");\n}"}
{"repo":"fd","file":"tests/tests.rs","line":721,"symbol":"test_no_ignore","kind":"function","lang":"rust","doc":"Ignored files (--no-ignore)","code":"fn test_no_ignore() {\n let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n\n te.assert_output(\n &[\"--no-ignore\", \"foo\"],\n \"a.foo\n fdignored.foo\n gitignored.foo\n one/b.foo\n one/two/c.foo\n one/two/C.Foo2\n one/two/three/d.foo\n one/two/three/directory_foo/\",\n );\n\n te.assert_output(\n &[\"--hidden\", \"--no-ignore\", \"foo\"],\n \".hidden.foo\n a.foo\n fdignored.foo\n gitignored.foo\n one/b.foo\n one/two/c.foo\n one/two/C.Foo2\n one/two/three/d.foo\n one/two/three/directory_foo/\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":752,"symbol":"test_gitignore_and_fdignore","kind":"function","lang":"rust","doc":".gitignore and .fdignore","code":"fn test_gitignore_and_fdignore() {\n let files = &[\n \"ignored-by-nothing\",\n \"ignored-by-fdignore\",\n \"ignored-by-gitignore\",\n \"ignored-by-both\",\n ];\n let te = TestEnv::new(&[], files);\n\n fs::File::create(te.test_root().join(\".fdignore\"))\n .unwrap()\n .write_all(b\"ignored-by-fdignore\\nignored-by-both\")\n .unwrap();\n\n fs::File::create(te.test_root().join(\".gitignore\"))\n .unwrap()\n .write_all(b\"ignored-by-gitignore\\nignored-by-both\")\n .unwrap();\n\n te.assert_output(&[\"ignored\"], \"ignored-by-nothing\");\n\n te.assert_output(\n &[\"--no-ignore-vcs\", \"ignored\"],\n \"ignored-by-nothing\n ignored-by-gitignore\",\n );\n\n te.assert_output(\n &[\"--no-ignore\", \"ignored\"],\n \"ignored-by-nothing\n ignored-by-fdignore\n ignored-by-gitignore\n ignored-by-both\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":790,"symbol":"test_no_ignore_parent","kind":"function","lang":"rust","doc":"Ignore parent ignore files (--no-ignore-parent)","code":"fn test_no_ignore_parent() {\n let dirs = &[\"inner\"];\n let files = &[\n \"inner/parent-ignored\",\n \"inner/child-ignored\",\n \"inner/not-ignored\",\n ];\n let te = TestEnv::new(dirs, files);\n\n // Ignore 'parent-ignored' in root\n fs::File::create(te.test_root().join(\".gitignore\"))\n .unwrap()\n .write_all(b\"parent-ignored\")\n .unwrap();\n // Ignore 'child-ignored' in inner\n fs::File::create(te.test_root().join(\"inner/.gitignore\"))\n .unwrap()\n .write_all(b\"child-ignored\")\n .unwrap();\n\n te.assert_output_subdirectory(\"inner\", &[], \"not-ignored\");\n\n te.assert_output_subdirectory(\n \"inner\",\n &[\"--no-ignore-parent\"],\n \"parent-ignored\n not-ignored\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":822,"symbol":"test_no_ignore_parent_inner_git","kind":"function","lang":"rust","doc":"Ignore parent ignore files (--no-ignore-parent) with an inner git repo","code":"fn test_no_ignore_parent_inner_git() {\n let dirs = &[\"inner\"];\n let files = &[\n \"inner/parent-ignored\",\n \"inner/child-ignored\",\n \"inner/not-ignored\",\n ];\n let te = TestEnv::new(dirs, files);\n\n // Make the inner folder also appear as a git repo\n fs::create_dir_all(te.test_root().join(\"inner/.git\")).unwrap();\n\n // Ignore 'parent-ignored' in root\n fs::File::create(te.test_root().join(\".gitignore\"))\n .unwrap()\n .write_all(b\"parent-ignored\")\n .unwrap();\n // Ignore 'child-ignored' in inner\n fs::File::create(te.test_root().join(\"inner/.gitignore\"))\n .unwrap()\n .write_all(b\"child-ignored\")\n .unwrap();\n\n te.assert_output_subdirectory(\n \"inner\",\n &[],\n \"not-ignored\n parent-ignored\",\n );\n\n te.assert_output_subdirectory(\n \"inner\",\n &[\"--no-ignore-parent\"],\n \"not-ignored\n parent-ignored\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":862,"symbol":"test_custom_ignore_precedence","kind":"function","lang":"rust","doc":"Precedence of .fdignore files","code":"fn test_custom_ignore_precedence() {\n let dirs = &[\"inner\"];\n let files = &[\"inner/foo\"];\n let te = TestEnv::new(dirs, files);\n\n // Ignore 'foo' via .gitignore\n fs::File::create(te.test_root().join(\"inner/.gitignore\"))\n .unwrap()\n .write_all(b\"foo\")\n .unwrap();\n\n // Whitelist 'foo' via .fdignore\n fs::File::create(te.test_root().join(\".fdignore\"))\n .unwrap()\n .write_all(b\"!foo\")\n .unwrap();\n\n te.assert_output(&[\"foo\"], \"inner/foo\");\n\n te.assert_output(&[\"--no-ignore-vcs\", \"foo\"], \"inner/foo\");\n\n te.assert_output(&[\"--no-ignore\", \"foo\"], \"inner/foo\");\n}"}
{"repo":"fd","file":"tests/tests.rs","line":888,"symbol":"test_respect_ignore_files","kind":"function","lang":"rust","doc":"Don't require git to respect gitignore (--no-require-git)","code":"fn test_respect_ignore_files() {\n let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n\n // Not in a git repo anymore\n fs::remove_dir(te.test_root().join(\".git\")).unwrap();\n\n // don't respect gitignore because we're not in a git repo\n te.assert_output(\n &[\"foo\"],\n \"a.foo\n gitignored.foo\n one/b.foo\n one/two/c.foo\n one/two/C.Foo2\n one/two/three/d.foo\n one/two/three/directory_foo/\",\n );\n\n // respect gitignore because we set `--no-require-git`\n te.assert_output(\n &[\"--no-require-git\", \"foo\"],\n \"a.foo\n one/b.foo\n one/two/c.foo\n one/two/C.Foo2\n one/two/three/d.foo\n one/two/three/directory_foo/\",\n );\n\n // make sure overriding works\n te.assert_output(\n &[\"--no-require-git\", \"--require-git\", \"foo\"],\n \"a.foo\n gitignored.foo\n one/b.foo\n one/two/c.foo\n one/two/C.Foo2\n one/two/three/d.foo\n one/two/three/directory_foo/\",\n );\n\n te.assert_output(\n &[\"--no-require-git\", \"--no-ignore\", \"foo\"],\n \"a.foo\n gitignored.foo\n fdignored.foo\n one/b.foo\n one/two/c.foo\n "}
{"repo":"fd","file":"tests/tests.rs","line":944,"symbol":"test_no_ignore_vcs","kind":"function","lang":"rust","doc":"VCS ignored files (--no-ignore-vcs)","code":"fn test_no_ignore_vcs() {\n let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n\n te.assert_output(\n &[\"--no-ignore-vcs\", \"foo\"],\n \"a.foo\n gitignored.foo\n one/b.foo\n one/two/c.foo\n one/two/C.Foo2\n one/two/three/d.foo\n one/two/three/directory_foo/\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":961,"symbol":"test_no_ignore_vcs_child_dir","kind":"function","lang":"rust","doc":"Test that --no-ignore-vcs still respects .fdignored in parent directory","code":"fn test_no_ignore_vcs_child_dir() {\n let te = TestEnv::new(\n &[\"inner\"],\n &[\"inner/fdignored.foo\", \"inner/foo\", \"inner/gitignored.foo\"],\n );\n\n te.assert_output_subdirectory(\n \"inner\",\n &[\"--no-ignore-vcs\", \"foo\"],\n \"foo\n gitignored.foo\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":977,"symbol":"test_custom_ignore_files","kind":"function","lang":"rust","doc":"Custom ignore files (--ignore-file)","code":"fn test_custom_ignore_files() {\n let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n\n // Ignore 'C.Foo2' and everything in 'three'.\n fs::File::create(te.test_root().join(\"custom.ignore\"))\n .unwrap()\n .write_all(b\"C.Foo2\\nthree\")\n .unwrap();\n\n te.assert_output(\n &[\"--ignore-file\", \"custom.ignore\", \"foo\"],\n \"a.foo\n one/b.foo\n one/two/c.foo\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":996,"symbol":"test_no_ignore_aliases","kind":"function","lang":"rust","doc":"Ignored files with ripgrep aliases (-u / -uu)","code":"fn test_no_ignore_aliases() {\n let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n\n te.assert_output(\n &[\"-u\", \"foo\"],\n \".hidden.foo\n a.foo\n fdignored.foo\n gitignored.foo\n one/b.foo\n one/two/c.foo\n one/two/C.Foo2\n one/two/three/d.foo\n one/two/three/directory_foo/\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":1015,"symbol":"test_global_ignore","kind":"function","lang":"rust","code":"fn test_global_ignore() {\n let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES).global_ignore_file(\"one\");\n te.assert_output(\n &[],\n \"a.foo\n e1 e2\n symlink\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":1049,"symbol":"test_no_global_ignore","kind":"function","lang":"rust","code":"fn test_no_global_ignore(flag: &str, expected_output: &str) {\n let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES).global_ignore_file(\"one\");\n te.assert_output(&[flag, \"foo\"], expected_output);\n}"}
{"repo":"fd","file":"tests/tests.rs","line":1056,"symbol":"test_follow","kind":"function","lang":"rust","doc":"Symlinks (--follow)","code":"fn test_follow() {\n let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n\n te.assert_output(\n &[\"--follow\", \"c.foo\"],\n \"one/two/c.foo\n one/two/C.Foo2\n symlink/c.foo\n symlink/C.Foo2\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":1074,"symbol":"test_file_system_boundaries","kind":"function","lang":"rust","doc":"File system boundaries (--one-file-system) Limited to Unix because, to the best of my knowledge, there is no easy way to test a use case file systems mounted into the tree on Windows. Not limiting depth causes massive delay under Darwin, see BurntSushi/ripgrep#1429","code":"fn test_file_system_boundaries() {\n // Helper function to get the device ID for a given path\n // Inspired by https://github.com/BurntSushi/ripgrep/blob/8892bf648cfec111e6e7ddd9f30e932b0371db68/ignore/src/walk.rs#L1693\n fn device_num(path: impl AsRef<Path>) -> u64 {\n use std::os::unix::fs::MetadataExt;\n\n path.as_ref().metadata().map(|md| md.dev()).unwrap()\n }\n\n // Can't simulate file system boundaries\n let te = TestEnv::new(&[], &[]);\n\n let dev_null = Path::new(\"/dev/null\");\n\n // /dev/null should exist in all sane Unixes. Skip if it doesn't exist for some reason.\n // Also skip should it be on the same device as the root partition for some reason.\n if !dev_null.is_file() || device_num(dev_null) == device_num(\"/\") {\n return;\n }\n\n te.assert_output(\n &[\"--full-path\", \"--max-depth\", \"2\", \"^/dev/null$\", \"/\"],\n \"/dev/null\",\n );\n te.assert_output(\n &[\n \"--one-file-system\",\n \"--full-path\",\n \"--max-depth\",\n \"2\",\n \"^/dev/null$\",\n \"/\",\n ],\n \"\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":1077,"symbol":"device_num","kind":"function","lang":"rust","doc":"Helper function to get the device ID for a given path Inspired by https://github.com/BurntSushi/ripgrep/blob/8892bf648cfec111e6e7ddd9f30e932b0371db68/ignore/src/walk.rs#L1693","code":"fn device_num(path: impl AsRef<Path>) -> u64 {\n use std::os::unix::fs::MetadataExt;\n\n path.as_ref().metadata().map(|md| md.dev()).unwrap()\n }"}
{"repo":"fd","file":"tests/tests.rs","line":1112,"symbol":"test_follow_broken_symlink","kind":"function","lang":"rust","code":"fn test_follow_broken_symlink() {\n let mut te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n te.create_broken_symlink(\"broken_symlink\")\n .expect(\"Failed to create broken symlink.\");\n\n te.assert_output(\n &[\"symlink\"],\n \"broken_symlink\n symlink\",\n );\n te.assert_output(\n &[\"--type\", \"symlink\", \"symlink\"],\n \"broken_symlink\n symlink\",\n );\n\n te.assert_output(&[\"--type\", \"file\", \"symlink\"], \"\");\n\n te.assert_output(\n &[\"--follow\", \"--type\", \"symlink\", \"symlink\"],\n \"broken_symlink\",\n );\n te.assert_output(&[\"--follow\", \"--type\", \"file\", \"symlink\"], \"\");\n}"}
{"repo":"fd","file":"tests/tests.rs","line":1139,"symbol":"test_print0","kind":"function","lang":"rust","doc":"Null separator (--print0)","code":"fn test_print0() {\n let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n\n te.assert_output(\n &[\"--print0\", \"foo\"],\n \"./a.fooNULL\n ./one/b.fooNULL\n ./one/two/C.Foo2NULL\n ./one/two/c.fooNULL\n ./one/two/three/d.fooNULL\n ./one/two/three/directory_foo/NULL\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":1155,"symbol":"test_max_depth","kind":"function","lang":"rust","doc":"Maximum depth (--max-depth)","code":"fn test_max_depth() {\n let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n\n te.assert_output(\n &[\"--max-depth\", \"3\"],\n \"a.foo\n e1 e2\n one/\n one/b.foo\n one/two/\n one/two/c.foo\n one/two/C.Foo2\n one/two/three/\n symlink\",\n );\n\n te.assert_output(\n &[\"--max-depth\", \"2\"],\n \"a.foo\n e1 e2\n one/\n one/b.foo\n one/two/\n symlink\",\n );\n\n te.assert_output(\n &[\"--max-depth\", \"1\"],\n \"a.foo\n e1 e2\n one/\n symlink\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":1192,"symbol":"test_min_depth","kind":"function","lang":"rust","doc":"Minimum depth (--min-depth)","code":"fn test_min_depth() {\n let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n\n te.assert_output(\n &[\"--min-depth\", \"3\"],\n \"one/two/c.foo\n one/two/C.Foo2\n one/two/three/\n one/two/three/d.foo\n one/two/three/directory_foo/\",\n );\n\n te.assert_output(\n &[\"--min-depth\", \"4\"],\n \"one/two/three/d.foo\n one/two/three/directory_foo/\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":1216,"symbol":"test_min_depth_broken_symlink","kind":"function","lang":"rust","doc":"Minimum depth with a broken symlink (regression test for #1017) A broken symlink, surfaced while following links, has no depth reported by the walker, so --min-depth used to drop it unconditionally.","code":"fn test_min_depth_broken_symlink() {\n let mut te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n te.create_broken_symlink(\"one/two/broken_symlink\")\n .expect(\"Failed to create broken symlink.\");\n\n // The broken symlink sits at depth 3, so it is kept up to that depth.\n te.assert_output(\n &[\n \"--follow\",\n \"--type\",\n \"symlink\",\n \"--min-depth\",\n \"3\",\n \"broken_symlink\",\n ],\n \"one/two/broken_symlink\",\n );\n\n // A --min-depth beyond its actual depth must exclude it.\n te.assert_output(\n &[\n \"--follow\",\n \"--type\",\n \"symlink\",\n \"--min-depth\",\n \"4\",\n \"broken_symlink\",\n ],\n \"\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":1254,"symbol":"test_min_depth_broken_symlink_absolute_path","kind":"function","lang":"rust","doc":"Minimum depth with a broken symlink combined with --absolute-path (#1017) With --absolute-path the search root is made absolute before walking, so the broken symlink's depth must still be computed relative to that root rather than from the absolute path's full component count.","code":"fn test_min_depth_broken_symlink_absolute_path() {\n let (mut te, abs_path) = get_test_env_with_abs_path(DEFAULT_DIRS, DEFAULT_FILES);\n te.create_broken_symlink(\"one/two/broken_symlink\")\n .expect(\"Failed to create broken symlink.\");\n\n // The broken symlink sits at depth 3 relative to the (absolute) root.\n te.assert_output(\n &[\n \"--follow\",\n \"--absolute-path\",\n \"--type\",\n \"symlink\",\n \"--min-depth\",\n \"3\",\n \"broken_symlink\",\n ],\n &format!(\"{abs_path}/one/two/broken_symlink\"),\n );\n\n // A --min-depth beyond its actual depth must exclude it.\n te.assert_output(\n &[\n \"--follow\",\n \"--absolute-path\",\n \"--type\",\n \"symlink\",\n \"--min-depth\",\n \"4\",\n \"broken_symlink\",\n ],\n \"\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":1297,"symbol":"test_min_depth_broken_symlink_overlapping_roots","kind":"function","lang":"rust","doc":"When two search roots overlap, the walker visits the same broken symlink once per root, at a different depth each time. Here `one/two/broken_symlink` is at depth 2 under root `one` and at depth 1 under root `one/two`, so --min-depth 2 must keep the entry the walker reached via `one` and drop the one it reached via `one/two`. A depth derived from the entry's path cannot distinguish the two visits, since both carry the same path.","code":"fn test_min_depth_broken_symlink_overlapping_roots() {\n let mut te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n te.create_broken_symlink(\"one/two/broken_symlink\")\n .expect(\"Failed to create broken symlink.\");\n\n // Only the route through `one` reaches depth 2.\n te.assert_output(\n &[\n \"--follow\",\n \"--type\",\n \"symlink\",\n \"--min-depth\",\n \"2\",\n \"broken_symlink\",\n \"one\",\n \"one/two\",\n ],\n \"one/two/broken_symlink\",\n );\n\n // Both routes clear --min-depth 1, so it is reported once per root.\n te.assert_output(\n &[\n \"--follow\",\n \"--type\",\n \"symlink\",\n \"--min-depth\",\n \"1\",\n \"broken_symlink\",\n \"one\",\n \"one/two\",\n ],\n \"one/two/broken_symlink\n one/two/broken_symlink\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":1340,"symbol":"test_max_depth_broken_symlink","kind":"function","lang":"rust","doc":"Maximum depth with a broken symlink (#1017) A broken symlink must be filtered by --max-depth like any other entry. The default environment also exposes it through the followed `symlink` directory (`symlink -> one/two`), so it is reachable at depth 2 as well as depth 3.","code":"fn test_max_depth_broken_symlink() {\n let mut te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n te.create_broken_symlink(\"one/two/broken_symlink\")\n .expect(\"Failed to create broken symlink.\");\n\n // --max-depth 3 keeps both routes to the broken symlink.\n te.assert_output(\n &[\n \"--follow\",\n \"--type\",\n \"symlink\",\n \"--max-depth\",\n \"3\",\n \"broken_symlink\",\n ],\n \"one/two/broken_symlink\n symlink/broken_symlink\",\n );\n\n // A --max-depth below either route must exclude it.\n te.assert_output(\n &[\n \"--follow\",\n \"--type\",\n \"symlink\",\n \"--max-depth\",\n \"1\",\n \"broken_symlink\",\n ],\n \"\",\n );\n}"}
{"repo":"fd","file":"tests/tests.rs","line":1379,"symbol":"test_exact_depth_broken_symlink","kind":"function","lang":"rust","doc":"Exact depth with a broken symlink (#1017) A broken symlink must be kept only at its exact depth. It is reachable at depth 3 (`one/two/broken_symlink`) and, through the followed `symlink` directory, at depth 2 (`symlink/broken_symlink`).","code":"fn test_exact_depth_broken_symlink() {\n let mut te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);\n te.create_broken_symlink(\"one/two/broken_symlink\")\n .expect(\"Failed to create broken symlink.\");\n\n // Only the depth-3 route matches --exact-depth 3.\n te.assert_output(\n &[\n \"--follow\",\n \"--type\",\n \"symlink\",\n \"--exact-depth\",\n \"3\",\n \"broken_symlink\",\n ],\n \"one/two/broken_symlink\",\n );\n\n // Only the depth-2 route (via the followed symlink) matches --exact-depth 2,\n // which confirms the depth is computed relative to the search root.\n te.assert_output(\n &[\n \"--follow\",\n \"--type\",\n \"symlink\",\n \"--exact-depth\",\n \"2\",\n \"broken_symlink\",\n ],\n \"symlink/broken_symlink\",\n );\n}"}