drop unused code:

fish_tests.cpp:
* comma_join

env.cpp:
* env_get_inherited
* env_get_runtime_path
* check_runtime_path (from tmux)
This commit is contained in:
David Adam 2023-12-31 21:14:17 +08:00
parent efa37b6a2e
commit 413ba192a0
4 changed files with 0 additions and 99 deletions

View File

@ -219,18 +219,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----
**License for code derived from tmux**
``fish`` contains code from `tmux <http://tmux.sourceforge.net>`_, copyrighted by Nicholas Marriott <nicm@users.sourceforge.net> (2007), and made available under the OpenBSD license.
The OpenBSD license is included below.
Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
----
**MIT License**
``fish`` includes a copy of Alpine.js, which is copyright 2019-2021 Caleb Porzio and contributors, and licensed under the MIT License. It also includes the Dracula theme, which is copyright 2018 Dracula Team, and the Nord theme, which is copyright 2016-present Sven Greb. These themes are also used under the MIT license.

View File

@ -126,8 +126,6 @@ void env_cpp_init() {
static std::map<wcstring, wcstring> inheriteds;
const std::map<wcstring, wcstring> &env_get_inherited() { return inheriteds; }
void set_inheriteds_ffi() {
wcstring key, val;
const char *const *envp = environ;
@ -224,72 +222,6 @@ env_stack_t::env_stack_t(rust::Box<EnvStackRef> imp) : impl_(std::move(imp)) {}
env_stack_t::env_stack_t(uint8_t *imp)
: impl_(rust::Box<EnvStackRef>::from_raw(reinterpret_cast<EnvStackRef *>(imp))) {}
#if defined(__APPLE__) || defined(__CYGWIN__)
static int check_runtime_path(const char *path) {
UNUSED(path);
return 0;
}
#else
/// Check, and create if necessary, a secure runtime path. Derived from tmux.c in tmux
/// (http://tmux.sourceforge.net/).
static int check_runtime_path(const char *path) {
// Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
// IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
// OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
struct stat statpath;
uid_t uid = geteuid();
if (mkdir(path, S_IRWXU) != 0 && errno != EEXIST) return errno;
if (lstat(path, &statpath) != 0) return errno;
if (!S_ISDIR(statpath.st_mode) || statpath.st_uid != uid ||
(statpath.st_mode & (S_IRWXG | S_IRWXO)) != 0)
return EACCES;
return 0;
}
#endif
/// Return the path of an appropriate runtime data directory.
wcstring env_get_runtime_path() {
wcstring result;
const char *dir = getenv("XDG_RUNTIME_DIR");
// Check that the path is actually usable. Technically this is guaranteed by the fdo spec but in
// practice it is not always the case: see #1828 and #2222.
if (dir != nullptr && check_runtime_path(dir) == 0) {
result = str2wcstring(dir);
} else {
// Don't rely on $USER being set, as setup_user() has not yet been called.
// See https://github.com/fish-shell/fish-shell/issues/5180
// getpeuid() can't fail, but getpwuid sure can.
auto pwuid = getpwuid(geteuid());
const char *uname = pwuid ? pwuid->pw_name : nullptr;
// /tmp/fish.user
std::string tmpdir = get_path_to_tmp_dir() + "/fish.";
if (uname) {
tmpdir.append(uname);
}
if (!uname || check_runtime_path(tmpdir.c_str()) != 0) {
FLOG(error, L"Runtime path not available.");
FLOGF(error, L"Try deleting the directory %s and restarting fish.", tmpdir.c_str());
return result;
}
result = str2wcstring(tmpdir);
}
return result;
}
static std::mutex s_setenv_lock{};
extern "C" {

View File

@ -313,9 +313,6 @@ enum {
struct EnvDyn;
#endif
/// Gets a path appropriate for runtime storage
wcstring env_get_runtime_path();
/// A wrapper around setenv() and unsetenv() which use a lock.
/// In general setenv() and getenv() are highly incompatible with threads. This makes it only
/// slightly safer.
@ -324,10 +321,6 @@ void setenv_lock(const char *name, const char *value, int overwrite);
void unsetenv_lock(const char *name);
}
/// Returns the originally inherited variables and their values.
/// This is a simple key->value map and not e.g. cut into paths.
const std::map<wcstring, wcstring> &env_get_inherited();
/// Populate the values in the "$history" variable.
/// fish_history_val is the value of the "$fish_history" variable, or "fish" if not set.
wcstring_list_ffi_t get_history_variable_text_ffi(const wcstring &fish_history_val);

View File

@ -159,18 +159,6 @@ static void err(const wchar_t *blah, ...) {
std::fwprintf(stdout, L"\n");
}
/// Joins a std::vector<wcstring> via commas.
wcstring comma_join(const std::vector<wcstring> &lst) {
wcstring result;
for (size_t i = 0; i < lst.size(); i++) {
if (i > 0) {
result.push_back(L',');
}
result.append(lst.at(i));
}
return result;
}
static std::vector<std::string> pushed_dirs;
// Helper to return a string whose length greatly exceeds PATH_MAX.