Parcourir la source

feat: granular progress during cleanup — xz compression percentage parsed in real-time, sub-stages weighted (compress 25%, source clean 25%, install clean 25%, complete 25%)

clanker il y a 1 semaine
Parent
commit
c0163b55bc
4 fichiers modifiés avec 789 ajouts et 1205 suppressions
  1. 745 1200
      installer/install-usm.sh
  2. 2 2
      src/lib/State/CachedPackage.vala
  3. 6 3
      src/lib/Transaction.vala
  4. 36 0
      src/lib/Util.vala

Fichier diff supprimé car celui-ci est trop grand
+ 745 - 1200
installer/install-usm.sh


+ 2 - 2
src/lib/State/CachedPackage.vala

@@ -86,7 +86,7 @@ namespace Usm {
             return path;
         }
 
-        public void archive_build() throws Error {
+        public void archive_build(Usm.ProgressDelegate? progress = null) throws Error {
             // An archive with no build directory is already the
             // authoritative artifact: extracting it just to repack the
             // same bytes is pure churn
@@ -102,7 +102,7 @@ namespace Usm {
                 archive_file.delete();
             }
 
-            Util.archive(build_dir, archive_file.get_path());
+            Util.archive_with_progress(build_dir, archive_file.get_path(), progress);
             clean_build_directory();
         }
 

+ 6 - 3
src/lib/Transaction.vala

@@ -704,12 +704,15 @@ namespace Usm {
             // A package with no build artifact (for example after `usm
             // clean builds`) has nothing to archive; its cache stays as-is
             if(package.has_build_directory() || package.has_build_archive()) {
-                package.archive_build();
+                package.archive_build((compression) => {
+                    report_progress(TransactionTask.CLEANING_UP, compression * 0.25f);
+                });
             }
-            report_progress(TransactionTask.CLEANING_UP, 0.33334f);
+            report_progress(TransactionTask.CLEANING_UP, 0.25f);
             package.clean_source();
-            report_progress(TransactionTask.CLEANING_UP, 0.66667f);
+            report_progress(TransactionTask.CLEANING_UP, 0.5f);
             package.clean_install();
+            report_progress(TransactionTask.CLEANING_UP, 0.75f);
             report_progress(TransactionTask.CLEANING_UP, 1.0f);
         }
     }

+ 36 - 0
src/lib/Util.vala

@@ -49,4 +49,40 @@ namespace Usm.Util {
         }
     }
 
+    /**
+     * Archives `source` into `archive` (tar.xz), reporting compression
+     * progress by parsing xz's verbose stderr. The callback receives a
+     * 0..1 fraction.
+     */
+    public static void archive_with_progress(string source, string archive_path, Usm.ProgressDelegate? progress) throws Error {
+        if(progress == null) {
+            archive(source, archive_path);
+            return;
+        }
+
+        var proc = new Subprocess.newv(
+            new string[] { "bash", "-c",
+                @"tar -cf - --directory '$source' . | xz -T0 -v -c > '$(archive_path)'" },
+            SubprocessFlags.STDERR_PIPE);
+
+        var stderr_pipe = new DataInputStream(proc.get_stderr_pipe());
+        stderr_pipe.set_buffer_size(512);
+
+        string line;
+        while((line = stderr_pipe.read_line(null)) != null) {
+            var trimmed = line.strip();
+            if(trimmed.length > 0 && trimmed[0].isdigit()) {
+                var space = trimmed.index_of(" ");
+                if(space > 0) {
+                    var pct_str = trimmed.substring(0, space);
+                    var pct = double.parse(pct_str);
+                    if(pct >= 0.0 && pct <= 100.0) {
+                        progress((float)(pct / 100.0));
+                    }
+                }
+            }
+        }
+        proc.wait_check();
+    }
+
 }

Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff