~gpanders/wk

40ec79b40050caf014bb0be59391fd4d5843dab5 — Greg Anders a month ago 785887c
Remove modified logic

This was only really necessary for knowing which files to commit to git,
but since files are now only committed in the 'new' and 'sync' commands
it's no longer needed.
2 files changed, 1 insertions(+), 25 deletions(-)

M src/cmd/backlinks.zig
M src/zettel.zig
M src/cmd/backlinks.zig => src/cmd/backlinks.zig +1 -7
@@ 19,11 19,5 @@ pub const cmd = Command{
pub fn run(allocator: *mem.Allocator, args: ?[]const []const u8) Command.Error!void {
    const zettels = try getZettels(allocator);
    try updateBacklinks(allocator, zettels);

    var nmodified: u32 = 0;
    for (zettels) |zet| {
        if (try zet.modified()) nmodified += 1;
    }

    stdout.print("Updated backlinks in {} notes.\n", .{nmodified}) catch return;
    stdout.print("Updated backlinks in all notes.\n", .{}) catch return;
}

M src/zettel.zig => src/zettel.zig +0 -18
@@ 21,7 21,6 @@ pub const Zettel = struct {
    id: []const u8,
    tags: [][]const u8,
    title: []const u8,
    mtime: i64,
    contents: []const u8,

    /// Create a new Zettel with the given title.


@@ 53,7 52,6 @@ pub const Zettel = struct {
            .id = fname[0..id_len],
            .tags = &[_][]const u8{},
            .title = try mem.dupe(allocator, u8, title),
            .mtime = (try file.stat()).mtime,
            .contents = contents,
        };
    }


@@ 65,21 63,6 @@ pub const Zettel = struct {
        return try file.inStream().readAllAlloc(self.allocator, 1 * 1024 * 1024);
    }

    pub fn modified(self: Zettel) !bool {
        var file = try fs.cwd().openFile(self.fname, .{ .read = true });
        defer file.close();

        if ((try file.stat()).mtime == self.mtime) {
            return false;
        }

        if (mem.eql(u8, self.contents, try self.read())) {
            return false;
        }

        return true;
    }

    pub fn match(self: Zettel, keywords: []const []const u8) bool {
        for (keywords) |keyword| {
            if (ascii.indexOfIgnoreCase(self.fname, keyword) != null or


@@ 305,7 288,6 @@ fn fromEntry(allocator: *mem.Allocator, entry: fs.Dir.Entry) !Zettel {
        .id = fname[0..id_len],
        .tags = tags.toOwnedSlice(),
        .title = title.?,
        .mtime = (try file.stat()).mtime,
        .contents = contents,
    };
}