Billy Barrow пре 10 месеци
родитељ
комит
a582b3e052
2 измењених фајлова са 76 додато и 3 уклоњено
  1. 74 1
      src/cli/Cli.vala
  2. 2 2
      src/lib/Manifest.vala

+ 74 - 1
src/cli/Cli.vala

@@ -58,13 +58,17 @@ public static int main(string[] args) {
         return acquire();
     }
 
+    if(verb == "remove") {
+        return uininstall();
+    }
+
 
     usage();
     return 255;
 }
 
 private void usage() {
-    printerr("USAGE:\n\tusm build <build path>\n\tusm rebuild <build path>\n\tusm install <build path>\n\tusm remove\nusm acquire\n");
+    printerr("USAGE:\n\tusm build <build path>\n\tusm install <build path>\n\tusm remove\nusm acquire\n");
 }
 
 
@@ -213,5 +217,74 @@ private int acquire() {
         return 251;
     }
 
+    return 0;
+}
+
+private int uininstall() {
+    var missing_management_deps = manifest.dependencies.manage.where(d => !d.is_satisfied());
+
+    if(missing_management_deps.any()) {
+        foreach (var item in missing_management_deps) {
+            printerr(@"Missing management dependency \"$item\".\n");
+        }
+
+        printerr("Could not remove manifest, missing dependencies\n");
+        return 252;
+    }
+
+    try {
+        var proc = manifest.run_remove(Usm.RemoveType.FINAL, SubprocessFlags.INHERIT_FDS);
+        if(proc != null) {
+            proc.wait_check();
+        }
+    }
+    catch(Error e) {
+        printerr(@"Error running remove exec: $(e.message)\n");
+        return 249;
+    }
+
+    // Do files and symlinks first
+    foreach (var resource in manifest.provides.where(r => r.value.file_type != Usm.ManifestFileType.DIRECTORY)) {
+        var path = paths.get_suggested_path(resource.key);
+        printerr(@"Deleting resource $(resource.key) from $path...");
+        try {
+            var file = File.new_for_path(path);
+            if(file.query_exists()) {
+                file.delete();
+                printerr(" done\n");
+            }
+            else {
+                printerr(" file missing\n");
+            }
+        }
+        catch(Error e) {
+            printerr(@" $(e.message)\n");
+            return 250;
+        }
+    }
+
+    // Do directories last
+    foreach (var resource in manifest.provides.where(r => r.value.file_type == Usm.ManifestFileType.DIRECTORY)) {
+        var path = paths.get_suggested_path(resource.key);
+        printerr(@"Deleting resource $(resource.key) from $path...");
+        try {
+            var file = File.new_for_path(path);
+            if(file.query_exists()) {
+                file.delete();
+                printerr(" done\n");
+            }
+            else {
+                printerr(" file missing\n");
+            }
+        }
+        catch(IOError.NOT_EMPTY e) {
+            printerr(" directory not empty\n");
+        }
+        catch(Error e) {
+            printerr(@" $(e.message)\n");
+            return 250;
+        }
+    }
+
     return 0;
 }

+ 2 - 2
src/lib/Manifest.vala

@@ -111,12 +111,12 @@ namespace Usm {
             return proc;
         }
 
-        public Subprocess? run_remove(string build_path, RemoveType type, SubprocessFlags flags) throws Error {
+        public Subprocess? run_remove(RemoveType type, SubprocessFlags flags) throws Error {
             if(executables.remove == null) {
                 return null;
             }
             var path = Path.build_filename(Environment.get_current_dir(), executables.remove);
-            var proc = new Subprocess.newv(new string[] { path, build_path, type.to_string() }, flags);
+            var proc = new Subprocess.newv(new string[] { path, type.to_string() }, flags);
             return proc;
         }