lucc / nvimpager

Use nvim as a pager to view manpages, diffs, etc with nvim's syntax highlighting
Other
386 stars 20 forks source link

File "..." no longer available #66

Closed copy closed 2 years ago

copy commented 2 years ago

(this bug appeared after upgrading from 0.10.2.r8.g499f43c to 0.10.4.r25.g8211fa5).

neovimpager throws the above error when an underlying file is deleted while it's opened in nvimpager. This happens, for example, during git commands (apparently git deletes the file before the editor is closed).

lucc commented 2 years ago

Can you tell me which version of neovim you are using or maybe which other conditions have to be fulfilled? (Maybe your init file?)

I can not currently reproduce this. I did

git checkout 499f43c
./nvimpager -p README.md
# in another window
rm README.md

with no error, and the same with 8211fa5.

copy commented 2 years ago

This is on nvim v0.7.0 without any config (PAGER='nvimpager -- -u NONE'). You may need to run :checktime manually, maybe your terminal or window manager doesn't send focus events (since I run -u NONE I guess it's somehow built-in, but I'm not sure).

That said, the issue doesn't seem to be the fact that nvim{,pager} checks for deleted files, but rather that the file is deleted early. If I delete README.md, I see the warning both in 499f43c and 499f43c (which may or may not be an issue; other pagers don't behave like that, but it has never affected me).

Comparing the output of strace:

% git checkout 499f43c
HEAD is now at 499f43c ci: show nvim --version for reference
% PAGER="$PWD/nvimpager -- -u NONE" strace -fo strace-499f43c git log
# :checktime doesn't trigger the error
% git checkout 8211fa5 
Previous HEAD position was 499f43c ci: show nvim --version for reference
HEAD is now at 8211fa5 Remove unused travis file
% PAGER="$PWD/nvimpager -- -u NONE" strace -fo strace-8211fa5 git log
# :checktime triggers the error
% grep -e 'execve(' -e 'unlink' -e 'exit(' strace-499f43c
26783 21:39:51.456569 execve("/usr/bin/git", ["git", "log"], 0x7ffd9e791ab8 /* 88 vars */) = 0
26784 21:39:51.464958 execve("/bin/sh", ["/bin/sh", "-c", "/tmp/nvimpager/nvimpager -- -u N"..., "/tmp/nvimpager/nvimpager -- -u N"...], 0x55d0429c6ca0 /* 93 vars */ <unfinished ...>
26784 21:39:51.469998 execve("/tmp/nvimpager/nvimpager", ["/tmp/nvimpager/nvimpager", "--", "-u", "NONE"], 0x5604027b66e0 /* 93 vars */ <unfinished ...>
26784 21:39:51.471410 execve("/usr/bin/bash", ["bash", "/tmp/nvimpager/nvimpager", "--", "-u", "NONE"], 0x7ffd81954b50 /* 93 vars */ <unfinished ...>
26785 21:39:51.478128 execve("/usr/bin/mktemp", ["mktemp"], 0x55ec546c24f0 /* 95 vars */) = 0
26786 21:39:51.480976 execve("/usr/bin/cat", ["cat"], 0x55ec546c24f0 /* 95 vars */) = 0
26787 21:39:51.490902 execve("/usr/bin/nvim", ["nvim", "-R", "-u", "NORC", "--cmd", "set rtp+=$RUNTIME | lua nvimpage"..., "/tmp/tmp.FCJQMU4ySM", "-u", "NONE", "--cmd", "lua nvimpager.stage1()", "-c", "lua nvimpager.stage2()"], 0x55ec546d8a10 /* 95 vars */) = 0
26789 21:39:51.504544 execve("/usr/bin/ps", ["/usr/bin/ps", "-p", "26783", "-o", "comm="], 0x561f4fc17f90 /* 99 vars */ <unfinished ...>
26790 21:39:51.571295 execve("/usr/bin/ps", ["/usr/bin/ps", "-p", "26783", "-o", "ppid="], 0x561f4fc17f90 /* 99 vars */ <unfinished ...>
26788 21:39:54.507305 exit(0)           = ?
26787 21:39:54.514034 unlink("/home/fabian/.local/share/nvim/swap//%tmp%tmp.FCJQMU4ySM.swp") = 0
26787 21:39:54.515315 unlink("/tmp/nvimcXQjkh/0") = 0
26787 21:39:54.515549 unlink("/tmp/nvimcXQjkh/0") = -1 ENOENT (No such file or directory)
26794 21:39:54.528300 execve("/usr/bin/rm", ["rm", "-f", "/tmp/tmp.FCJQMU4ySM"], 0x55ec546d8a10 /* 95 vars */) = 0
26794 21:39:54.532540 unlinkat(AT_FDCWD</tmp/nvimpager>, "/tmp/tmp.FCJQMU4ySM", 0) = 0
% grep -e 'execve(' -e 'unlink' -e 'exit(' strace-8211fa5
26856 21:40:19.134381 execve("/usr/bin/git", ["git", "log"], 0x7ffd9a2f8ba8 /* 88 vars */) = 0
26857 21:40:19.142779 execve("/bin/sh", ["/bin/sh", "-c", "/tmp/nvimpager/nvimpager -- -u N"..., "/tmp/nvimpager/nvimpager -- -u N"...], 0x55d84c0e1ca0 /* 93 vars */ <unfinished ...>
26857 21:40:19.147941 execve("/tmp/nvimpager/nvimpager", ["/tmp/nvimpager/nvimpager", "--", "-u", "NONE"], 0x555e257826e0 /* 93 vars */ <unfinished ...>
26857 21:40:19.149368 execve("/usr/bin/bash", ["bash", "/tmp/nvimpager/nvimpager", "--", "-u", "NONE"], 0x7ffc20005460 /* 93 vars */ <unfinished ...>
26858 21:40:19.156177 execve("/usr/bin/mktemp", ["mktemp"], 0x557ad5334610 /* 96 vars */) = 0
26859 21:40:19.159212 execve("/usr/bin/cat", ["cat"], 0x557ad5334610 /* 96 vars */) = 0
26857 21:40:19.169461 execve("/usr/bin/nvim", ["nvimpager", "-R", "-u", "NORC", "--cmd", "set rtp+=$RUNTIME | lua nvimpage"..., "/tmp/tmp.LumPlWZirY", "-u", "NONE", "--cmd", "lua nvimpager.stage1()", "-c", "lua nvimpager.stage2()"], 0x557ad534b3e0 /* 95 vars */) = 0
26861 21:40:19.183298 execve("/usr/bin/ps", ["/usr/bin/ps", "-p", "26856", "-o", "comm="], 0x56420606cd90 /* 99 vars */ <unfinished ...>
26862 21:40:19.251116 execve("/usr/bin/ps", ["/usr/bin/ps", "-p", "26856", "-o", "ppid="], 0x56420606cd90 /* 99 vars */ <unfinished ...>
26857 21:40:19.317002 unlink("/home/fabian/.local/share/nvim/swap//%tmp%nvimpager.swp") = 0
26857 21:40:19.319040 unlink("/tmp/tmp.LumPlWZirY") = 0
26860 21:40:22.730914 exit(0)           = ?
26857 21:40:22.737317 unlink("/home/fabian/.local/share/nvim/swap//%tmp%tmp.LumPlWZirY.swp") = 0
26857 21:40:22.737764 unlink("/tmp/nvim3dA2R0/0") = 0
26857 21:40:22.737819 unlink("/tmp/nvim3dA2R0/0") = -1 ENOENT (No such file or directory)

For some reason, the behaviour is very different between the two versions. When using 499f43c nvimpager execves "rm", "-f", "/tmp/tmp.FCJQMU4ySM" after the nvim progress exits. When using 8211fa5 unlink is called directly, shortly after nvim starts. Looks like it may be related to https://github.com/lucc/nvimpager/commit/54edebf91f4f31457c0c9a09b13fd01d4e9b8302.

lucc commented 2 years ago

I came up with an idea. Can you check if the branch "issue66" works for you?

copy commented 2 years ago

The issue66 branch fixes the issue, cheers!