Method: FakeFS::File.chmod

Defined in:
lib/fakefs/file.rb

.chmod(new_mode, filename) ⇒ Object



300
301
302
303
304
305
306
307
308
309
310
# File 'lib/fakefs/file.rb', line 300

def self.chmod(new_mode, filename)
  # chmod's mode can either be passed in in absolute mode, or symbolic mode
  # for reference: https://ruby-doc.org/stdlib-2.2.2/libdoc/fileutils/rdoc/FileUtils.html#method-c-chmod
  # if the mode is passed in symbolic mode we must convert it to absolute mode
  is_absolute_mode = new_mode.is_a? Numeric
  unless is_absolute_mode
    current_mode = FileSystem.find(filename).mode
    new_mode = convert_symbolic_chmod_to_absolute(new_mode, current_mode)
  end
  FileSystem.find(filename).mode = 0o100000 + new_mode
end