PathUtils

Public Class Methods

flock(lock_file, unlink_file = true) click to toggle source

PathUtils.flock(lock_file) { block } -> nil

Create a file lock for the duration of the provided block @param lock_file [String] path including file to use for locking @param unlink_file [true, false] should lock file be removed when lock released?

# File lib/openshift-origin-common/utils/path_utils.rb, line 87
def flock(lock_file, unlink_file = true)
  File.open(lock_file, File::RDWR|File::CREAT|File::TRUNC, 0600) do |lock|
    lock.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
    lock.flock(File::LOCK_EX)

    begin
      yield(lock)
    ensure
      FileUtils.rm_f(lock_file) if unlink_file
      lock.flock(File::LOCK_UN) unless lock.closed?
    end
  end
end
join(string, *smth) click to toggle source

PathUtils.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 76
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 34
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 48
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
oo_lchown(user, group, *list) click to toggle source

Created to mimic oo_chown, but symbolic links are NOT dereferenced.

# File lib/openshift-origin-common/utils/path_utils.rb, line 59
def oo_lchown(user, group, *list)
  user  = pu_get_uid(user)
  group = pu_get_gid(group)

  File.lchown(user, group, *list)
end

Public Instance Methods

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

  EtcUtils.gid(group)
end
pu_get_uid(user) click to toggle source
# File lib/openshift-origin-common/utils/path_utils.rb, line 103
def pu_get_uid(user)
  return nil unless user

  EtcUtils.uid(user)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.