Changes
2 changed files (+77/-0)
-
-
@@ -81,6 +81,14 @@ stdenvNoCC.mkDerivation rec {--long project \ --require-parameter \ -d "Project directory to bind mount" complete -c ${name} \ --condition "__fish_seen_subcommand_from incus; and __fish_seen_subcommand_from $incus_commands" \ --long mutable \ --require-parameter \ -d "Directory types to disable readonly mode" \ --no-files \ -a "git\t'.git directory under PROJECT' jj\t'.jj directory under PROJECT'" EOF) ''; }
-
-
-
@@ -36,6 +36,7 @@ const incus = struct {shift: bool = true, source: []const u8, path: []const u8, readonly: bool = false, }; };
-
@@ -55,6 +56,12 @@ const Options = struct {/// Wayland socket to bind. wayland_socket: ?WaylandSocket = null, /// Enable writes to "$PROJECT/.git". mutable_git_dir: bool = false, /// Enable writes to "$PROJECT/.jj". mutable_jj_dir: bool = false, const WriteError = std.Io.Writer.Error || std.mem.Allocator.Error; fn writeJson(self: *const Options, allocator: std.mem.Allocator, writer: *std.Io.Writer) WriteError!void {
-
@@ -110,6 +117,24 @@ const Options = struct {.source = project_dir, .path = "/home/workerbee/project", }); if (!self.mutable_git_dir) { try json.objectField("git"); try json.write(incus.DiskDevice{ .source = try std.fs.path.join(allocator, &.{ project_dir, ".git" }), .path = "/home/workerbee/project/.git", .readonly = true, }); } if (!self.mutable_jj_dir) { try json.objectField("jj"); try json.write(incus.DiskDevice{ .source = try std.fs.path.join(allocator, &.{ project_dir, ".jj" }), .path = "/home/workerbee/project/.jj", .readonly = true, }); } } try json.endObject();
-
@@ -138,6 +163,15 @@ const help =\\ Project directory to bind mount. To use this option, \\ host and local machine MUST be the same. \\ \\--mutable <VALUE>[,<VALUE>...] \\ Comma-separated list of directories to disable readonly \\ mount. To prevent unintentional command execution on \\ container host, certain directories are mounted in \\ readonly mode. You can allow writes certain directories \\ using this option. Available values are: \\ * git ... $PROJECT/.git \\ * jj ... $PROJECT/.jj \\ ; pub fn run(allocator: std.mem.Allocator, args: *std.process.ArgIterator) !exit.Code {
-
@@ -213,10 +247,45 @@ pub fn run(allocator: std.mem.Allocator, args: *std.process.ArgIterator) !exit.Ccontinue; } if (std.mem.eql(u8, arg, "--mutable")) { const values = args.next() orelse { std.log.err("{s} option requires a value", .{arg}); return .incorrect_usage; }; var values_iter = std.mem.splitScalar(u8, values, ','); while (values_iter.next()) |value| { if (std.mem.eql(u8, value, "git")) { options.mutable_git_dir = true; continue; } if (std.mem.eql(u8, value, "jj")) { options.mutable_jj_dir = true; continue; } std.log.err("Unknown value {s} at {s} option", .{ value, arg }); return .incorrect_usage; } continue; } std.log.err("Unknown option value: {s}", .{arg}); return .incorrect_usage; } if (options.mutable_git_dir and options.project_dir == null) { std.log.err("--mutable=git requires --project option", .{}); return .incorrect_usage; } if (options.mutable_jj_dir and options.project_dir == null) { std.log.err("--mutable=jj requires --project option", .{}); return .incorrect_usage; } var output_buffer: [1024]u8 = undefined; var output_writer = std.fs.File.stdout().writer(&output_buffer); const writer = &output_writer.interface;
-