Author Topic: Preserving file permissions  (Read 19162 times)

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Preserving file permissions
« on: March 29, 2014, 10:23:18 pm »
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 to get permissions and chmod to set them. It only works for regular save, not save as.
« Last Edit: March 29, 2014, 10:28:02 pm by dmoore »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Preserving file permissions
« Reply #1 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.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: Preserving file permissions
« Reply #2 on: March 30, 2014, 01:55:20 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...

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: Preserving file permissions
« Reply #3 on: March 30, 2014, 04:53:53 pm »
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...
« Last Edit: March 30, 2014, 05:54:24 pm by dmoore »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Preserving file permissions
« Reply #4 on: March 31, 2014, 08:37:42 am »
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.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: Preserving file permissions
« Reply #5 on: March 31, 2014, 02:54:03 pm »
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)

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Preserving file permissions
« Reply #6 on: March 31, 2014, 11:20:39 pm »
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.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: Preserving file permissions
« Reply #7 on: April 12, 2014, 05:01:45 pm »
Ping. Anyone have any thoughts on what is the right #ifdef to use to detect systems with stat?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Preserving file permissions
« Reply #8 on: April 14, 2014, 12:19:50 am »
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: Preserving file permissions
« Reply #9 on: April 14, 2014, 12:40:52 am »
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?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Preserving file permissions
« Reply #10 on: April 14, 2014, 01:09:56 am »
You could probably add some global macro which could be checked if we have posix or not.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]