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



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

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



18
19
20
# File 'lib/ftpd/file_info.rb', line 18

def ftype
  @ftype
end

#groupString (readonly)

Returns The group name.

Returns:

  • (String)

    The group name



22
23
24
# File 'lib/ftpd/file_info.rb', line 22

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



73
74
75
# File 'lib/ftpd/file_info.rb', line 73

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



40
41
42
# File 'lib/ftpd/file_info.rb', line 40

def mode
  @mode
end

#mtimeTime (readonly)

Returns The modification time.

Returns:

  • (Time)

    The modification time



44
45
46
# File 'lib/ftpd/file_info.rb', line 44

def mtime
  @mtime
end

Returns The number of hard links.

Returns:

  • (Integer)

    The number of hard links



48
49
50
# File 'lib/ftpd/file_info.rb', line 48

def nlink
  @nlink
end

#ownerString (readonly)

Returns The owner name.

Returns:

  • (String)

    The owner name



52
53
54
# File 'lib/ftpd/file_info.rb', line 52

def owner
  @owner
end

#pathString (readonly)

Returns The object’s path.

Returns:

  • (String)

    The object’s path



60
61
62
# File 'lib/ftpd/file_info.rb', line 60

def path
  @path
end

#sizeInteger (readonly)

Returns The size, in bytes.

Returns:

  • (Integer)

    The size, in bytes



56
57
58
# File 'lib/ftpd/file_info.rb', line 56

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



109
110
111
# File 'lib/ftpd/file_info.rb', line 109

def directory?
  @ftype == 'directory'
end

#file?Boolean

Returns true if the object is a file.

Returns:

  • (Boolean)

    true if the object is a file



103
104
105
# File 'lib/ftpd/file_info.rb', line 103

def file?
  @ftype == 'file'
end