|
|
@@ -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();
|
|
|
+ }
|
|
|
+
|
|
|
}
|