Module: Koch::Ogm

Included in:
CreateDirectory, CreateFile
Defined in:
lib/koch/ogm.rb

Overview

This module applies changes to of file’s or directory’s owner, group, mode.

Instance Method Summary collapse

Instance Method Details

#apply_groupObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/koch/ogm.rb', line 20

def apply_group
  return if @group.nil?

  @group = Etc.getgrnam(@group).gid if @group.is_a? String
  return if stat.gid == @group

  @changed = true
  maybe("Group changed: #{name} #{stat.gid} to #{@group}") do
    File.chown nil, @group, name
  end
end

#apply_modeObject



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/koch/ogm.rb', line 32

def apply_mode
  return if @mode.nil?

  @mode = Integer(@mode, 8) if @mode.is_a? String
  curr_mode = stat.mode & 0o7777
  return if curr_mode == @mode

  @changed = true
  maybe(format("Mode changed: #{name} old: %o new: %o", (curr_mode || 0), @mode)) do
    File.chmod @mode, name
  end
end

#apply_ownerObject



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/koch/ogm.rb', line 8

def apply_owner
  return if @owner.nil?

  @owner = Etc.getpwnam(@owner).uid if @owner.is_a? String
  return if stat.uid == @owner

  @changed = true
  maybe("Owner changed: #{name} #{stat.uid} to #{@owner}") do
    File.chown @owner, nil, name
  end
end