fs.watch : knowing when a copy is finished ?

651 views
Skip to first unread message

Naouak

unread,
Feb 28, 2012, 2:11:29 PM2/28/12
to nod...@googlegroups.com
Hi,

My aim is to do an automatic operation on files dropped into a directory over the network.

To be sure that no one try to modify that file during the execution of the operation, I want to move it from the drop area to another dir. With fs.watch I'm able to tell when a new file arrives with the rename event. The problem is when the transfer is not fast enough, I will get the event before the file has finished transfer.

So my question is : Is there a way to know if transfer is done before doing anything ?

Thanks for your answers,

Naouak, Grade 2 de Kobal.
Site web: http://www.naouak.net

fent

unread,
Feb 28, 2012, 2:39:54 PM2/28/12
to nod...@googlegroups.com
If you don't know the file size, you could use node-growing-file https://github.com/felixge/node-growing-file

It uses a timeout to determine if a file is finished growing or not.

Naouak

unread,
Feb 28, 2012, 2:46:20 PM2/28/12
to nod...@googlegroups.com
So the best way would be to check whether the file is still growing to start the process.
I will do that.

Thanks for the answer.

Naouak, Grade 2 de Kobal.
Site web: http://www.naouak.net


--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Mark Hahn

unread,
Feb 28, 2012, 2:48:49 PM2/28/12
to nod...@googlegroups.com
Isn't there some way to see if the file is still open by someone else?

Matt

unread,
Feb 28, 2012, 2:49:48 PM2/28/12
to nod...@googlegroups.com
That's extremely fragile advice. Just use an atomic move/rename. i.e. copy it to <name>.tmp and then move it to <name> when done. Don't read any files with suffix .tmp (or use dot files, even better, though if things break crappy sysadmins might not "see" the files).

Matt.

Naouak

unread,
Feb 28, 2012, 2:56:46 PM2/28/12
to nod...@googlegroups.com
Matt: 
Does it mean that I would have at least the double of filesize to be able to do anything with it ?
How come does it protect me from anything ? I mean, if the copy is local won't it be done before the end of the network one ?

Naouak, Grade 2 de Kobal.
Site web: http://www.naouak.net


Matt

unread,
Feb 28, 2012, 7:03:18 PM2/28/12
to nod...@googlegroups.com
On Tue, Feb 28, 2012 at 2:56 PM, Naouak <tar...@gmail.com> wrote:
Matt: 
Does it mean that I would have at least the double of filesize to be able to do anything with it ?

No.
 
How come does it protect me from anything ?

Because you write your code to ignore those temporary files.
 
I mean, if the copy is local won't it be done before the end of the network one ?

I don't understand the question.

Matt.

Mark Hahn

unread,
Feb 28, 2012, 7:09:27 PM2/28/12
to nod...@googlegroups.com
The confusion is whether the sender or the receiver is doing the copy from .tmp.  The sender does the copy (or rename) in order to make this work right.

Matt

unread,
Feb 28, 2012, 7:14:52 PM2/28/12
to nod...@googlegroups.com
Well if the receiver was doing the copy there wouldn't be any issues, as it could just wait for itself to finish :)

On Tue, Feb 28, 2012 at 7:09 PM, Mark Hahn <ma...@hahnca.com> wrote:
The confusion is whether the sender or the receiver is doing the copy from .tmp.  The sender does the copy (or rename) in order to make this work right.

Mark Hahn

unread,
Feb 28, 2012, 7:19:55 PM2/28/12
to nod...@googlegroups.com
I was just pointing out the source of the confusion on this thread - i didn't do a very good job of it though.
Reply all
Reply to author
Forward
0 new messages