[TxMt] Re: [TM2] File Mode changes on Save
Brad Choate
brad at bradchoate.com
Tue Dec 20 04:14:46 UTC 2011
On Dec 19, 2011, at 7:51 PM, Alexander Rudy wrote:
> I'm having some weird behavior with saving in textmate 2. Some files I save seem to magically acquire executable permissions (i.e. the file mode gains +x on user, group and other) when I hit save. This is a little annoying (nosetests doesn't pick up files with executable permissions by default) and possibly a security hole. However, it only seems to happen to *some* files and *some* saves. I can't even seem to reproduce it regularly.
>
> Has anyone else seen this behavior or been able to reproduce it in a given context? I'd love to at least be able to track this behavior down and understand when/why it happens.
It's by design. This is happening due to a command in the "Source" bundle:
Source -> Other Actions -> Make Script Executable (ruby)
(mislabeled, since it applies to scripts other than Ruby)
The scope selector for this command is: source.ruby, source.perl, source.python
so, it will be invoked when a Ruby, Perl or Python script is saved. The "Semantic Class" setting for this command is the key thing here: "callback.document.did-save". The command runs upon saving one of these file types.
The command does a couple of tests before it makes the script executable. It tests if the target script is already executable. If it is, then it does nothing else. It also tests for a "#!" at the start of the script (a shebang line, indicating it is meant to be run as a command script). If it doesn't start with that, then the script won't be made executable.
So, if you have Python unit tests, you should be able to omit the "#!/usr/bin/python" or "#!env python" line at the top of the file. nosetests should pick them up even without this line.
-Brad
More information about the textmate
mailing list