Class: Zip::ZipFileSystem::ZipFsDir

Inherits:
Object
  • Object
show all
Defined in:
lib/zip/zipfilesystem.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mappedZip) ⇒ ZipFsDir

Returns a new instance of ZipFsDir.



372
373
374
# File 'lib/zip/zipfilesystem.rb', line 372

def initialize(mappedZip)
  @mappedZip = mappedZip
end

Instance Attribute Details

#file=(value) ⇒ Object (writeonly)

Sets the attribute file

Parameters:

  • value

    the value to set the attribute file to.



376
377
378
# File 'lib/zip/zipfilesystem.rb', line 376

def file=(value)
  @file = value
end

Instance Method Details

#chdir(aDirectoryName) ⇒ Object



398
399
400
401
402
403
# File 'lib/zip/zipfilesystem.rb', line 398

def chdir(aDirectoryName)
  unless @file.stat(aDirectoryName).directory?
    raise Errno::EINVAL, "Invalid argument - #{aDirectoryName}"
  end
  @mappedZip.pwd = @file.expand_path(aDirectoryName)
end

#chroot(*args) ⇒ Object

Raises:

  • (NotImplementedError)


438
439
440
# File 'lib/zip/zipfilesystem.rb', line 438

def chroot(*args)
	raise NotImplementedError, "The chroot() function is not implemented"
end

#delete(entryName) ⇒ Object Also known as: rmdir, unlink



425
426
427
428
429
430
# File 'lib/zip/zipfilesystem.rb', line 425

def delete(entryName)
  unless @file.stat(entryName).directory?
    raise Errno::EINVAL, "Invalid argument - #{entryName}"
  end
  @mappedZip.remove(entryName)
end

#entries(aDirectoryName) ⇒ Object



405
406
407
408
409
# File 'lib/zip/zipfilesystem.rb', line 405

def entries(aDirectoryName)
  entries = []
  foreach(aDirectoryName) { |e| entries << e }
  entries
end

#foreach(aDirectoryName) ⇒ Object



411
412
413
414
415
416
417
418
419
420
421
422
423
# File 'lib/zip/zipfilesystem.rb', line 411

def foreach(aDirectoryName)
  unless @file.stat(aDirectoryName).directory?
    raise Errno::ENOTDIR, aDirectoryName
  end
  path = @file.expand_path(aDirectoryName).ensure_end("/")

  subDirEntriesRegex = Regexp.new("^#{path}([^/]+)$")
  @mappedZip.each { 
    |fileName|
    match = subDirEntriesRegex.match(fileName)
    yield(match[1]) unless match == nil
  }
end

#mkdir(entryName, permissionInt = 0) ⇒ Object



434
435
436
# File 'lib/zip/zipfilesystem.rb', line 434

def mkdir(entryName, permissionInt = 0)
  @mappedZip.mkdir(entryName, permissionInt)
end

#new(aDirectoryName) ⇒ Object



378
379
380
# File 'lib/zip/zipfilesystem.rb', line 378

def new(aDirectoryName)
  ZipFsDirIterator.new(entries(aDirectoryName))
end

#open(aDirectoryName) ⇒ Object



382
383
384
385
386
387
388
389
390
391
392
393
# File 'lib/zip/zipfilesystem.rb', line 382

def open(aDirectoryName)
  dirIt = new(aDirectoryName)
  if block_given?
    begin
      yield(dirIt)
      return nil
    ensure
      dirIt.close
    end
  end
  dirIt
end

#pwdObject Also known as: getwd



395
# File 'lib/zip/zipfilesystem.rb', line 395

def pwd; @mappedZip.pwd; end