Sublime Forum

TMP file causing problems when file is saved

#1

Ok. second attempt at writing a post here.

I have been using ST2 for many months. It has become my editor of choice for coffeescript.

I have a cake file and several directories are constantly monitored to compile sources as they are updated.

All worked well until I purchased a license and installed ST3.

The problem is with the temporary file created when a file is saved to disk. It’s name is <source name~XXXXXXXXX.TMP.

What happens is that nodes.js seems to try to access this file for some reason as it monitors the directory for changes, and it’s not allowed. So it crashes with an EPERM error.

This does not happen with ST2, or with Netbeans, or with Notepad++.



Only ST3 has this problem.

The temporary file disappears as soon as one presses the Y key to answer the question ‘do you want to terminate the batch file Y/N’

And if one restarts the batch file, it compiles everything ok, and starts monitoring the directories. Until a file is saved again, and the problem occurs again too.

What can be done? Saving a file is such a basic operation that I can’t believe ST3 is trying to innovate in this area!! Could ST3 go back to the way files were saved in ST2? I’m sure no one would notice, except those who have spent hours like me on this problem, and these people will applaude.

0 Likes

#2

This is a bug in your directory monitoring program.

You can do ST2 style saving via setting atomic_save to false.

0 Likes

#3

That solved the problem. Many thanks!

It seems to be a bit difficult with nodes to follow what’s happening to the file as the original version is renamed, the new version is created,and the temporary file is deleted (which is how I understand the atomic saves work).

this doesn’t work:

fs.watch dir, (ev,fname)->
  return unless /\.coffee/.test fname
  compile fname

It’s normal as if the event is ‘rename’, the file is no longer a coffee file.

But this does not work either:

fs.watch dir, (ev,fname)->
  return unless /\.coffee/.test fname
  return unless ev is 'change'
  compile fname

so here the file is a coffee file, and it was changed. Strangely the program complains that it can’t access the TMP file.

Well, actually, I think the reason it does not work might be that it’s a coffee file that changed, but… it’s no longer a coffee file (it has become a TMP file). I don’t know how to get both the old and the new name of a file that was renamed… Nodes seems to give only a filename and an event name…

Probably the solution is simply to introduce a delay somewhere and wait for the dust to settle instead of reacting to each step of the process.

What’s a bit puzzling still is that files are only referred to by name. Not by file handle. Then how come Nodes complains that it can’t open a TMP file when I specifically try to compile a coffee file?

Anyway. It’s more a nodes problem than a Sublime problem. For now, the non-atomic saves do the trick so I’ll stick with them.

Thanks again for the quick reply.
Sublime Text is really an amazing product.

0 Likes