diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2019-04-29 19:20:22 +0200 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2019-04-29 19:55:42 +0200 |
commit | 24b7462b3cbf9a70f07f0a8e8da562a365cdc37a (patch) | |
tree | 59bc0d9761679ba4f0528bf591e0adab2b934622 /src/nvim/memline.c | |
parent | a0d723db55cf2b81e3bd9271cda9b1b58a5c9f3c (diff) | |
download | rneovim-24b7462b3cbf9a70f07f0a8e8da562a365cdc37a.tar.gz rneovim-24b7462b3cbf9a70f07f0a8e8da562a365cdc37a.tar.bz2 rneovim-24b7462b3cbf9a70f07f0a8e8da562a365cdc37a.zip |
vim-patch:8.1.0313: information about a swap file is unavailable
Problem: Information about a swap file is unavailable.
Solution: Add swapinfo(). (Enzo Ferber)
https://github.com/vim/vim/commit/00f123a56585363cd13f062fd3bb123efcfaa664
Diffstat (limited to 'src/nvim/memline.c')
-rw-r--r-- | src/nvim/memline.c | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 662eda3c7c..3e18c8559a 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -1457,10 +1457,41 @@ static char *make_percent_swname(const char *dir, char *name) static bool process_still_running; #endif -/* - * Give information about an existing swap file. - * Returns timestamp (0 when unknown). - */ +/// Return information found in swapfile "fname" in dictionary "d". +/// This is used by the swapinfo() function. +void get_b0_dict(const char *fname, dict_T *d) +{ + int fd; + struct block0 b0; + + if ((fd = os_open(fname, O_RDONLY, 0)) >= 0) { + if (read_eintr(fd, &b0, sizeof(b0)) == sizeof(b0)) { + if (b0_magic_wrong(&b0)) { + tv_dict_add_str(d, S_LEN("error"), xstrdup("magic number mismatch")); + } else { + // We have swap information. + tv_dict_add_str(d, S_LEN("version"), xstrdup((char *)b0.b0_version)); + tv_dict_add_str(d, S_LEN("user"), xstrdup((char *)b0.b0_uname)); + tv_dict_add_str(d, S_LEN("host"), xstrdup((char *)b0.b0_hname)); + tv_dict_add_str(d, S_LEN("fname"), xstrdup((char *)b0.b0_fname)); + + tv_dict_add_nr(d, S_LEN("pid"), char_to_long(b0.b0_pid)); + tv_dict_add_nr(d, S_LEN("mtime"), char_to_long(b0.b0_mtime)); +#ifdef CHECK_INODE + tv_dict_add_nr(d, S_LEN("inode"), char_to_long(b0.b0_ino)); +#endif + } + } else { + tv_dict_add_str(d, S_LEN("error"), xstrdup("Cannot read file")); + } + close(fd); + } else { + tv_dict_add_str(d, S_LEN("error"), xstrdup("Cannot open file")); + } +} + +/// Give information about an existing swap file. +/// Returns timestamp (0 when unknown). static time_t swapfile_info(char_u *fname) { assert(fname != NULL); |