为什么不能像Windows OS X锁文件,并在复制到Samba共享? [英] Why doesn't OS X lock files like windows does when copying to a Samba share?

查看:155
本文介绍了为什么不能像Windows OS X锁文件,并在复制到Samba共享?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有使用.net FileSystemWatcher的观看Samba网络共享的视频文件的项目。当它看到一个文件,它添加到一间code队列。当文件被离队,他们被移动到本地目录,其中的过程,然后连接codeS文件到几种不同的格式,并吐出他们到输出目录。

I have a project that uses the .net FileSystemWatcher to watch a Samba network share for video files. When it sees a file, it adds it to an encode queue. When files are dequeued, they are moved to a local directory where the process then encodes the file to several different formats and spits them out to an output directory.

的问题的产生是由于视频文件都这么大,它通常需要几分钟为他们复制完全进入网络目录,因此,当一个文件被出列,它可能会或可能不会完全完成被复制到网络分享。当文件被从Windows计算机复制,我能够解决它,因为试图将一个正在复制抛出IOException的文件。我只是捕获异常和重试每隔几秒钟,直到它完成复制。

The problem arises because the video files are so big, that it often takes several minutes for them to copy completely into the network directory, so when a file is dequeued, it may or may not have completely finished being copied to the network share. When the file is being copied from a windows machine, I am able to work around it because trying to move a file that is still being copied throws an IOException. I simply catch the exception and retry every few seconds until it is done copying.

当一个文件从一台计算机运行OS X却投进Samba共享,即IOException异常没有抛出。而是,部分文件被复制到工作路径,然后不连接code,因为它不是一个有效的视频文件。

When a file is dropped into the Samba share from a computer running OS X however, that IOException is not thrown. Instead, a partial file is copied to the working directory which then fails to encode because it is not a valid video file.

所以我的问题是,有没有什么办法让FileSystemWatcher的等待文件发射它的创建事件之前完全写入(根据<一href="http://stackoverflow.com/questions/8733816/configuring-filesystemwatcher-such-that-it-raises-created-event-only-when-the-fi">this问题我认为这个问题的答案是不)?另外,有一种方式来获得从OS X复制到以类似于那些在窗口里的文件吗?或者,我需要找到观看Samba共享另一种解决方案?感谢您的帮助。

So my question is, is there any way to make the FileSystemWatcher wait for files to be completely written before firing its "Created" event (based on this question I think the answer to that question is "no")? Alternatively, is there a way to get files copied from OS X to behave similarly to those in windows? Or do I need to find another solution for watching the Samba share? Thanks for any help.

推荐答案

选项3。最好的办法是有一个过程,手表文件传入的份额。当它看到的文件,记下其大小和/或修改日期

Option 3. Your best bet is to have a process that watches the incoming share for files. When it sees a file, note its size and/or modification date.

然后,一定量的时间后(如,1或2秒),再看看。需要注意的是之前见过的任何文件,并比较他们的新的大小/ MOD日期你看到最后一次的人。

Then, after some amount of time (like, 1 or 2 seconds), look again. Note any files that were seen before and compare their new sizes/mod dates to the one you saw last time.

这是没有改变的某个时间足够长期间的任何文件(1秒?5S?)被认为是完成。

Any file that has not changed for some "sufficiently long" period of time (1s? 5s?) is considered "done".

一旦你已经完成的文件,移动/重命名文件到另一个目录。这是从你的加载过程可以运行此目录。它知道,只有那些完整的文件此目录中。

Once you have a "done" file, MOVE/rename that file to another directory. It is from THIS directory that your loading process can run. It "knows" that only files that are complete are in this directory.

有了这个两阶段的过程中,你可以以后可能进行验收的文件添加其他规则,因为所有的这些规则必须通过之前,该文件被移动到正确的临时区域(你可以检查格式,检查大小等),而不仅仅是文件存在一个简单的规则。

By having this two stage process, you are able to later possibly add other rules for acceptance of a file, since all of those rules must pass before the file gets moved to its proper staging area (you can check format, check size, etc.) beyond a simple rule of just file existence.

您购买过程可以依赖于文件的存在,无论是作为一个启动机构和重启机制。当这个过程发生故障后重新启动或者关机时,可以假设,在第二个登台的任何文件或者是新的或不完整的,并根据自己的内部状态,采取适当的行动。当处理完成后可以选择删除该文件,或将其移动到已完成区域进行归档或什么不是。

Your later process can rely on file existence, both as a start mechanism and a restart mechanism. When the process restarts after failure or shut down, it can assume that any files in the second staging are either new or incomplete and take appropriate action based on its own internal state. When the processing is done it can choose to either delete the file, or move it to a "finished" area for archiving or what not.

这篇关于为什么不能像Windows OS X锁文件,并在复制到Samba共享?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆