Parcourir la source

fix(paths): ensure trailing slashes on all path arguments

clanker il y a 1 mois
Parent
commit
05714f8aaf
2 fichiers modifiés avec 28 ajouts et 21 suppressions
  1. 6 6
      src/lib/Manifest.vala
  2. 22 15
      src/lib/Paths.vala

+ 6 - 6
src/lib/Manifest.vala

@@ -179,7 +179,7 @@ namespace Usm {
                 }
                 modified_flags = modified_flags | SubprocessFlags.STDOUT_PIPE;
                 
-                var proc = new Subprocess.newv(new string[] { path, effective_build_path }, modified_flags);
+                var proc = new Subprocess.newv(new string[] { path, Paths.ensure_trailing_slash(effective_build_path) }, modified_flags);
                 
                 // Start a new thread to monitor STDOUT for progress information
                 ThreadFunc<void> progress_thread_func = () => {
@@ -240,7 +240,7 @@ namespace Usm {
                 
                 return proc;
             } else {
-                var proc = new Subprocess.newv(new string[] { path, effective_build_path }, flags);
+                var proc = new Subprocess.newv(new string[] { path, Paths.ensure_trailing_slash(effective_build_path) }, flags);
                 
                 // Restore original working directory after subprocess completes
                 Environment.set_current_dir(original_working_dir);
@@ -262,7 +262,7 @@ namespace Usm {
             
             // Change to the working directory for subprocess execution
             Environment.set_current_dir(working_dir);
-            var proc = new Subprocess.newv(new string[] { path, build_path }, flags);
+            var proc = new Subprocess.newv(new string[] { path, Paths.ensure_trailing_slash(build_path) }, flags);
             
             // Restore original working directory after subprocess completes
             Environment.set_current_dir(original_working_dir);
@@ -299,7 +299,7 @@ namespace Usm {
             // Change to the working directory for subprocess execution
             Environment.set_current_dir(working_dir);
             new_paths.set_envs();
-            var proc = new Subprocess.newv(new string[] { path, build_path, install_path, type.to_string() }, flags);
+            var proc = new Subprocess.newv(new string[] { path, Paths.ensure_trailing_slash(build_path), Paths.ensure_trailing_slash(install_path), type.to_string() }, flags);
             
             // Restore original working directory after subprocess completes
             Environment.set_current_dir(original_working_dir);
@@ -320,7 +320,7 @@ namespace Usm {
             
             // Change to the working directory for subprocess execution
             Environment.set_current_dir(working_dir);
-            var proc = new Subprocess.newv(new string[] { path, build_path, type.to_string() }, flags);
+            var proc = new Subprocess.newv(new string[] { path, Paths.ensure_trailing_slash(build_path), type.to_string() }, flags);
             
             // Restore original working directory after subprocess completes
             Environment.set_current_dir(original_working_dir);
@@ -352,7 +352,7 @@ namespace Usm {
             
             // Change to the working directory for subprocess execution
             Environment.set_current_dir(working_dir);
-            var proc = new Subprocess.newv(new string[] { path, build_path }, flags);
+            var proc = new Subprocess.newv(new string[] { path, Paths.ensure_trailing_slash(build_path) }, flags);
             
             // Restore original working directory after subprocess completes
             Environment.set_current_dir(original_working_dir);

+ 22 - 15
src/lib/Paths.vala

@@ -22,21 +22,28 @@ namespace Usm {
         public string usm_config_dir { get; set; }
 
         public void set_envs() {
-            Environment.set_variable("DESTDIR", destination, true);
-            Environment.set_variable("PREFIX", prefix, true);
-            Environment.set_variable("BINDIR", bin, true);
-            Environment.set_variable("INCLUDEDIR", include, true);
-            Environment.set_variable("DATADIR", data, true);
-            Environment.set_variable("INFODIR", info, true);
-            Environment.set_variable("LIBDIR", lib, true);
-            Environment.set_variable("MANDIR", man, true);
-            Environment.set_variable("LIBEXECDIR", libexec, true);
-            Environment.set_variable("LOCALEDIR", locale, true);
-            Environment.set_variable("LOCALSTATEDIR", local_state, true);
-            Environment.set_variable("SBINDIR", sbin, true);
-            Environment.set_variable("SHAREDSTATEDIR", shared_state, true);
-            Environment.set_variable("SYSCONFIGDIR", sys_config, true);
-            Environment.set_variable("TAGSDIR", tags, true);
+            Environment.set_variable("DESTDIR", Paths.ensure_trailing_slash(destination), true);
+            Environment.set_variable("PREFIX", Paths.ensure_trailing_slash(prefix), true);
+            Environment.set_variable("BINDIR", Paths.ensure_trailing_slash(bin), true);
+            Environment.set_variable("INCLUDEDIR", Paths.ensure_trailing_slash(include), true);
+            Environment.set_variable("DATADIR", Paths.ensure_trailing_slash(data), true);
+            Environment.set_variable("INFODIR", Paths.ensure_trailing_slash(info), true);
+            Environment.set_variable("LIBDIR", Paths.ensure_trailing_slash(lib), true);
+            Environment.set_variable("MANDIR", Paths.ensure_trailing_slash(man), true);
+            Environment.set_variable("LIBEXECDIR", Paths.ensure_trailing_slash(libexec), true);
+            Environment.set_variable("LOCALEDIR", Paths.ensure_trailing_slash(locale), true);
+            Environment.set_variable("LOCALSTATEDIR", Paths.ensure_trailing_slash(local_state), true);
+            Environment.set_variable("SBINDIR", Paths.ensure_trailing_slash(sbin), true);
+            Environment.set_variable("SHAREDSTATEDIR", Paths.ensure_trailing_slash(shared_state), true);
+            Environment.set_variable("SYSCONFIGDIR", Paths.ensure_trailing_slash(sys_config), true);
+            Environment.set_variable("TAGSDIR", Paths.ensure_trailing_slash(tags), true);
+        }
+
+        public static string ensure_trailing_slash(string path) {
+            if (path == null || path.length == 0) {
+                return "/";
+            }
+            return path.has_suffix("/") ? path : path + "/";
         }
 
         public string get_suggested_base_path_for_type(ResourceType type) {