Class: Ftpd::FileInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/ftpd/file_info.rb

Overview

Information about a file object (file, directory, symlink, etc.)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ FileInfo

Create a new instance. See the various attributes for argument details.

Parameters:

  • opts (Hash)

    The file attributes

Options Hash (opts):

  • :ftype (String)

    The file type

  • :group (String)

    The group name

  • :identifier (String)

    The object’s identifier

  • :mode (Integer)

    The mode bits

  • :mtime (Time)

    The modification time

  • :nlink (Integer)

    The number of hard links

  • :owner (String)

    The owner name

  • :size (Integer)

    The size

  • :path (String)

    The object’s path



91
92
93
94
95
96
97
98
99
100
101
# File 'lib/ftpd/file_info.rb', line 91

def initialize(opts)
  @ftype = opts[:ftype]
  @group = opts[:group]
  @identifier = opts[:identifier]
  @mode = opts[:mode]
  @mtime = opts[:mtime]
  @nlink = opts[:nlink]
  @owner = opts[:owner]
  @path = opts[:path]
  @size = opts[:size]
end

Instance Attribute Details

#ftypeString (readonly)

One of:

  • ‘file’

  • ‘directory’

  • ‘characterSpecial’

  • ‘blockSpecial’

  • ‘fifo’

  • ‘link’

  • ‘socket’

  • ‘unknown’

Returns:

  • (String)

    The file’s type, as returned by File.lstat



20
21
22
# File 'lib/ftpd/file_info.rb', line 20

def ftype
  @ftype
end

#groupString (readonly)

Returns The group name.

Returns:

  • (String)

    The group name



24
25
26
# File 'lib/ftpd/file_info.rb', line 24

def group
  @group
end

#identifierString (readonly)

This uniquely identifies the file: Two objects with the same identifier are expected to refer to the same file or directory.

On a disk file system, might be dev.inode, e.g. “8388621.48598”

This is optional and does not have to be set. If set, it is used in EPLF output.

Returns:

  • (String)

    The object’s identifier



75
76
77
# File 'lib/ftpd/file_info.rb', line 75

def identifier
  @identifier
end

#modeInteger (readonly)

The bits are:

* 0 - others have execute permission
* 1 - others have write permission
* 2 - others have read permission
* 3 - group has execute permission
* 4 - group has write permission
* 5 - group has read permission
* 6 - owner has execute permission
* 7 - owner has write permission
* 8 - owner has read permission
* 9 - sticky bit
* 10 - set-group-ID bit
* 11 - set UID bit

Other bits may be present; they are ignored

Returns:

  • (Integer)

    The mode bits, as returned by File::Stat#mode



42
43
44
# File 'lib/ftpd/file_info.rb', line 42

def mode
  @mode
end

#mtimeTime (readonly)

Returns The modification time.

Returns:

  • (Time)

    The modification time



46
47
48
# File 'lib/ftpd/file_info.rb', line 46

def mtime
  @mtime
end

Returns The number of hard links.

Returns:

  • (Integer)

    The number of hard links



50
51
52
# File 'lib/ftpd/file_info.rb', line 50

def nlink
  @nlink
end

#ownerString (readonly)

Returns The owner name.

Returns:

  • (String)

    The owner name



54
55
56
# File 'lib/ftpd/file_info.rb', line 54

def owner
  @owner
end

#pathString (readonly)

Returns The object’s path.

Returns:

  • (String)

    The object’s path



62
63
64
# File 'lib/ftpd/file_info.rb', line 62

def path
  @path
end

#sizeInteger (readonly)

Returns The size, in bytes.

Returns:

  • (Integer)

    The size, in bytes



58
59
60
# File 'lib/ftpd/file_info.rb', line 58

def size
  @size
end

Instance Method Details

#directory?Boolean

Returns true if the object is a directory.

Returns:

  • (Boolean)

    true if the object is a directory



111
112
113
# File 'lib/ftpd/file_info.rb', line 111

def directory?
  @ftype == 'directory'
end

#file?Boolean

Returns true if the object is a file.

Returns:

  • (Boolean)

    true if the object is a file



105
106
107
# File 'lib/ftpd/file_info.rb', line 105

def file?
  @ftype == 'file'
end