[bug] The plugin fails to load the stores session, when /home or the workspace path is a symlink
Basic checklist
- [ x] I have read the README
- [ x] I have read the wiki
- [ x] I have read
:h session,:h mksession, and:h sessionoptions - [ x] I have searched through existing/closed issues
- [ x] I have checked if the recommended config has changed, and if that solves my issue.
Expected vs Actual behavior
On FreeBSD the /home directory is by default a symlink to /usr/home.
If the Session.store function tries to save the session, it calls Session.info and fails because nil was returned.
The reason why Session.info fails is because it receives the argument spath which was created by a call to vim.loop.cwd().
vim.loop.cwd() returns the realpath of the current working directory, which on FreeBSD is for ~/projects/abc the path /usr/home/USER/projects/abc.
For reference the code in question
https://github.com/GnikDroy/projections.nvim/blob/f18a8505f84f45a0fe024cafca5b969447f63cd5/lua/projections/session.lua#L17-L37
Here the info function extracts the workspace_path and then compares this path with the path of the workspace set in the configuration. The path of the Workspace is a Path object.
In Path.new the given spath is normalized https://github.com/GnikDroy/projections.nvim/blob/f18a8505f84f45a0fe024cafca5b969447f63cd5/lua/projections/path.lua#L33
The result of calling vim.fs.normalize("~/projects") is "/home/USER/projects".
This lets this condition https://github.com/GnikDroy/projections.nvim/blob/f18a8505f84f45a0fe024cafca5b969447f63cd5/lua/projections/session.lua#L25
fail since "/usr/home/USER/projects" is unequal to "/home/USER/projects".
Of course this can be avoided, when I use the realpath (usr/home/USER/projects) in projections_workspaces.json.
But what bothers me is that it failed silently and no session was saved, but I also have no good solution.
Ideally Workspace.path should hold the real path and only compare it with a real path, but I don't know if lua/neovim can get the information without relying on shell or libs.
Anyway It is at least something which could be documented.
Environment information
- Neovim version: v0.9.5
- Operating system: FreeBSD 14.0
- Projections branch/commit hash: f18a8505f84f45a0fe024cafca5b969447f63cd5
- Projections config:
require("projections").setup({ })
- Projections workspace file (find this at
stdpath('data') .. 'projections_workspaces.json':
[
{
"path": "~/projects/",
"patterns": []
}
]
- Result of
ls -lahfrom projection sessions folder (find this atstdpath('cache') .. 'projections_sessions/'. Remove personal information as needed.
- Result of
tree -a -L 2from every configured workspace (both config and workspace json file). Remove personal and unnecessary information as needed.
I don't have the tree command on my system and I think this is irrelevant.
To Reproduce Steps to reproduce the behavior:
- Create a symlink to the real workspace path
- Try to store a session with Session.store for the symlink path
Ok. So, I believe projections needs to handle symlinks correctly. I can perhaps make Path.__eq(a, b) method work with symlinks. I will see what I can do.
In the meanwhile, you can try to see if the dev branch has this issue (likely still there). It tries to avoid vim.loop, which is currently vim.uv in nvim-0.10. This is supposed to be the "new" projections. I will put up a migration notice in a couple of days.
Thanks for the reply.
I have checked with the dev branch (0e36a2d2a9a7ff160618bbe636bc26365d4e0487) there is still the same problem.vim.fn.getcwd() also return the real path.
Having the same issue :P