xolox / vim-session

Extended session management for Vim (:mksession on steroids)
http://peterodding.com/code/vim/session/
961 stars 80 forks source link

force recreation of directory containing temporary file #166

Closed d-e-s-o closed 7 years ago

d-e-s-o commented 7 years ago

Apparently, Vim's tempname() function upon first invocation creates a temporary directory along with a temporary file below it. Subsequent invocations assume the temporary directory to be still existent. If that is not the case, attempting to access to temporary file will fail. In many cases we have seen errors popping up because this temporary directory was removed and no attempt to recreate it was made by Vim. For lack of a better solution and my unfamiliarity with Vim script (paired with an aversion towards it), this change simply forcefully attempts to recreate the directory and ignores any errors doing so.

inkarkat commented 7 years ago

Why would the temp directory vanish; this is not normal behavior? I would rather fix the root cause than introducing kludges in all sorts of plugins.

Some Linux distros clean /tmp on reboot. But that's fine, as it doesn't affect the (short-term) use by this plugin.

d-e-s-o commented 7 years ago

It is not "normal" behavior, no. Various programs create orphaned files/directories below /tmp on my system. Since it is placed in a ramdisk I clean it on occasion when the system is running for a longer time.

In my opinion this cleaning should not screw up vim-session. I don't I see why it needs to create a temporary directory instead of just a temporary file below /tmp/. There may be a valid reason for it, I did not look closely and I wrote this patch more then a year ago. At this point I am just trying to destage any changes that may benefit upstream. If you have a better solution please let me know. If you don't see that as an issue that's fine as well, I can keep the patch locally; though I disagree in that I believe this is an issue. If such a directory is needed to be present Vim should hold a file descriptor to it open and create the file relative to this file descriptor (or something along those lines).

inkarkat commented 7 years ago

@d-e-s-o Thanks for the explanation. I still think that working around this in session.vim (and potentially many many other plugins) is the wrong approach. If you think your use case (of cleaning the temp directory while Vim is running) is valid and important, I would suggest to open an issue at Vim's bug tracker, or directly discuss this on the vim_dev mailing list. Either they agree and fix this in Vim (so all plugins benefit from it), or they tell you this is unsupported (and then you should stop cleaning the temp dir).

d-e-s-o commented 7 years ago

Fair enough. Thanks for taking the time to consider.