vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit ca56caebfc6665dcd16a61f89e8a942d7a4e0fb2
parent a537d758fcd670c3fc56ceb5728563ac936c1522
Author: Tom Schwindl <schwindl@posteo.de>
Date:   Sun, 10 Jul 2022 19:30:22 +0000

vis: Compare inodes instead of filenames

Diffstat:
Mvis.c | 11++++++++---
Mvis.h | 2--
2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/vis.c b/vis.c @@ -179,14 +179,19 @@ err: static File *file_new(Vis *vis, const char *name) { char *name_absolute = NULL; + struct stat new; + if (name) { if (!(name_absolute = absolute_path(name))) return NULL; + if (stat(name_absolute, &new) && errno != ENOENT) + return NULL; + File *existing = NULL; - /* try to detect whether the same file is already open in another window - * TODO: do this based on inodes */ + /* try to detect whether the same file is already open in another window */ for (File *file = vis->files; file; file = file->next) { - if (file->name && strcmp(file->name, name_absolute) == 0) { + if (file->name && file->stat.st_dev == new.st_dev && + file->stat.st_ino == new.st_ino) { existing = file; break; } diff --git a/vis.h b/vis.h @@ -189,8 +189,6 @@ void vis_update(Vis*); * @rst * .. note:: If the given file name is already opened in another window, * the underlying File object is shared. - * .. warning:: This duplication detection is currently based on normalized, - * absolute file names. TODO: compare inodes instead. * @endrst */ bool vis_window_new(Vis*, const char *filename);