[vim/vim] `writefile`: optionally update the corresponding buffer's `mtime` (PR #15857)

26 views
Skip to first unread message

Rob Pilling

unread,
Oct 11, 2024, 1:15:32 PM10/11/24
to vim/vim, Subscribed

This permits plugins which use writefile() to write to a buffer, to also update the buffer's mtime, so future :writes won't then think there's been a change to the file outside of vim


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/15857

Commit Summary

  • 6e5ee5d buffer.c: make buflist_findname_stat() public
  • 7db0820 `buf_store_time`: optionally update `mtime_read{,_ns}`
  • 217e1e1 `writefile(data, fname, "t")` to a buffer updates the buffer's mtime

File Changes

(8 files)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/15857@github.com>

Rob Pilling

unread,
Oct 11, 2024, 1:20:25 PM10/11/24
to vim/vim, Push

@bobrippling pushed 2 commits.

  • e2bec43 `buf_store_time`: optionally update `mtime_read{,_ns}`
  • 1b3200e `writefile(data, fname, "t")` to a buffer updates the buffer's mtime


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/15857/before/217e1e1644071ed437cb5ec05e0ba49feb8cef28/after/1b3200e1bb8a8aeb75265754fdea52e5b97f4a67@github.com>

Rob Pilling

unread,
Oct 11, 2024, 1:50:27 PM10/11/24
to vim/vim, Push

@bobrippling pushed 2 commits.

  • 1228aa4 `buf_store_time`: optionally update `mtime_read{,_ns}`
  • 1e7ea5f `writefile(data, fname, "t")` to a buffer updates the buffer's mtime

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/15857/before/1b3200e1bb8a8aeb75265754fdea52e5b97f4a67/after/1e7ea5fbc9fd5ba72f4ee69b03a60363a33a6077@github.com>

Rob Pilling

unread,
Oct 11, 2024, 3:39:46 PM10/11/24
to vim/vim, Subscribed

Test failure appears to be unrelated:

From test_popupwin.vim:
Found errors in Test_popup_beval():
Run 1, 18:00:10 - 18:00:23:
command line
  ..script /Users/runner/work/vim/vim/src/testdir/runtest.vim[607]
  ..function RunTheTest[57]
  ..Test_popup_beval[39]
  ..VerifyScreenDump

line 67: See dump file difference: call term_dumpdiff("testdir/failed/Test_popupwin_beval_3.dump", "testdir/dumps/Test_popupwin_beval_3.dump");
difference in line 4: "|4| @10|t+0#0000001#ffd7ff255|e|x|t| +0#0000000#ffffff0@58"


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/15857/c2408020955@github.com>

zeertzjq

unread,
Oct 11, 2024, 8:10:45 PM10/11/24
to vim/vim, Subscribed

@zeertzjq commented on this pull request.


In runtime/doc/builtin.txt:

> @@ -12417,6 +12417,10 @@ writefile({object}, {fname} [, {flags}])			*writefile()*
 		     When {flags} does not contain "S" or "s" then fsync() is
 		     called if the 'fsync' option is set.
 
+		't'  if the {fname} corresponds to a buffer, update that buffer's
+		     modified time so future writes to the buffer don't think there's
+		     changes outside of vim.
⬇️ Suggested change
-		     changes outside of vim.
+		     changes outside of Vim.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/15857/review/2363684727@github.com>

Rob Pilling

unread,
Oct 12, 2024, 4:22:43 AM10/12/24
to vim/vim, Push

@bobrippling pushed 1 commit.

  • d02c120 `writefile(data, fname, "t")` to a buffer updates the buffer's mtime

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/15857/before/1e7ea5fbc9fd5ba72f4ee69b03a60363a33a6077/after/d02c1203b0c3269bb01f34b59627118167e8cfea@github.com>

Rob Pilling

unread,
Oct 12, 2024, 4:23:05 AM10/12/24
to vim/vim, Subscribed

@bobrippling commented on this pull request.


In runtime/doc/builtin.txt:

> @@ -12417,6 +12417,10 @@ writefile({object}, {fname} [, {flags}])			*writefile()*
 		     When {flags} does not contain "S" or "s" then fsync() is
 		     called if the 'fsync' option is set.
 
+		't'  if the {fname} corresponds to a buffer, update that buffer's
+		     modified time so future writes to the buffer don't think there's
+		     changes outside of vim.

Thanks - sorted


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/15857/review/2363830521@github.com>

Gary Johnson

unread,
Oct 12, 2024, 4:34:32 AM10/12/24
to reply+ACY5DGBSF3HR4E3TTB...@reply.github.com, vim...@googlegroups.com
On 2024-10-12, Rob Pilling wrote:
> @bobrippling commented on this pull request.
>
> -------------------------------------------------------------------------------
>
> In runtime/doc/builtin.txt:
>
> > @@ -12417,6 +12417,10 @@ writefile({object}, {fname} [, {flags}]) *writefile()*
> When {flags} does not contain "S" or "s" then fsync() is
> called if the 'fsync' option is set.
>
> + 't' if the {fname} corresponds to a buffer, update that buffer's
> + modified time so future writes to the buffer don't think there's
> + changes outside of vim.

there's -> there have been

Regards,
Gary

vim-dev ML

unread,
Oct 12, 2024, 4:34:57 AM10/12/24
to vim/vim, vim-dev ML, Your activity


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/15857/c2408458609@github.com>

Christian Brabandt

unread,
Oct 12, 2024, 5:24:07 AM10/12/24
to vim/vim, vim-dev ML, Comment

Thanks. Can you plesae add a test? I suppose you could use :let mess=execute(':w') after using writefile() and then check, that mess does not contain the warning. Or perhaps use :checktime and check that W11 isn't returned.


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/15857/c2408473283@github.com>

Rob Pilling

unread,
Oct 14, 2024, 7:06:27 AM10/14/24
to vim/vim, vim-dev ML, Comment

On testing this, I'm not convinced it's that useful - my initial usecase was to do a background write to a slow filesystem, without locking up Vim's UI, but writefile is still called synchronously (even from a timer).

I need to find a different approach to write the file and then update vim's mtime, I'll put this into draft for now


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/15857/c2410879573@github.com>

Christian Brabandt

unread,
Oct 14, 2024, 3:44:32 PM10/14/24
to vim/vim, vim-dev ML, Comment

you may want to consider disabling the 'fsync' option.


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/15857/c2412077276@github.com>

Rob Pilling

unread,
Oct 15, 2024, 3:30:52 AM10/15/24
to vim/vim, vim-dev ML, Comment

Ah thank you, I'll see how well that helps


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/15857/c2413107544@github.com>

K.Takata

unread,
Oct 15, 2024, 3:59:03 AM10/15/24
to vim/vim, vim-dev ML, Comment

@k-takata commented on this pull request.


In src/proto/buffer.pro:

> +#ifdef UNIX
+buf_T *buflist_findname_stat(char_u *ffname, stat_T *stp);
+#endif

This file is generated by the cproto command. The #ifdef and #endif lines are not needed:

⬇️ Suggested change
-#ifdef UNIX
-buf_T *buflist_findname_stat(char_u *ffname, stat_T *stp);
-#endif
+buf_T *buflist_findname_stat(char_u *ffname, stat_T *stp);

However, the definitions of buflist_findname() and buflist_findname_stat() need to be adjusted to make cproto work. E.g.:

    buf_T *
buflist_findname(char_u *ffname)
{
#ifdef UNIX
    stat_T	st;

    if (mch_stat((char *)ffname, &st) < 0)
	st.st_dev = (dev_T)-1;
    return buflist_findname_stat(ffname, &st);
#else
    return buflist_findname_stat(ffname, NULL);
#endif
}

/*
 * Same as buflist_findname(), but pass the stat structure to avoid getting it
 * twice for the same file.
 * Returns NULL if not found.
 */
    buf_T *
buflist_findname_stat(
    char_u	*ffname,
    stat_T	*stp)
{
    buf_T	*buf;

    // Start at the last buffer, expect to find a match sooner.
    FOR_ALL_BUFS_FROM_LAST(buf)
	if ((buf->b_flags & BF_DUMMY) == 0 && !otherfile_buf(buf, ffname
#ifdef UNIX
		    , stp
#endif
		    ))
	    return buf;
    return NULL;
}


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: <vim/vim/pull/15857/review/2368473863@github.com>

Rob Pilling

unread,
Oct 16, 2024, 1:15:49 PM10/16/24
to vim/vim, vim-dev ML, Comment

Closed #15857.


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/15857/issue_event/14685100466@github.com>

Rob Pilling

unread,
Oct 16, 2024, 1:15:49 PM10/16/24
to vim/vim, vim-dev ML, Comment

Thanks for the review and comments - 'fsync' seems to have alleviated this so I'll close the PR (don't think there's further use in providing the ability to update a buffer's mtime for now)


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/15857/c2417442371@github.com>

Reply all
Reply to author
Forward
0 new messages