Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Turn any git repository into your terminal notebook.
- `zemo ls` — list topic names from `<memo>/topics/` (alphabetical).
- `zemo cat [topic]` — print scratch (or `topics/<topic>.md`) to stdout. Read-only, no git operations.
- `zemo dump` — print scratch and all topics to stdout with section headers. Read-only, no git operations.
- `zemo upgrade` — download and install the latest release in-place. `--check` to dry-run (Unix only for now; Windows tracked in #11).
- `zemo upgrade` — download and install the latest release in-place. `--check` to dry-run.
- Auto pull-on-open / commit-on-close when `<memo>/.git` exists.
- Conventional Commits messages: `docs(<scope>): YYYY-MM-DD HH:MM` for edits, `chore: sync ...` for manual sync.
- Single static binary on Linux / macOS / Windows.
Expand Down
25 changes: 17 additions & 8 deletions src/cli.zig
Original file line number Diff line number Diff line change
Expand Up @@ -485,20 +485,29 @@ fn doUpgrade(allocator: std.mem.Allocator, io: Io, stdout: *Io.Writer, stderr: *
};
defer allocator.free(archive);

// 3. アーカイブから zemo バイナリを抽出
const new_binary = upgrade.extractZemoBinary(allocator, archive, upgrade.binaryBasename()) catch |err| {
try stderr.print("zemo: failed to extract binary: {s}\n", .{@errorName(err)});
return 1;
};
defer allocator.free(new_binary);

// 4. 自分自身のパスを取得して置換
// 3. 先に install_path を解決 (zip 抽出の作業領域として親ディレクトリを使う)
const install_path = upgrade.installPath(allocator, io) catch |err| {
try stderr.print("zemo: failed to resolve install path: {s}\n", .{@errorName(err)});
return 1;
};
defer allocator.free(install_path);

// 4. アーカイブ形式に応じてバイナリを取り出す
const new_binary = if (std.mem.endsWith(u8, asset, ".zip")) blk: {
const work_dir = std.fs.path.dirname(install_path) orelse {
try stderr.print("zemo: cannot determine working dir from install path: {s}\n", .{install_path});
return 1;
};
break :blk upgrade.extractZemoBinaryFromZip(allocator, io, archive, upgrade.binaryBasename(), work_dir) catch |err| {
try stderr.print("zemo: failed to extract binary: {s}\n", .{@errorName(err)});
return 1;
};
} else upgrade.extractZemoBinary(allocator, archive, upgrade.binaryBasename()) catch |err| {
try stderr.print("zemo: failed to extract binary: {s}\n", .{@errorName(err)});
return 1;
};
defer allocator.free(new_binary);

upgrade.replaceBinary(allocator, io, install_path, new_binary) catch |err| {
try stderr.print("zemo: failed to replace binary at {s}: {s}\n", .{ install_path, @errorName(err) });
return 1;
Expand Down
10 changes: 9 additions & 1 deletion src/main.zig
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
const std = @import("std");
const cli = @import("zemo").cli;
const zemo = @import("zemo");
const cli = zemo.cli;
const upgrade = zemo.upgrade;

pub fn main(init: std.process.Init) !void {
const arena = init.arena.allocator();

// Windows で前回の `zemo upgrade` が残した `<exe>.old` を起動時に掃除する。
// 走行中の自分自身を置換した直後はこのプロセス側がまだ .old を握っているので、
// クリーンアップできるのは「次回以降の zemo 起動」になる。
upgrade.cleanupStaleBinary(arena, init.io);

const args = try init.minimal.args.toSlice(arena);
const code = try cli.run(arena, init.io, init.environ_map, args);
std.process.exit(code);
Expand Down
Loading
Loading