-l 完成
This commit is contained in:
parent
5d59e49fb1
commit
bb1374aca3
1 changed files with 11 additions and 7 deletions
18
ls.rb
18
ls.rb
|
@ -39,29 +39,33 @@ def list_filenames
|
|||
filenames = params['a'] ? Dir.glob('*', File::FNM_DOTMATCH) : Dir.glob('*')
|
||||
filenames = filenames.reverse if params['r']
|
||||
if params['l']
|
||||
ownerinfo(filenames)
|
||||
output(filenames)
|
||||
exit
|
||||
else
|
||||
filenames
|
||||
end
|
||||
end
|
||||
|
||||
def ownerinfo(filenames)
|
||||
def output(filenames)
|
||||
file_blocks(filenames)
|
||||
filenames.each do |file|
|
||||
file_stat = File::Stat.new(file)
|
||||
print " #{TYPES[file_stat.ftype]}"
|
||||
print TYPES[file_stat.ftype]
|
||||
permission(file_stat)
|
||||
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))
|
||||
printer(file_stat, filenames)
|
||||
timestamp(file_stat)
|
||||
symbolic(file)
|
||||
puts
|
||||
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)
|
||||
if File.lstat(filenames).symlink?
|
||||
print " #{filenames} -> #{File.readlink(filenames)}"
|
||||
|
|
Loading…
Reference in a new issue