Jul 6, 2013

Changing default behavior of File::chmod

File::chmod has been around for a long time, and is really stable, and really hasn't changed since 1999. It is far more user friendly than the chmod()  in core Perl. I recently used it for an interview test. It took me a few times to get right however because it's default behavior in symchmod() mode is to use the systems umask. I find this to be very confusing behavior. I actually thought it was a bug at first, and asked for comaint since it hadn't been updated in so long. Now that I realize it's intentional I'm unsure how to best proceed. On one hand I believe that the most obvious behavior (mimicking unix chmod) should be the default, on the other changing something that has been around this long... So I'm writing this blog post. What do you think? should I preserve the behavior? if not I'm aiming for a long deprecation cycle. Unfortunately because it used package variables for this setting, I haven't come up with a way to deprecate code wise that won't be annoying.

Regardless of what I do with this, there'll be a new release that has proper metadata, tests rewritten with Test::More, etc.

2 comments:

  1. I currently use File::chmod. Yes, the API is a bit weird. But I'd vote for leaving it alone and creating a modern alternative, e.g. File::Mode, File::Perm or something.

    We recently have experienced too many breakage in the Perl-land already. With Perl I used to just be able to run a 10-15 years old script without problem, and that's what's great about Perl. But with recent Perl...

    Just my 2 cents.

    ReplyDelete
  2. are you using symchmod mode? e.g. chmod('-r') not chmod(0777)? do you have $File::chmod::UMASK set explicitly? if you're not using symchmod or have UMASK set explicitly your behavior won't change (if I decided to do this, amongst other things I have to go through cpan reverse deps to find out what people have been doing with it).

    I simply find this behavior not only unexpected, because I was doing chmod('-x') on files and it was removing write's too.. why? my umask is 0022, and it was applying that. I've been known to set umask to 0077, which means the default behavior of chmod changes depending on the environment of system it's on. Now I think it's a neat feature, so I don't intend to remove it, I'm just considering forcing people to set the flag if they want this behavior.

    I do appreciate the feedback, given further explanation would I be breaking your scripts?

    ReplyDelete

No trolling, profanity, or flame wars :: My Blog, my rules! No crying or arguing about them.