Skip to content

Commit

Permalink
Remove the dirs-next dependency
Browse files Browse the repository at this point in the history
This crate hasn't been maintained in a while, and we only used it for
obtaining the home directory, which is easy enough to implement
ourselves.

On Windows we expect the USERPROFILE variable to be set, and we don't
have a fallback to SHGetFolderPathW(). As far as I can tell USERPROFILE
is usually set, so it should be good enough. In all cases if the home
directory is explicitly set to an empty string we ignore it, because
there's no scenario in which one would treat it any different from a
home directory not being set at all.

Changelog: changed
  • Loading branch information
yorickpeterse committed Sep 22, 2022
1 parent b41c2c8 commit c0e6752
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 173 deletions.
103 changes: 0 additions & 103 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion vm/Cargo.toml
Expand Up @@ -13,7 +13,6 @@ doctest = false
libffi-system = ["libffi/system"]

[dependencies]
dirs-next = "^1.0"
libloading = "^0.7"
libffi = "^3.0"
crossbeam-utils = "^0.8"
Expand Down
28 changes: 18 additions & 10 deletions vm/src/builtin_functions/env.rs
@@ -1,5 +1,4 @@
//! Functions for setting/getting environment and operating system data.
use crate::directories;
use crate::mem::{Array, Pointer, String as InkoString};
use crate::platform;
use crate::process::ProcessPointer;
Expand Down Expand Up @@ -48,15 +47,22 @@ pub(crate) fn env_home_directory(
_: ProcessPointer,
_: &[Pointer],
) -> Result<Pointer, RuntimeError> {
let result = if let Some(path) = directories::home() {
InkoString::alloc(
state.permanent_space.string_class(),
canonalize(path),
)
// Rather than performing all sorts of magical incantations to get the home
// directory, we're just going to require that these environment variables
// are set.
let var = if cfg!(windows) {
state.environment.get("USERPROFILE")
} else {
Pointer::undefined_singleton()
state.environment.get("HOME")
};

// If the home is explicitly set to an empty string we still ignore it,
// because there's no scenario in which Some("") is useful.
let result = var
.cloned()
.filter(|p| unsafe { !InkoString::read(p).is_empty() })
.unwrap_or_else(Pointer::undefined_singleton);

Ok(result)
}

Expand All @@ -66,7 +72,7 @@ pub(crate) fn env_temp_directory(
_: ProcessPointer,
_: &[Pointer],
) -> Result<Pointer, RuntimeError> {
let path = canonalize(directories::temp());
let path = canonalize(env::temp_dir().to_string_lossy().into_owned());

Ok(InkoString::alloc(state.permanent_space.string_class(), path))
}
Expand All @@ -77,7 +83,9 @@ pub(crate) fn env_get_working_directory(
_: ProcessPointer,
_: &[Pointer],
) -> Result<Pointer, RuntimeError> {
let path = directories::working_directory().map(canonalize)?;
let path = env::current_dir()
.map(|path| path.to_string_lossy().into_owned())
.map(canonalize)?;

Ok(InkoString::alloc(state.permanent_space.string_class(), path))
}
Expand All @@ -90,7 +98,7 @@ pub(crate) fn env_set_working_directory(
) -> Result<Pointer, RuntimeError> {
let dir = unsafe { InkoString::read(&arguments[0]) };

directories::set_working_directory(dir)?;
env::set_current_dir(dir)?;
Ok(Pointer::nil_singleton())
}

Expand Down
58 changes: 0 additions & 58 deletions vm/src/directories.rs

This file was deleted.

1 change: 0 additions & 1 deletion vm/src/lib.rs
Expand Up @@ -9,7 +9,6 @@ pub mod arc_without_weak;
pub mod builtin_functions;
pub mod chunk;
pub mod config;
pub mod directories;
pub mod execution_context;
pub mod ffi;
pub mod hasher;
Expand Down

0 comments on commit c0e6752

Please sign in to comment.