summaryrefslogtreecommitdiff
path: root/src/selection_pipe.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/selection_pipe.zig')
-rw-r--r--src/selection_pipe.zig26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/selection_pipe.zig b/src/selection_pipe.zig
index 8e721751..e1a42962 100644
--- a/src/selection_pipe.zig
+++ b/src/selection_pipe.zig
@@ -4,6 +4,7 @@
//! `runOne` on that worker. No subprocess or borrowed core memory reaches the
//! editor/event-loop thread.
const std = @import("std");
+const filesystem = @import("fs.zig");
/// A deliberately finite answer. One selection cannot retain more than 1 MiB
/// and a multi-selection command cannot retain more than 4 MiB in total.
@@ -43,7 +44,7 @@ pub const Job = struct {
.inputs = &.{},
};
errdefer gpa.free(job.command);
- job.cwd = try gpa.dupe(u8, request.cwd);
+ job.cwd = try gpa.dupe(u8, filesystem.localPath(request.cwd) orelse request.cwd);
errdefer gpa.free(job.cwd);
job.inputs = try gpa.alloc([]u8, request.inputs.len);
errdefer gpa.free(job.inputs);
@@ -325,6 +326,29 @@ pub fn runJob(gpa: std.mem.Allocator, io: std.Io, job: *const Job) Response {
return response;
}
+test "native selection filters use the physical directory of an explicit OS mount" {
+ const gpa = std.testing.allocator;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ var directory_buf: [4096]u8 = undefined;
+ const directory = directory_buf[0..try tmp.dir.realPath(std.testing.io, &directory_buf)];
+ var declared_buf: [4102]u8 = undefined;
+ const declared = try std.fmt.bufPrint(&declared_buf, "/n/os{s}", .{directory});
+ const job = try Job.copy(gpa, .{ .id = 1, .command = "pwd", .cwd = declared, .inputs = &.{.{ .bytes = "" }} });
+ defer job.deinit(gpa);
+ try std.testing.expectEqualStrings(directory, job.cwd);
+ switch (runOne(gpa, std.testing.io, job.command, job.cwd, "")) {
+ .ok => |bytes| {
+ defer gpa.free(bytes);
+ try std.testing.expectEqualStrings(directory, std.mem.trimEnd(u8, bytes, "\n"));
+ },
+ .failed => |failure| {
+ gpa.free(failure.stderr);
+ return error.FilterFailed;
+ },
+ }
+}
+
test "native pipe runner preserves stdin/stdout bytes and reports how it failed" {
const gpa = std.testing.allocator;
const io = std.testing.io;