class 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
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
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
Private Instance Methods
dirent_from_path(path, orig_path=nil)
click to toggle source
orig_path
is just so that we can use the requested path in the
error messages even if it has been already modified
# File lib/ole/storage/file_system.rb, line 128 def dirent_from_path path, orig_path=nil orig_path ||= path dirent = @ole.dirent_from_path path raise Errno::ENOENT, orig_path unless dirent raise Errno::EISDIR, orig_path if dirent.dir? dirent end