RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
Merge transfer manifest entries into destination listings
Mel339220f736f0
diff --git a/src/files/app.zig b/src/files/app.zigindex b3d0cc3..90a2c5a 100644--- a/src/files/app.zig+++ b/src/files/app.zig@@ -36,6 +36,7 @@ const app_sidebar_paint = @import("app_sidebar_paint.zig");const app_scroll = @import("app_scroll.zig");const app_torrents = @import("app_torrents.zig");const app_torrent_rows = @import("app_torrent_rows.zig");+const app_transfer_rows = @import("app_transfer_rows.zig");const app_git_sidebar = @import("app_git_sidebar.zig");const app_opening = @import("app_opening.zig");const app_audio = @import("app_audio.zig");@@ -285,6 +286,7 @@ pub const App = struct {job_rate_sample_at: i64 = 0,job_bytes_per_second: u64 = 0,job_state: ops_mod.JobState = .idle,+ transfer_rows_dirty: bool = false,status_notice: ?[]u8 = null,status_notice_until: i64 = 0,status_is_error: bool = false,@@ -824,6 +826,7 @@ pub const renderFileOpsTip = app_sidebar_paint.renderFileOpsTip;pub const torrentForItem = app_torrent_rows.torrentForItem;pub const hasFolderTransfers = app_torrent_rows.hasFolderTransfers;pub const appendTorrentRows = app_torrent_rows.appendTorrentRows;+ pub const appendTransferRows = app_transfer_rows.appendTransferRows;pub const inlineTorrentWidth = app_torrent_rows.inlineTorrentWidth;pub const renderInlineTorrent = app_torrent_rows.renderInlineTorrent;pub const inlineTorrentHit = app_torrent_rows.inlineTorrentHit;diff --git a/src/files/app_listing.zig b/src/files/app_listing.zigindex 76ce745..699a60c 100644--- a/src/files/app_listing.zig+++ b/src/files/app_listing.zig@@ -351,6 +351,7 @@ pub fn sync(self: *App) void {const bytes_changed = self.job_transferred_bytes != progress.transferred_bytes;const tooltip_hovered = self.hoverKey() == std.math.maxInt(usize) - 2002;if (state_changed) {+ self.transfer_rows_dirty = true;self.invalidate();} else if (processed_changed or bytes_changed or file_path_changed or(rate_changed and tooltip_hovered))@@ -407,7 +408,10 @@ pub fn sync(self: *App) void {// the first loop after release applies it.if (self.selection_band != null or self.drag_origin != null) return;const snap = self.worker.takeSnapshot() orelse {- if (self.torrents.rows_changed) self.rebuildView();+ if (self.torrents.rows_changed or self.transfer_rows_dirty) {+ self.transfer_rows_dirty = false;+ self.rebuildView();+ }return;};if (isStaleSnapshot(snap.request_id, self.active_request_id)) {@@ -421,6 +425,7 @@ pub fn sync(self: *App) void {self.clampSidebarScroll();self.loading = false;self.rebuildView();+ self.transfer_rows_dirty = false;if (self.restore_view) self.restoreView();if (self.initial_selection) |path| {self.initial_selection = null;@@ -571,6 +576,7 @@ pub fn rebuildView(self: *App) void {}) catch continue;}self.appendTorrentRows(mem, &selected_paths);+ self.appendTransferRows(mem, &selected_paths);// Transfer placeholders and synthetic snapshots have no worker key.// Give those rows keys from the same locale before sorting so every// comparison uses one collation, including mixed real/stub folders.diff --git a/src/files/app_model.zig b/src/files/app_model.zigindex 85a537c..9d6223a 100644--- a/src/files/app_model.zig+++ b/src/files/app_model.zig@@ -199,6 +199,8 @@ pub const ViewItem = struct {git_status: git.Status = .clean,git_lines: ?git.LineCounts = null,transfer_stub: bool = false,+ transfer_ghost: bool = false,+ transfer_state: ?@import("ops.zig").TransferEntryState = null,missing: bool = false,name: []const u8,/// Path from the listed folder, shown instead of `name` in the Git view'sdiff --git a/src/files/app_transfer_rows.zig b/src/files/app_transfer_rows.zignew file mode 100644index 0000000..7a8a12b--- /dev/null+++ b/src/files/app_transfer_rows.zig@@ -0,0 +1,172 @@+//! Merge active file-operation manifest entries into the current folder view.++const std = @import("std");+const App = @import("app.zig").App;+const ViewItem = @import("app_model.zig").ViewItem;+const transfer_tree = @import("transfer_tree.zig");+const fold = @import("ui").fold;++pub fn appendTransferRows(+ self: *App,+ mem: std.mem.Allocator,+ old: *const std.StringHashMap(ViewItem),+) void {+ if (self.chooser != null or self.transfer_view.active or+ self.history.archive_len > 0 or self.isRecent() or self.changedOnly()) return;+ if (self.job_state != .running and self.job_state != .paused and+ self.job_state != .waiting_conflict) return;++ const runner = self.job_runner orelse return;+ var manifest = runner.snapshotTransferManifest(self.allocator) catch return;+ defer manifest.deinit();++ var tree = transfer_tree.build(mem, manifest.entries.items) catch return;+ defer tree.deinit();+ appendTreeRows(self, mem, &tree, old);+}++/// Appends only direct children of the displayed folder. Existing filesystem+/// entries take precedence; completed entries are published and usable.+pub fn appendTreeRows(+ self: *App,+ mem: std.mem.Allocator,+ tree: *const transfer_tree.Tree,+ old: *const std.StringHashMap(ViewItem),+) void {+ for (tree.nodes.items) |node| {+ if (!std.mem.eql(u8, std.fs.path.dirname(node.path) orelse "", self.history.current)) continue;++ const ghost = switch (node.state) {+ .pending, .copying => true,+ .completed => false,+ .skipped, .failed, .cancelled => continue,+ };+ if (self.folders_only and node.kind != .directory) continue;+ if (!fold.contains(node.name, self.search.text.items, .{ .turkish = @import("i18n").isTurkish() })) continue;++ var represented = false;+ for (self.items.items) |item| {+ if (std.mem.eql(u8, item.path, node.path)) {+ represented = true;+ break;+ }+ }+ if (represented) continue;++ const previous = old.get(node.path);+ const bytes: i64 = @intCast(@min(node.size, @as(u64, std.math.maxInt(i64))));+ const name = mem.dupe(u8, node.name) catch continue;+ const path = mem.dupe(u8, node.path) catch {+ mem.free(name);+ continue;+ };+ self.items.append(self.allocator, .{+ .name = name,+ .path = path,+ .is_dir = node.kind == .directory,+ .is_symlink = node.kind == .symlink,+ .is_broken = false,+ .transfer_ghost = ghost,+ .transfer_state = node.state,+ .missing = ghost,+ .bytes = bytes,+ .mtime = 0,+ .icon_name = switch (node.kind) {+ .directory => "folder",+ .file => "text-x-generic",+ .symlink => "emblem-symbolic-link",+ },+ .selected = if (previous) |item| item.selected else false,+ .selection_fill = if (previous) |item| item.selection_fill else .{},+ .selection_border = if (previous) |item| item.selection_border else .{},+ }) catch {+ mem.free(name);+ mem.free(path);+ };+ }+}++test "transfer rows merge direct children, prefer real entries and retain selection" {+ const allocator = std.testing.allocator;+ var arena = std.heap.ArenaAllocator.init(allocator);+ defer arena.deinit();+ const mem = arena.allocator();++ var app: App = .{+ .allocator = allocator,+ .io = undefined,+ .environ = undefined,+ .theme_cfg = undefined,+ .worker = undefined,+ .history = .{ .allocator = allocator, .current = "/destination/root" },+ .home_dir = "/",+ .items_arena = undefined,+ };+ defer app.items.deinit(allocator);++ try app.items.append(allocator, .{+ .name = "already-real.txt",+ .path = "/destination/root/already-real.txt",+ .is_dir = false,+ .is_symlink = false,+ .is_broken = false,+ .bytes = 9,+ .mtime = 1,+ .icon_name = "text-x-generic",+ });++ var manifest = @import("ops.zig").TransferManifest.init(allocator);+ defer manifest.deinit();+ try manifest.append("/source", "", "/destination/root", 0, .directory, 0);+ try manifest.append("/source/already-real.txt", "already-real.txt", "/destination/root/already-real.txt", 9, .file, 0);+ try manifest.append("/source/pending.txt", "pending.txt", "/destination/root/pending.txt", 12, .file, 0);+ try manifest.append("/source/sub", "sub", "/destination/root/sub", 0, .directory, 0);+ try manifest.append("/source/sub/nested.txt", "sub/nested.txt", "/destination/root/sub/nested.txt", 4, .file, 0);+ try manifest.append("/source/done.txt", "done.txt", "/destination/root/done.txt", 20, .file, 0);+ try manifest.append("/source/skipped.txt", "skipped.txt", "/destination/root/skipped.txt", 2, .file, 0);+ manifest.entries.items[1].state = .pending;+ manifest.entries.items[2].state = .pending;+ manifest.entries.items[3].state = .copying;+ manifest.entries.items[4].state = .pending;+ manifest.entries.items[5].state = .completed;+ manifest.entries.items[6].state = .skipped;++ var tree = try transfer_tree.build(allocator, manifest.entries.items);+ defer tree.deinit();++ var old = std.StringHashMap(ViewItem).init(allocator);+ defer old.deinit();+ try old.put("/destination/root/pending.txt", .{+ .name = "pending.txt",+ .path = "/destination/root/pending.txt",+ .is_dir = false,+ .is_symlink = false,+ .is_broken = false,+ .bytes = 12,+ .mtime = 0,+ .icon_name = "text-x-generic",+ .selected = true,+ });++ appendTreeRows(&app, mem, &tree, &old);++ // Existing real entry + pending file + copying directory + completed file.+ try std.testing.expectEqual(@as(usize, 4), app.items.items.len);+ try std.testing.expectEqualStrings("already-real.txt", app.items.items[0].name);+ try std.testing.expect(app.items.items[0].transfer_state == null);++ const pending = app.items.items[1];+ try std.testing.expectEqualStrings("pending.txt", pending.name);+ try std.testing.expect(pending.transfer_ghost and pending.missing);+ try std.testing.expect(pending.selected);+ try std.testing.expectEqual(@as(i64, 12), pending.bytes);++ const sub = app.items.items[2];+ try std.testing.expectEqualStrings("sub", sub.name);+ try std.testing.expect(sub.is_dir and sub.transfer_ghost and sub.missing);++ const done = app.items.items[3];+ try std.testing.expectEqualStrings("done.txt", done.name);+ try std.testing.expect(!done.transfer_ghost and !done.missing);+ try std.testing.expectEqual(@import("ops.zig").TransferEntryState.completed, done.transfer_state.?);+}