Class: Ole::Storage::FileClass

### Home Classes Methods

### In Files

- lib/ole/storage/file_system.rb

### Parent

Object

### Namespace

- CLASS Ole::Storage::FileClass::Stat

### Methods

- ::new
- #delete
- #directory?
- #exist?
- #exists?
- #expand_path
- #file?
- #new
- #open
- #read
- #rename
- #size
- #size?
- #stat
- #unlink

### Files

- ChangeLog
- README

### Class/Module Index

Quicksearch

- Ole
- Ole::IOMode
- Ole::IOMode::Constants
- Ole::Storage
- Ole::Storage::AllocationTable
- Ole::Storage::AllocationTable::Big
- Ole::Storage::AllocationTable::Small
- Ole::Storage::DirClass
- Ole::Storage::DirClass::Dir
- Ole::Storage::Dirent
- Ole::Storage::FileClass
- Ole::Storage::FileClass::Stat
- Ole::Storage::Header
- Ole::Storage::MetaData
- Ole::Storage::RangesIOMigrateable
- Ole::Storage::RangesIOResizeable
- Ole::Types
- Ole::Types::Clsid
- Ole::Types::Data
- Ole::Types::FileTime
- Ole::Types::Lpstr
- Ole::Types::Lpwstr
- Ole::Types::PropertySet
- Ole::Types::PropertySet::Constants
- Ole::Types::PropertySet::Section
- Ole::Types::Variant
- Ole::Types::Variant::Constants
- RangesIO

No matching classes.

# Ole::Storage::FileClass

### Public Class Methods

new(ole) click to toggle source

    # File lib/ole/storage/file_system.rb, line 105
    def initialize ole
      @ole = ole
    end

### Public Instance Methods

delete(*paths) click to toggle source
Alias for: unlink
directory?(path) click to toggle source

    # File lib/ole/storage/file_system.rb, line 147
    def directory? path
      dirent = @ole.dirent_from_path path
      dirent and dirent.dir?
    end

exist?(path) click to toggle source
Alias for: exists?
exists?(path) click to toggle source

    # File lib/ole/storage/file_system.rb, line 137
    def exists? path
      !!@ole.dirent_from_path(path)
    end

Also aliased as: exist?
expand_path(path) click to toggle source

    # File lib/ole/storage/file_system.rb, line 109
    def expand_path path
      # its already absolute if it starts with a '/'
      unless path =~ /^\//
        # get the raw stored pwd value (its blank for root)
        pwd = @ole.dir.instance_variable_get :@pwd
        path = "#{pwd}/#{path}"
      end
      # at this point its already absolute. we use File.expand_path
      # just for the .. and . handling
      # No longer use RUBY_PLATFORM =~ /win/ as it matches darwin. better way?
      if File::ALT_SEPARATOR != "\\"
        File.expand_path(path)
      else
        File.expand_path(path)[2..-1]
      end
    end

file?(path) click to toggle source

    # File lib/ole/storage/file_system.rb, line 142
    def file? path
      dirent = @ole.dirent_from_path path
      dirent and dirent.file?
    end

new(path, mode='r') click to toggle source

explicit wrapper instead of alias to inhibit block

    # File lib/ole/storage/file_system.rb, line 170
    def new path, mode='r'
      open path, mode
    end

open(path, mode='r', &block) click to toggle source

    # File lib/ole/storage/file_system.rb, line 152
    def open path, mode='r', &block
      if IOMode.new(mode).create?
        begin
          dirent = dirent_from_path path
        rescue Errno::ENOENT
          # maybe instead of repeating this everywhere, i should have
          # a get_parent_dirent function.
          parent_path, basename = File.split expand_path(path)
          parent = @ole.dir.send :dirent_from_path, parent_path, path
          parent << dirent = Dirent.new(@ole, :type => :file, :name => basename)
        end
      else
        dirent = dirent_from_path path
      end
      dirent.open mode, &block
    end

read(path) click to toggle source

    # File lib/ole/storage/file_system.rb, line 196
    def read path
      open path, &:read
    end

rename(from_path, to_path) click to toggle source

most of the work this function does is moving the dirent between 2 parents. the actual name changing is quite simple. File.rename can move a file into another folder, which is why i've done it too, though i think its not always possible...

FIXME File.rename can be used for directories too....

    # File lib/ole/storage/file_system.rb, line 206
    def rename from_path, to_path
      # check what we want to rename from exists. do it this
      # way to allow directories.
      dirent = @ole.dirent_from_path from_path
      raise Errno::ENOENT, from_path unless dirent
      # delete what we want to rename to if necessary
      begin
        unlink to_path
      rescue Errno::ENOENT
        # we actually get here, but rcov doesn't think so. add 1 + 1 to
        # keep rcov happy for now... :)
        1 + 1
      end
      # reparent the dirent
      to_parent_path, to_basename = File.split expand_path(to_path)
      from_parent = dirent.parent
      to_parent = @ole.dir.send :dirent_from_path, to_parent_path, to_path
      from_parent.delete dirent, false
      # and also change its name
      dirent.name = to_basename
      to_parent << dirent
      0
    end

size(path) click to toggle source

    # File lib/ole/storage/file_system.rb, line 174
    def size path
      dirent_from_path(path).size
    rescue Errno::EISDIR
      # kind of arbitrary. I'm getting 4096 from ::File, but
      # the zip tests want 0.
      0
    end

size?(path) click to toggle source

    # File lib/ole/storage/file_system.rb, line 182
    def size? path
      dirent_from_path(path).size
      # any other exceptions i need to rescue?
    rescue Errno::ENOENT, Errno::EISDIR
      nil
    end

stat(path) click to toggle source

    # File lib/ole/storage/file_system.rb, line 189
    def stat path
      # we do this to allow dirs.
      dirent = @ole.dirent_from_path path
      raise Errno::ENOENT, path unless dirent
      Stat.new dirent
    end

unlink(*paths) click to toggle source

    # File lib/ole/storage/file_system.rb, line 230
    def unlink(*paths)
      paths.each do |path|
        dirent = dirent_from_path path
        dirent.parent.delete dirent
      end
      paths.length # hmmm. as per ::File ?
    end

Also aliased as: delete

[Validate]

Generated with the Darkfish Rdoc Generator 2.