-l 完成

This commit is contained in:
Rikuoh Tsujitani 2024-05-24 14:18:08 +09:00
parent 5d59e49fb1
commit bb1374aca3

18
ls.rb
View file

@ -39,29 +39,33 @@ def list_filenames
filenames = params['a'] ? Dir.glob('*', File::FNM_DOTMATCH) : Dir.glob('*') filenames = params['a'] ? Dir.glob('*', File::FNM_DOTMATCH) : Dir.glob('*')
filenames = filenames.reverse if params['r'] filenames = filenames.reverse if params['r']
if params['l'] if params['l']
ownerinfo(filenames) output(filenames)
exit exit
else else
filenames filenames
end end
end end
def ownerinfo(filenames) def output(filenames)
file_blocks(filenames) file_blocks(filenames)
filenames.each do |file| filenames.each do |file|
file_stat = File::Stat.new(file) file_stat = File::Stat.new(file)
print " #{TYPES[file_stat.ftype]}" print TYPES[file_stat.ftype]
permission(file_stat) permission(file_stat)
print " #{file_stat.nlink}" printer(file_stat, filenames)
print " #{Etc.getpwuid(file_stat.uid).name}"
print " #{Etc.getgrgid(file_stat.gid).name}"
print " #{file_stat.size}".rjust(file_size(filenames))
timestamp(file_stat) timestamp(file_stat)
symbolic(file) symbolic(file)
puts puts
end end
end end
def printer(file_stat, filenames)
print " #{file_stat.nlink}"
print " #{Etc.getpwuid(file_stat.uid).name}"
print " #{Etc.getgrgid(file_stat.gid).name}"
print " #{file_stat.size}".rjust(file_size(filenames))
end
def symbolic(filenames) def symbolic(filenames)
if File.lstat(filenames).symlink? if File.lstat(filenames).symlink?
print " #{filenames} -> #{File.readlink(filenames)}" print " #{filenames} -> #{File.readlink(filenames)}"