Parent

Namespace

Ole::Storage::DirClass

An instance of this class is supposed to provide similar methods to the class methods of Dir itself.

Fairly complete - like zip/zipfilesystem's implementation, i provide everything except chroot and glob. glob could be done with a glob to regex conversion, and then simply match in the entries array... although recursive glob complicates that somewhat.

Dir.chroot, Dir.glob, Dir.[], and Dir.tmpdir is the complete list of methods still missing.

Public Class Methods

new(ole) click to toggle source
# File lib/ole/storage/file_system.rb, line 253
def initialize ole
  @ole = ole
  @pwd = ''
end

Public Instance Methods

chdir(orig_path) click to toggle source
# File lib/ole/storage/file_system.rb, line 288
def chdir orig_path
  # make path absolute, squeeze slashes, and remove trailing slash
  path = @ole.file.expand_path(orig_path).squeeze('/').sub(/\/$/, '')
  # this is just for the side effects of the exceptions if invalid
  dirent_from_path path, orig_path
  if block_given?
    old_pwd = @pwd
    begin
      @pwd = path
      yield
    ensure
      @pwd = old_pwd
    end
  else
    @pwd = path
    0
  end
end
delete(path) click to toggle source
Alias for: rmdir
entries(path) click to toggle source
# File lib/ole/storage/file_system.rb, line 307
def entries path
  dirent = dirent_from_path path
  # Not sure about adding on the dots...
  entries = ]. ..] + dirent.children.map(&:name)
  # do some checks about un-reachable files
  seen = {}
  entries.each do |n|
    Log.warn "inaccessible file (filename contains slash) - #{n.inspect}" if n['/']
    Log.warn "inaccessible file (duplicate filename) - #{n.inspect}" if seen[n]
    seen[n] = true
  end
  entries
end
foreach(path, &block) click to toggle source
# File lib/ole/storage/file_system.rb, line 321
def foreach path, &block
  entries(path).each(&block)
end
getwd() click to toggle source
Alias for: pwd
mkdir(path) click to toggle source
# File lib/ole/storage/file_system.rb, line 325
def mkdir path
  parent_path, basename = File.split @ole.file.expand_path(path)
  # note that we will complain about the full path despite accessing
  # the parent path. this is consistent with ::Dir
  parent = dirent_from_path parent_path, path
  # now, we first should ensure that it doesn't already exist
  # either as a file or a directory.
  raise Errno::EEXIST, path if parent/basename
  parent << Dirent.new(@ole, :type => :dir, :name => basename)
  0
end
new(path) click to toggle source

as for file, explicit alias to inhibit block

# File lib/ole/storage/file_system.rb, line 276
def new path
  open path
end
open(path) click to toggle source
# File lib/ole/storage/file_system.rb, line 269
def open path
  dir = Dir.new path, entries(path)
  return dir unless block_given?
  yield dir
end
pwd() click to toggle source

pwd is always stored without the trailing slash. we handle the root case here

# File lib/ole/storage/file_system.rb, line 282
def pwd
  return '/' if @pwd.empty?
  @pwd
end
Also aliased as: getwd
rmdir(path) click to toggle source
# File lib/ole/storage/file_system.rb, line 337
def rmdir path
  dirent = dirent_from_path path
  raise Errno::ENOTEMPTY, path unless dirent.children.empty?
  dirent.parent.delete dirent
  0 # hmmm. as per ::Dir ?
end
Also aliased as: delete, unlink

[Validate]

Generated with the Darkfish Rdoc Generator 2.