Class: FPM::Fry::Chroot

Inherits:
Object
  • Object
show all
Defined in:
lib/fpm/fry/chroot.rb

Overview

Helper class for filesystem operations inside staging directory. Resolves all symlinks relativ to a given base directory.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base) ⇒ Chroot

Returns a new instance of Chroot.

Parameters:

  • base (String)

    filesystem base

Raises:

  • (ArgumentError)


10
11
12
13
# File 'lib/fpm/fry/chroot.rb', line 10

def initialize(base)
  raise ArgumentError, "Base #{base.inspect} is not a directory" unless File.directory? base
  @base = base
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



7
8
9
# File 'lib/fpm/fry/chroot.rb', line 7

def base
  @base
end

Instance Method Details

#entries(path) ⇒ Array<String>

Returns all directory entries like Dir.entries.

Parameters:

  • path (String)

Returns:

  • (Array<String>)

    entries



18
19
20
21
22
23
# File 'lib/fpm/fry/chroot.rb', line 18

def entries(path)
  dir = rebase(path)
  return Dir.entries(dir)
rescue => ex
  raise Fry::WithData(ex, path: path)
end

#find(path) {|entry| ... } ⇒ Object

Yields all entries recursively like Find.find.

Parameters:

  • path (String)

Yields:

  • entry

Yield Parameters:

  • entry (String)


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/fpm/fry/chroot.rb', line 39

def find(path, &block)
  if stat(path).directory?
    catch(:prune) do
      block.call(path)
      entries(path).each do | e |
        next if e == "."
        next if e == ".."
        ep = File.join(path,e)
        find(ep, &block)
      end
    end
  else
    block.call(path)
  end
  return nil
end

#lstat(file) ⇒ File::Stat

Stats a file without following the last symlink like File.lstat.

Parameters:

  • file (String)

Returns:

  • (File::Stat)

    stat

See Also:

  • FPM::Fry::Chroot.(File(File.lstat)


60
61
62
# File 'lib/fpm/fry/chroot.rb', line 60

def lstat(file)
  File.lstat(rebase(file, FOLLOW_ALL_BUT_LAST))
end

#open(path, *args, &block) ⇒ Object

Opens a file like File.open.

Parameters:

  • path (String)

See Also:

  • FPM::Fry::Chroot.(File(File.open)


28
29
30
31
32
33
# File 'lib/fpm/fry/chroot.rb', line 28

def open(path,*args,&block)
  file = rebase(path)
  return File.open(file,*args,&block)
rescue => ex
  raise Fry::WithData(ex, path: path)
end

#stat(file) ⇒ File::Stat

Stats a file like File.stat.

Parameters:

  • file (String)

Returns:

  • (File::Stat)

    stat

See Also:

  • FPM::Fry::Chroot.(File(File.stat)


68
69
70
# File 'lib/fpm/fry/chroot.rb', line 68

def stat(file)
  File.stat(rebase(file))
end