Skip to content

Commit 942a9d1

Browse files
committed
Fix set env vars
1 parent b312950 commit 942a9d1

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sharun"
3-
version = "0.5.5"
3+
version = "0.5.6"
44
readme = "README.md"
55
license = "MIT"
66
repository = "https://github.com/VHSgunzo/sharun"

src/main.rs

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -595,20 +595,31 @@ fn main() {
595595
env::remove_var("SHARUN_WORKING_DIR")
596596
}
597597

598+
#[cfg(feature = "setenv")]
599+
{
600+
if let Ok(dir) = PathBuf::from(&library_path).read_dir() {
601+
for entry in dir.flatten() {
602+
let entry_path = entry.path();
603+
if entry_path.is_dir() {
604+
let name = entry.file_name();
605+
if let Some(name) = name.to_str() {
606+
if name.starts_with("girepository-") {
607+
env::set_var("GI_TYPELIB_PATH", entry_path)
608+
}
609+
}
610+
}
611+
}
612+
}
613+
}
614+
598615
let lib_path_file = &format!("{library_path}/lib.path");
599616
if !Path::new(lib_path_file).exists() && is_writable(&library_path) {
600617
gen_library_path(&library_path, lib_path_file)
601618
}
602619

603620
add_to_env("PATH", bin_dir);
604621

605-
let mut lib_path_data = read_to_string(lib_path_file).unwrap_or("".into());
606-
if !lib_path_data.is_empty() {
607-
lib_path_data = lib_path_data.trim().into();
608-
library_path = lib_path_data
609-
.replace("\n", ":")
610-
.replace("+", &library_path)
611-
}
622+
let mut lib_path_data = read_to_string(lib_path_file).unwrap_or_default();
612623

613624
#[cfg(feature = "setenv")]
614625
{
@@ -668,9 +679,6 @@ fn main() {
668679
if dir.starts_with("gegl-") {
669680
env::set_var("GEGL_PATH", dir_path)
670681
}
671-
if dir.starts_with("girepository-") {
672-
env::set_var("GI_TYPELIB_PATH", dir_path)
673-
}
674682
if dir == "libdecor" {
675683
let plugins = &format!("{dir_path}/plugins-1");
676684
if Path::new(plugins).exists() {
@@ -714,17 +722,7 @@ fn main() {
714722
}
715723
}
716724
}
717-
}
718-
719-
drop(lib_path_data);
720-
721-
let ld_library_path_env = &get_env_var("LD_LIBRARY_PATH");
722-
if !ld_library_path_env.is_empty() {
723-
library_path += &format!(":{ld_library_path_env}")
724-
}
725725

726-
#[cfg(feature = "setenv")]
727-
{
728726
let share_dir = PathBuf::from(format!("{sharun_dir}/share"));
729727
if share_dir.exists() {
730728
if let Ok(dir) = share_dir.read_dir() {
@@ -814,6 +812,20 @@ fn main() {
814812
}
815813
}
816814

815+
if !lib_path_data.is_empty() {
816+
lib_path_data = lib_path_data.trim().into();
817+
library_path = lib_path_data
818+
.replace("\n", ":")
819+
.replace("+", &library_path)
820+
}
821+
822+
drop(lib_path_data);
823+
824+
let ld_library_path_env = &get_env_var("LD_LIBRARY_PATH");
825+
if !ld_library_path_env.is_empty() {
826+
library_path += &format!(":{ld_library_path_env}")
827+
}
828+
817829
for var_name in unset_envs {
818830
env::remove_var(var_name)
819831
}

0 commit comments

Comments
 (0)