Class Ole::Storage::DirClass
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

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

pretty complete. like zip/zipfilesystem‘s implementation, i provide everything except chroot and glob. glob could be done with a glob to regex regex, 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.

Methods

chdir   delete   dirent_from_path   entries   foreach   getwd   mkdir   new   new   open   pwd   rmdir   unlink  

Classes and Modules

Class Ole::Storage::DirClass::Dir

Public Class methods

[Source]

     # File lib/ole/storage/file_system.rb, line 256
256:                         def initialize ole
257:                                 @ole = ole
258:                                 @pwd = ''
259:                         end

Public Instance methods

[Source]

     # File lib/ole/storage/file_system.rb, line 297
297:                         def chdir orig_path
298:                                 # make path absolute, squeeze slashes, and remove trailing slash
299:                                 path = @ole.file.expand_path(orig_path).gsub(/\/+/, '/').sub(/\/$/, '')
300:                                 # this is just for the side effects of the exceptions if invalid
301:                                 dirent_from_path path, orig_path
302:                                 if block_given?
303:                                         old_pwd = @pwd
304:                                         begin
305:                                                 @pwd = path
306:                                                 yield
307:                                         ensure
308:                                                 @pwd = old_pwd
309:                                         end
310:                                 else
311:                                         @pwd = path
312:                                         0
313:                                 end
314:                         end
delete(path)

Alias for rmdir

[Source]

     # File lib/ole/storage/file_system.rb, line 316
316:                         def entries path
317:                                 dirent = dirent_from_path path
318:                                 # Not sure about adding on the dots...
319:                                 entries = %w[. ..] + dirent.children.map(&:name)
320:                                 # do some checks about un-reachable files
321:                                 seen = {}
322:                                 entries.each do |n|
323:                                         Log.warn "inaccessible file (filename contains slash) - #{n.inspect}" if n['/']
324:                                         Log.warn "inaccessible file (duplicate filename) - #{n.inspect}" if seen[n]
325:                                         seen[n] = true
326:                                 end
327:                                 entries
328:                         end

[Source]

     # File lib/ole/storage/file_system.rb, line 330
330:                         def foreach path, &block
331:                                 entries(path).each(&block)
332:                         end
getwd()

Alias for pwd

there are some other important ones, like: chroot (!), glob etc etc. for now, i think

[Source]

     # File lib/ole/storage/file_system.rb, line 336
336:                         def mkdir path
337:                                 # as for rmdir below:
338:                                 parent_path, basename = File.split @ole.file.expand_path(path)
339:                                 # note that we will complain about the full path despite accessing
340:                                 # the parent path. this is consistent with ::Dir
341:                                 parent = dirent_from_path parent_path, path
342:                                 # now, we first should ensure that it doesn't already exist
343:                                 # either as a file or a directory.
344:                                 raise Errno::EEXIST, path if parent/basename
345:                                 parent.children << Dirent.new(@ole, :type => :dir, :name => basename)
346:                                 0
347:                         end

as for file, explicit alias to inhibit block

[Source]

     # File lib/ole/storage/file_system.rb, line 282
282:                         def new path
283:                                 open path
284:                         end

[Source]

     # File lib/ole/storage/file_system.rb, line 272
272:                         def open path
273:                                 dir = Dir.new path, entries(path)
274:                                 if block_given?
275:                                         yield dir
276:                                 else
277:                                         dir
278:                                 end
279:                         end

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

[Source]

     # File lib/ole/storage/file_system.rb, line 288
288:                         def pwd
289:                                 if @pwd.empty?
290:                                         '/'
291:                                 else
292:                                         @pwd
293:                                 end
294:                         end

[Source]

     # File lib/ole/storage/file_system.rb, line 349
349:                         def rmdir path
350:                                 dirent = dirent_from_path path
351:                                 raise Errno::ENOTEMPTY, path unless dirent.children.empty?
352: 
353:                                 # now delete it, how to do that? the canonical representation that is
354:                                 # maintained is the root tree, and the children array. we must remove it
355:                                 # from the children array.
356:                                 # we need the parent then. this sucks but anyway:
357:                                 # we need to split the path. but before we can do that, we need
358:                                 # to expand it first. eg. say we need the parent to unlink
359:                                 # a/b/../c. the parent should be a, not a/b/.., or a/b.
360:                                 parent_path, basename = File.split @ole.file.expand_path(path)
361:                                 # this shouldn't be able to fail if the above didn't
362:                                 parent = dirent_from_path parent_path
363:                                 # note that the way this currently works, on save and repack time this will get
364:                                 # reflected. to work properly, ie to make a difference now it would have to re-write
365:                                 # the dirent. i think that Ole::Storage#close will handle that. and maybe include a
366:                                 # #repack.
367:                                 parent.children.delete dirent
368:                                 0 # hmmm. as per ::Dir ?
369:                         end
unlink(path)

Alias for rmdir

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 263
263:                         def dirent_from_path path, orig_path=nil
264:                                 orig_path ||= path
265:                                 dirent = @ole.dirent_from_path path
266:                                 raise Errno::ENOENT,  orig_path unless dirent
267:                                 raise Errno::ENOTDIR, orig_path unless dirent.dir?
268:                                 dirent
269:                         end

[Validate]