Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions lib/net/sftp/protocol/04/name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def file?
# used by the unix "ls" utility.
def longname
@longname ||= begin
permissions = attributes.permissions || 0
longname = if directory?
"d"
elsif symlink?
Expand All @@ -46,22 +47,26 @@ def longname
"-"
end

longname << (attributes.permissions & 0400 != 0 ? "r" : "-")
longname << (attributes.permissions & 0200 != 0 ? "w" : "-")
longname << (attributes.permissions & 0100 != 0 ? "x" : "-")
longname << (attributes.permissions & 0040 != 0 ? "r" : "-")
longname << (attributes.permissions & 0020 != 0 ? "w" : "-")
longname << (attributes.permissions & 0010 != 0 ? "x" : "-")
longname << (attributes.permissions & 0004 != 0 ? "r" : "-")
longname << (attributes.permissions & 0002 != 0 ? "w" : "-")
longname << (attributes.permissions & 0001 != 0 ? "x" : "-")
longname << (permissions & 0400 != 0 ? "r" : "-")
longname << (permissions & 0200 != 0 ? "w" : "-")
longname << (permissions & 0100 != 0 ? "x" : "-")
longname << (permissions & 0040 != 0 ? "r" : "-")
longname << (permissions & 0020 != 0 ? "w" : "-")
longname << (permissions & 0010 != 0 ? "x" : "-")
longname << (permissions & 0004 != 0 ? "r" : "-")
longname << (permissions & 0002 != 0 ? "w" : "-")
longname << (permissions & 0001 != 0 ? "x" : "-")

longname << (" %-8s %-8s %8d " % [attributes.owner, attributes.group, attributes.size])
longname << (" %-8s %-8s %8s " % [attributes.owner, attributes.group, attributes.size || "-"])

longname << Time.at(attributes.mtime).strftime("%b %e %H:%M ")
longname << if attributes.mtime
Time.at(attributes.mtime).strftime("%b %e %H:%M ")
else
" " * 13
end
longname << name
end
end
end

end; end; end; end
end; end; end; end
9 changes: 9 additions & 0 deletions test/protocol/04/test_name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,13 @@ def test_longname_for_file_should_format_as_file
assert_equal "-rwxr-xr-x jamis users 10240 Mar 12 03:40 test",
@file.longname
end

def test_longname_should_tolerate_omitted_optional_attributes
sparse = Net::SFTP::Protocol::V04::Name.new(
"test",
Net::SFTP::Protocol::V04::Attributes.new(:type => 1)
)

assert_equal "---------- - test", sparse.longname
end
end