how to watch a File System for change

穿精又带淫゛_ 提交于 2019-12-12 15:30:00

问题


I'm doing a project in a course at my university on distributed systems. I'm planning on creating something similar to Dropbox ( getdropbox.com ), but with some sort of non-centralized peer-to-peer twist to it. For this i need some method of detecting change in a directory structure. How do you think Dropbox do this? Their implementation works remarkably well. I'm wonder if they use FileSystemWatcher from the win32 api on windows, and something similar and platform dependent on Linux and Mac.


回答1:


To my knowledge, DropBox (and the like) uses a Windows service (or a daemon on the Linux/Mac side) to monitor the file system. Creating such in .Net is very easy and this scenario is usually the textbook example for Windows Services. I believe doing a similar thing in C++ would be fairly straight forward as well.

Here's a link to a simple tutorial for .Net on how to create a service on Windows. All that you would need to do for your solution is add your monitor logic in the Timer.Tick() event.

http://www.developer.com/net/csharp/article.php/2173801




回答2:


Under Mac OS X Leopard there's the FSEvents API that allows you to register for notifications of file-system changes:

http://googlemac.blogspot.com/2008/03/file-system-change-logger-for-leopard.html




回答3:


On the Linux side, there's the horribly undocumented inotify. If you don't mind using glib, there's the GFileMonitor class, which is really easy to use. I don't think it's portable though, so it would be Linux-only.




回答4:


eduffy mentioned inotify ....

I saw this a while back, based on inotify. called incron, it adds cron like functionality to incron.

http://www.linux.com/feature/144666



来源:https://stackoverflow.com/questions/317571/how-to-watch-a-file-system-for-change

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!