Module: Ftpd::DiskFileSystem::List
- Includes:
- TranslateExceptions
- Included in:
- Ftpd::DiskFileSystem, ReadOnlyDiskFileSystem
- Defined in:
- lib/ftpd/disk_file_system.rb
Overview
DiskFileSystem mixin providing directory listing
Instance Method Summary collapse
-
#dir(ftp_path) ⇒ Array<String>
Expand a path that may contain globs into a list of paths of matching files and directories.
-
#file_info(ftp_path) ⇒ FileInfo
Get information about a single file or directory.
Methods included from TranslateExceptions
included, #translate_exception
Instance Method Details
#dir(ftp_path) ⇒ Array<String>
Expand a path that may contain globs into a list of paths of matching files and directories. The paths returned are fully qualified, relative to the root of the virtual file system.
For example, suppose these files exist on the physical file system:
/var/lib/ftp/foo/foo
/var/lib/ftp/foo/subdir/bar
/var/lib/ftp/foo/subdir/baz
and that the directory /var/lib/ftp is the root of the virtual file system. Then:
dir('foo') # => ['/foo']
dir('subdir') # => ['/subdir']
dir('subdir/*') # => ['/subdir/bar', '/subdir/baz']
dir('*') # => ['/foo', '/subdir']
Called for:
-
LIST
-
NLST
If missing, then these commands are not supported.
287 288 289 290 291 |
# File 'lib/ftpd/disk_file_system.rb', line 287 def dir(ftp_path) Dir[(ftp_path)].map do |path| path.sub(/^#{@data_dir}/, '') end end |
#file_info(ftp_path) ⇒ FileInfo
Get information about a single file or directory. Should follow symlinks (per http://cr.yp.to/ftp/list/eplf.html, “lstat() is not a good idea for FTP directory listings”).
Called for:
-
LIST
If missing, then these commands are not supported.
244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/ftpd/disk_file_system.rb', line 244 def file_info(ftp_path) stat = File.stat((ftp_path)) FileInfo.new(:ftype => stat.ftype, :group => gid_name(stat.gid), :identifier => identifier(stat), :mode => stat.mode, :mtime => stat.mtime, :nlink => stat.nlink, :owner => uid_name(stat.uid), :path => ftp_path, :size => stat.size) end |