Class: RStyx::Server::DirectoryOnDisk

Inherits:
SDirectory show all
Defined in:
lib/rstyx/server.rb

Overview

Class representing a directory on the host filesystem. While there’s no real problem with using this class directly, it’s probably better to use FileOnDisk instead (it will return a DirectoryOnDisk instance when passed a directory.

Instance Attribute Summary

Attributes inherited from SFile

#atime, #gid, #mtime, #muid, #name, #parent, #permissions, #uid, #version

Instance Method Summary collapse

Methods inherited from SDirectory

#<<, #[], #child_count, #child_exists?, #newfile, #read, #remove_child

Methods inherited from SFile

#add_changelistener, #add_client, #appendonly?, #auth?, #can_setlength?, #can_setmode?, #can_setmtime?, #can_setname?, #client, #client_connected, #client_disconnected, #contents_changed, #delete, #directory?, #exclusive?, #filetype, #full_path, #length, #length=, #mode, #mode=, #num_clients, #qid, #read, #remove, #remove_client, #remove_dead_clients, #rename, #reply_read, #reply_write, #set_mtime, #stat, #uuid, #version_incr, #write

Constructor Details

#initialize(path, name, perm) ⇒ DirectoryOnDisk

Create a new DirectoryOnDisk instance. This



2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
# File 'lib/rstyx/server.rb', line 2018

def initialize(path, name, perm)
  @name = name
  @path = File.expand_path(path)

  s = File.stat(@path)
  pwent = Etc.getpwuid(s.uid)
  grent = Etc.getgrgid(s.gid)
  argv = { :permissions => perm & s.mode, :apponly => false,
    :excl => false, :uid => pwent.name, :gid => grent.name }
  super(@name, argv)
  self.refresh(false)
end

Instance Method Details

#refresh(update_children = true) ⇒ Object

Read all metadata from the underlying directory. If update_children is true, all immediate children of this directory will be refreshed as well. – TODO: check for files deleted in the host filesystem ++



2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
# File 'lib/rstyx/server.rb', line 2039

def refresh(update_children=true)
  s = File.stat(@path)
  @mtime = s.mtime
  @atime = s.atime
  unless update_children
    return
  end
  Dir.foreach(@path) do |file|
    # do not treat . or .. as valid files
    if file == '.' || file == '..'
      next
    end
    # Check if a file with this name is already known
    sf = self[file]
    if sf.nil?
      begin
        filepath = @path + File::SEPARATOR + file
        sf = FileOnDisk.new(filepath)
        if sf.is_a?(SDirectory)
          sf.permissions = @permissions
        else
          # This is an SFile (a FileOnDisk).  Set to the same permissions
          # as the host directory without the execute flags.
          sf.permissions = @permissions & 0666
        end
        self << sf
      rescue Exception => e
        # This should be impossible
      end
    else
      # The file is already known to us.  Refresh the file metadata
      # but do not descend into subdirectories (could lead to deep
      # recursion).
      if (sf.is_a?(SDirectory))
        sf.refresh(false)
      else
        sf.refresh
      end
    end
  end
end