module PathUtils

Public Class Methods

join(string, *smth) click to toggle source

#join(string, …) -> path

Returns a new string formed by joining the strings using File::SEPARATOR.

Differs from File.join in as much as Pathname is used to sanitize and canonize the path.

PathUtils.join("usr", "mail", "gumby")   #=> "usr/mail/gumby"
# File lib/openshift-origin-common/utils/path_utils.rb, line 63
def join(string, *smth)
  Pathname.new(File.join(string, smth)).cleanpath.to_path
end
oo_chown(user, group, list, options = {}) click to toggle source

Method #oo_chown wrapper for FileUtils.chown.

Created because an error in FileUtils.chown where an all digit user or group name is assumed to be a uid or a gid. Mongoids can be all numeric.

# File lib/openshift-origin-common/utils/path_utils.rb, line 32
def oo_chown(user, group, list, options = {})
  user  = pu_get_uid(user)
  group = pu_get_gid(group)

  FileUtils.chown(user, group, list, options)
end
oo_chown_R(user, group, list, options = {}) click to toggle source

Method #oo_chown_R wrapper for FileUtils.chown_R.

Created because an error in FileUtils.chown where an all digit user or group name is assumed to be a uid or a gid. Mongoids can be all numeric.

# File lib/openshift-origin-common/utils/path_utils.rb, line 46
def oo_chown_R(user, group, list, options = {})
  user  = pu_get_uid(user)
  group = pu_get_gid(group)

  FileUtils.chown_R(user, group, list, options)
end

Public Instance Methods

pu_get_gid(group) click to toggle source
# File lib/openshift-origin-common/utils/path_utils.rb, line 83
def pu_get_gid(group)
  return nil unless group

  case group
    when Integer
      group < 4294967296 ? group : Etc.getgrnam(group.to_s).gid
    when /\A\d{1,10}\z/
      group.to_i
    else
      Etc.getgrnam(group).gid
  end
end
pu_get_uid(user) click to toggle source
# File lib/openshift-origin-common/utils/path_utils.rb, line 69
def pu_get_uid(user)
  return nil unless user
  case user
    when Integer
      user < 4294967296 ? user : Etc.getpwnam(user.to_s).uid
    when /\A\d{1,10}\z/
      user.to_i
    else
      Etc.getpwnam(user).uid
  end
end

Private Instance Methods

join(string, *smth) click to toggle source

#join(string, …) -> path

Returns a new string formed by joining the strings using File::SEPARATOR.

Differs from File.join in as much as Pathname is used to sanitize and canonize the path.

PathUtils.join("usr", "mail", "gumby")   #=> "usr/mail/gumby"
# File lib/openshift-origin-common/utils/path_utils.rb, line 63
def join(string, *smth)
  Pathname.new(File.join(string, smth)).cleanpath.to_path
end
oo_chown(user, group, list, options = {}) click to toggle source

Method #oo_chown wrapper for FileUtils.chown.

Created because an error in FileUtils.chown where an all digit user or group name is assumed to be a uid or a gid. Mongoids can be all numeric.

# File lib/openshift-origin-common/utils/path_utils.rb, line 32
def oo_chown(user, group, list, options = {})
  user  = pu_get_uid(user)
  group = pu_get_gid(group)

  FileUtils.chown(user, group, list, options)
end
oo_chown_R(user, group, list, options = {}) click to toggle source

Method #oo_chown_R wrapper for FileUtils.chown_R.

Created because an error in FileUtils.chown where an all digit user or group name is assumed to be a uid or a gid. Mongoids can be all numeric.

# File lib/openshift-origin-common/utils/path_utils.rb, line 46
def oo_chown_R(user, group, list, options = {})
  user  = pu_get_uid(user)
  group = pu_get_gid(group)

  FileUtils.chown_R(user, group, list, options)
end