Class Ole::Storage::FileClass
In: lib/ole/storage/file_system.rb
Parent: Object
String Data Lpstr Clsid Lpwstr Section Enumerable DateTime FileTime Constants Variant::Constants Storage\n[lib/ole/storage/base.rb\nlib/ole/storage/file_system.rb\nlib/ole/storage/meta_data.rb] PropertySet lib/ole/storage/file_system.rb lib/ole/types/property_set.rb lib/ole/types/base.rb Constants Constants Variant Types Ole dot/m_9_0.png

Methods

delete   directory?   dirent_from_path   exist?   exists?   expand_path   file?   new   new   open   read   rename   size   size?   stat   unlink  

Classes and Modules

Class Ole::Storage::FileClass::Stat

Public Class methods

[Source]

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

Public Instance methods

delete(*paths)

Alias for unlink

[Source]

     # File lib/ole/storage/file_system.rb, line 141
141:                         def directory? path
142:                                 dirent = @ole.dirent_from_path path
143:                                 dirent and dirent.dir?
144:                         end
exist?(path)

Alias for exists?

[Source]

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

[Source]

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

[Source]

     # File lib/ole/storage/file_system.rb, line 136
136:                         def file? path
137:                                 dirent = @ole.dirent_from_path path
138:                                 dirent and dirent.file?
139:                         end

explicit wrapper instead of alias to inhibit block

[Source]

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

[Source]

     # File lib/ole/storage/file_system.rb, line 146
146:                         def open path, mode='r', &block
147:                                 if IO::Mode.new(mode).create?
148:                                         begin
149:                                                 dirent = dirent_from_path path
150:                                         rescue Errno::ENOENT
151:                                                 # maybe instead of repeating this everywhere, i should have
152:                                                 # a get_parent_dirent function.
153:                                                 parent_path, basename = File.split expand_path(path)
154:                                                 parent = @ole.dir.send :dirent_from_path, parent_path, path
155:                                                 parent.children << dirent = Dirent.new(@ole, :type => :file, :name => basename)
156:                                         end
157:                                 else
158:                                         dirent = dirent_from_path path
159:                                 end
160:                                 dirent.open mode, &block
161:                         end

[Source]

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

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.…

[Source]

     # File lib/ole/storage/file_system.rb, line 200
200:                         def rename from_path, to_path
201:                                 # check what we want to rename from exists. do it this
202:                                 # way to allow directories.
203:                                 dirent = @ole.dirent_from_path from_path
204:                                 raise Errno::ENOENT, from_path unless dirent
205:                                 # delete what we want to rename to if necessary
206:                                 begin
207:                                         unlink to_path
208:                                 rescue Errno::ENOENT
209:                                         # we actually get here, but rcov doesn't think so. add 1 + 1 to
210:                                         # keep rcov happy for now... :)
211:                                         1 + 1
212:                                 end
213:                                 # reparent the dirent
214:                                 from_parent_path, from_basename = File.split expand_path(from_path)
215:                                 to_parent_path, to_basename = File.split expand_path(to_path)
216:                                 from_parent = @ole.dir.send :dirent_from_path, from_parent_path, from_path
217:                                 to_parent = @ole.dir.send :dirent_from_path, to_parent_path, to_path
218:                                 from_parent.children.delete dirent
219:                                 # and also change its name
220:                                 dirent.name = to_basename
221:                                 to_parent.children << dirent
222:                                 0
223:                         end

[Source]

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

[Source]

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

[Source]

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

crappy copy from Dir.

[Source]

     # File lib/ole/storage/file_system.rb, line 226
226:                         def unlink(*paths)
227:                                 paths.each do |path|
228:                                         dirent = @ole.dirent_from_path path
229:                                         # i think we should free all of our blocks from the
230:                                         # allocation table.
231:                                         # i think if you run repack, all free blocks should get zeroed,
232:                                         # but currently the original data is there unmodified.
233:                                         open(path) { |f| f.truncate 0 }
234:                                         # remove ourself from our parent, so we won't be part of the dir
235:                                         # tree at save time.
236:                                         parent_path, basename = File.split expand_path(path)
237:                                         parent = @ole.dir.send :dirent_from_path, parent_path, path
238:                                         parent.children.delete dirent
239:                                 end
240:                                 paths.length # hmmm. as per ::File ?
241:                         end

Private Instance methods

orig_path is just so that we can use the requested path in the error messages even if it has been already modified

[Source]

     # File lib/ole/storage/file_system.rb, line 122
122:                         def dirent_from_path path, orig_path=nil
123:                                 orig_path ||= path
124:                                 dirent = @ole.dirent_from_path path
125:                                 raise Errno::ENOENT,  orig_path unless dirent
126:                                 raise Errno::EISDIR, orig_path if dirent.dir?
127:                                 dirent
128:                         end

[Validate]