I finally got irritated enough by my scripts losing their execute permissions after being saved by C::B that I wrote a little plugin to preserve them:
https://github.com/spillz/codeblocks-python/tree/master/PreservePermissions
Wasn't sure whether to do this as a plugin or as a patch to the save routine in the SDK, so it's a plugin for now.
Notes:
* Linux only, because frankly permissions generally aren't used much on windows by most users, but if someone wants to patch for windows that's fine too.
* Uses system calls stat (http://linux.die.net/man/2/stat) to get permissions and chmod (http://linux.die.net/man/2/chmod) to set them. It only works for regular save, not save as.
I think it should be fixed in the SDK, no as plugin, because there is a changes for race conditions or sync issues.
Quote from: oBFusCATed on March 30, 2014, 01:33:11 PM
I think it should be fixed in the SDK, no as plugin, because there is a changes for race conditions or sync issues.
I was under the impression that NotifyPlugins was blocking and therefore synchronous. So race issues no more or less likely as a plugin I would think. Isn't the existing code already susceptible to arace issues anyway (because access to the original file is never locked) which in practice are never an issue?
But I can show you what a patch to the SDK would look like...
Attached is the alternative of an SDK patch. Wasn't sure what #IFDEF to use, so used __WXGTK__ for now.
Contrary to what I said about "Save As", one potential flaw is that when you overwrite an existing file with Save As, the permissions will be the same as the file you are overwriting. I can't decide if that's good or bad...
A check for platform::unix would probably be better. But you probably need to check for osx, too. I'm not sure what will happen with a cygwin builds thought.
Also the preserve_permissions argument is not used anywhere in the function, nor passed to false. So it should probably not be added.
Thanks for taking a look.
Isn't the platform stuff for runtime checks? We need a compile time check.
I put the function arg in for the case that we don't want to preserve permissions for SaveAs - but need to add the code. Maybe a better way is to have a wxString permissions_from argument, which is the file to take permissions from?
Cygwin should be fine I would think. Does OS X have stat? (And that's __wxMAC__ or something anyway isn't it, which isn't in the patch)
OSX is based on FreeBSD, so it is unix - thus most of the posix apis should work just fine.
But you're correct that the platform stuff is runtime only.
The wxString permissinsFrom parameter sounds fine to me.
Ping. Anyone have any thoughts on what is the right #ifdef to use to detect systems with stat?
Probably some of these: http://stackoverflow.com/questions/5919996/how-to-detect-reliably-mac-os-x-ios-linux-windows-in-c-preprocessor
I'd probably use __posix.
Thanks for the links.
This is hilariously comprehensive: http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system
I saw answers like this in a couple of places: http://stackoverflow.com/a/16107549/748925 so maybe this is better than __posix?
You could probably add some global macro which could be checked if we have posix or not.