击败 Windows 上的 CIFS 文件缓存/强制“刷新”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4071183/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:31:18  来源:igfitidea点击:

Defeating CIFS file caching on Windows / forcing "refresh"

windowssambacifs

提问by Ben Hymanson

I'm modifying files on a UNIX system and accessing them on a Windows box. The server runs samba and there is some amount of caching done by the client. When I modify the file on the UNIX side, the only reliable way to see the new version of the file is to right click in Windows Explorer and select "refresh".

我正在 UNIX 系统上修改文件并在 Windows 机器上访问它们。服务器运行 samba,客户端完成了一些缓存。当我在 UNIX 端修改文件时,查看文件新版本的唯一可靠方法是在 Windows 资源管理器中右键单击并选择“刷新”。

I'm looking for the Windows API equivalent of right-clicking in Windows Explorer and selecting "refresh". There are other questions on SO about sending a message to Explorer to cause it to refresh, but that's not what I want: I don't care about the contents of the Explorer window and I would prefer to not even need one open to the target directory. I just want to integrate the cache-defeating effect into my program so I avoid seeing stale data.

我正在寻找相当于在 Windows 资源管理器中右键单击并选择“刷新”的 Windows API。关于向资源管理器发送消息以使其刷新,SO 上还有其他问题,但这不是我想要的:我不关心资源管理器窗口的内容,我什至希望不需要向目标打开一个目录。我只是想将缓存破坏效果集成到我的程序中,这样我就可以避免看到陈旧的数据。

采纳答案by Robie Basak

CIFS includes a notification system for updates. Explorer registers for this, and will reflect any changes that Samba sends it. I'm not aware of any other API mechanism to tell Windows that it needs to do a refresh.

CIFS 包括一个更新通知系统。Explorer 会为此注册,并将反映 Samba 发送给它的任何更改。我不知道有任何其他 API 机制可以告诉 Windows 它需要进行刷新。

Samba supports Linux inotify, so it should automatically pick up any changes to folders that Explorer is displaying and send Explorer updates.

Samba 支持 Linux inotify,因此它应该自动获取对 Explorer 显示的文件夹的任何更改并发送 Explorer 更新。

Are you using a recent-enough version of Samba, and has Samba been built with inotify support? This is obviously Linux only. For another Unix, you could implement equivalent functionality. The relevant code is in smbd/notify_internal.c.

您是否在使用最新版本的 Samba,并且 Samba 是否支持 inotify?这显然仅适用于 Linux。对于另一个 Unix,您可以实现等效的功能。相关代码在smbd/notify_internal.c.