Class: FPM::Fry::Chroot
- Inherits:
-
Object
- Object
- FPM::Fry::Chroot
- 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
-
#base ⇒ Object
readonly
Returns the value of attribute base.
Instance Method Summary collapse
-
#entries(path) ⇒ Array<String>
Returns all directory entries like Dir.entries.
-
#find(path) {|entry| ... } ⇒ Object
Yields all entries recursively like Find.find.
-
#initialize(base) ⇒ Chroot
constructor
A new instance of Chroot.
-
#lstat(file) ⇒ File::Stat
Stats a file without following the last symlink like File.lstat.
-
#open(path, *args, &block) ⇒ Object
Opens a file like File.open.
-
#stat(file) ⇒ File::Stat
Stats a file like File.stat.
Constructor Details
#initialize(base) ⇒ Chroot
Returns a new instance of Chroot.
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
#base ⇒ Object (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.
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.
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.
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.
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.
68 69 70 |
# File 'lib/fpm/fry/chroot.rb', line 68 def stat(file) File.stat(rebase(file)) end |