Feature #2190

FileUtils::chmod - allow symbolic mode

Added by Suraj Kurapati almost 6 years ago. Updated over 4 years ago.

[ruby-core:26029]
Status:Closed
Priority:Normal
Assignee:Motohiro KOSAKI

Description

=begin
Hello,

I request that FileUtils::chmod() and FileUtils::chmod_R() accept
symbolic modes, which are strings like "u+x,g-w,o=" (see "symbolic
mode" in man chmod for details), in addition to the numeric modes
they currently accept.

If my request is fulfilled, the following would be equivalent:

FileUtils::chmod(0712, "file.txt")

FileUtils::chmod("u=rwx,g=x,o=w", "file.txt")

In addition, symbolic modes would allow delta/patch changes:

FileUtils::chmod("g+w", "file.txt")

This is not so easy with numeric modes, because you must
first read the current mode, apply your delta/patch mode
using a bitwise OR operation, and finally apply the new
numeric mode using FileUtils::chmod().

Thanks for your consideration.
=end

0001-FileUtils-chmod-to-symbolic-mode-added.patch Magnifier (6.6 KB) 三村 益隆, 05/17/2010 06:07 PM

Associated revisions

Revision 31407
Added by Motohiro KOSAKI over 4 years ago

  • lib/fileutils.rb (FileUtils#chmod): accept symbolic mode argument.
    The patch was written by takkanm. [Feature #2190]

  • lib/fileutils.rb (FileUtils#fu_mode): new helper function.

  • lib/fileutils.rb (FileUtils#symbolic_modes_to_i): ditto.

  • lib/fileutils.rb (FileUtils#mode_mask): ditto.

  • lib/fileutils.rb (FileUtils#user_mask): ditto.

  • test/fileutils/test_fileutils.rb (TestFileUtils#test_chmod_symbol_mode):
    new test for the above symbolic mode.

  • test/fileutils/test_fileutils.rb (TestFileUtils#test_chmod_R): ditto.

Revision 31407
Added by Motohiro KOSAKI over 4 years ago

  • lib/fileutils.rb (FileUtils#chmod): accept symbolic mode argument.
    The patch was written by takkanm. [Feature #2190]

  • lib/fileutils.rb (FileUtils#fu_mode): new helper function.

  • lib/fileutils.rb (FileUtils#symbolic_modes_to_i): ditto.

  • lib/fileutils.rb (FileUtils#mode_mask): ditto.

  • lib/fileutils.rb (FileUtils#user_mask): ditto.

  • test/fileutils/test_fileutils.rb (TestFileUtils#test_chmod_symbol_mode):
    new test for the above symbolic mode.

  • test/fileutils/test_fileutils.rb (TestFileUtils#test_chmod_R): ditto.

History

#1 Updated by Kazuhiro NISHIYAMA over 5 years ago

  • Category set to lib
  • Target version set to 2.0.0

=begin

=end

#2 Updated by 三村 益隆 about 5 years ago

=begin
Hi. I'm takkanm.

FileUtils:: chmod () that I wrote a patch to use the symbolic mode.
How about this?
=end

#3 Updated by Suraj Kurapati about 5 years ago

=begin
Thanks for your patch, takkanm! I hope the Ruby developers will
accept it into Ruby trunk. I have one small suggestion for you:

def fu_mode(mode, path)
  • mode.class == String ? symbolic_modes_to_i(mode, path) : mode
  • mode.is_a?(String) ? symbolic_modes_to_i(mode, path) : mode end

Greetings.
=end

#4 Updated by Evgeniy Dolzhenko almost 5 years ago

=begin
+1 Would like to see this it's way to the core, except that current_file_mode function doesn't seem to be really used anyway and can be removed:

  • def symbolic_modes_to_i(modes, path)
  • current_mode = current_file_mode(path)
  • current_mode = (File.stat(path).mode & 07777) ... =end

#5 Updated by ted cooper over 4 years ago

=begin
+1
we have a million chmod ... expressions lurking because of this omission. please accept this into trunk!
=end

#6 Updated by Motohiro KOSAKI over 4 years ago

  • Status changed from Open to Assigned
  • Assignee set to Motohiro KOSAKI

=begin
Hi

This request seems very reasonable to me. I'll review the patch later.
=end

#7 Updated by Motohiro KOSAKI over 4 years ago

  • Status changed from Assigned to Closed

#8 Updated by Motohiro KOSAKI over 4 years ago

I slightly change the testcase at r31415. because FreeBSD don't change sticky bit.

Thx.

Also available in: Atom PDF