We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
'ls -al' incorrectly shows '..' files as duplicates of '.'
When using ls inside a cowrie instance the '..' entry is just a duplicate of the '.' entry. The group and user information is often wrong. This is a very easy to check fingerprint of cowrie. 

**To Reproduce**
Steps to reproduce the behavior:
1. SSH into a cowrie instance.
2. `cd /home/richard`
3. `ls -al`
4. The '..' entry has ownership 'richard richard'

**Expected behavior**
The information for the parent folder should be retrieved. In the case of '/home' from '/home/richard' the owner of '/home' should read as 'root root'

'ls -al' incorrectly shows '..' files as duplicates of '.'
When using ls inside a cowrie instance the '..' entry is just a duplicate of the '.' entry. The group and user information is often wrong. This is a very easy to check fingerprint of cowrie. 

**To Reproduce**
Steps to reproduce the behavior:
1. SSH into a cowrie instance.
2. `cd /home/richard`
3. `ls -al`
4. The '..' entry has ownership 'richard richard'

**Expected behavior**
The information for the parent folder should be retrieved. In the case of '/home' from '/home/richard' the owner of '/home' should read as 'root root'


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/cowrie/commands/ls.py`
Content:
```
1 # Copyright (c) 2009 Upi Tamminen <desaster@gmail.com>
2 # See the COPYRIGHT file for more information
3 
4 from __future__ import absolute_import, division
5 
6 import getopt
7 import stat
8 import time
9 
10 import cowrie.shell.fs as fs
11 from cowrie.shell.command import HoneyPotCommand
12 from cowrie.shell.pwd import Group, Passwd
13 
14 commands = {}
15 
16 
17 class command_ls(HoneyPotCommand):
18 
19     def uid2name(self, uid):
20         try:
21             return Passwd().getpwuid(uid)["pw_name"]
22         except Exception:
23             return str(uid)
24 
25     def gid2name(self, gid):
26         try:
27             return Group().getgrgid(gid)["gr_name"]
28         except Exception:
29             return str(gid)
30 
31     def call(self):
32         path = self.protocol.cwd
33         paths = []
34         self.showHidden = False
35         self.showDirectories = False
36         func = self.do_ls_normal
37 
38         # Parse options or display no files
39         try:
40             opts, args = getopt.gnu_getopt(self.args, '1@ABCFGHLOPRSTUWabcdefghiklmnopqrstuvwx',
41                                            ['help', 'version', 'param'])
42         except getopt.GetoptError as err:
43             self.write("ls: {}\n".format(err))
44             self.write("Try 'ls --help' for more information.\n")
45             return
46 
47         for x, a in opts:
48             if x in ('-l'):
49                 func = self.do_ls_l
50             if x in ('-a'):
51                 self.showHidden = True
52             if x in ('-d'):
53                 self.showDirectories = True
54 
55         for arg in args:
56             paths.append(self.protocol.fs.resolve_path(arg, self.protocol.cwd))
57 
58         if not paths:
59             func(path)
60         else:
61             for path in paths:
62                 func(path)
63 
64     def do_ls_normal(self, path):
65         try:
66             if self.protocol.fs.isdir(path) and not self.showDirectories:
67                 files = self.protocol.fs.get_path(path)[:]
68                 if self.showHidden:
69                     dot = self.protocol.fs.getfile(path)[:]
70                     dot[fs.A_NAME] = '.'
71                     files.append(dot)
72                     # FIXME: should grab dotdot off the parent instead
73                     dotdot = self.protocol.fs.getfile(path)[:]
74                     dotdot[fs.A_NAME] = '..'
75                     files.append(dotdot)
76                 else:
77                     files = [x for x in files if not x[fs.A_NAME].startswith('.')]
78                 files.sort()
79             else:
80                 files = (self.protocol.fs.getfile(path)[:],)
81         except Exception:
82             self.write(
83                 'ls: cannot access %s: No such file or directory\n' % (path,))
84             return
85 
86         line = [x[fs.A_NAME] for x in files]
87         if not line:
88             return
89         count = 0
90         maxlen = max([len(x) for x in line])
91 
92         try:
93             wincols = self.protocol.user.windowSize[1]
94         except AttributeError:
95             wincols = 80
96 
97         perline = int(wincols / (maxlen + 1))
98         for f in line:
99             if count == perline:
100                 count = 0
101                 self.write('\n')
102             self.write(f.ljust(maxlen + 1))
103             count += 1
104         self.write('\n')
105 
106     def do_ls_l(self, path):
107         try:
108             if self.protocol.fs.isdir(path) and not self.showDirectories:
109                 files = self.protocol.fs.get_path(path)[:]
110                 if self.showHidden:
111                     dot = self.protocol.fs.getfile(path)[:]
112                     dot[fs.A_NAME] = '.'
113                     files.append(dot)
114                     # FIXME: should grab dotdot off the parent instead
115                     dotdot = self.protocol.fs.getfile(path)[:]
116                     dotdot[fs.A_NAME] = '..'
117                     files.append(dotdot)
118                 else:
119                     files = [x for x in files if not x[fs.A_NAME].startswith('.')]
120                 files.sort()
121             else:
122                 files = (self.protocol.fs.getfile(path)[:],)
123         except Exception:
124             self.write(
125                 'ls: cannot access %s: No such file or directory\n' % (path,))
126             return
127 
128         largest = 0
129         if len(files):
130             largest = max([x[fs.A_SIZE] for x in files])
131 
132         for file in files:
133             if file[fs.A_NAME].startswith('.') and not self.showHidden:
134                 continue
135 
136             perms = ['-'] * 10
137             if file[fs.A_MODE] & stat.S_IRUSR:
138                 perms[1] = 'r'
139             if file[fs.A_MODE] & stat.S_IWUSR:
140                 perms[2] = 'w'
141             if file[fs.A_MODE] & stat.S_IXUSR:
142                 perms[3] = 'x'
143             if file[fs.A_MODE] & stat.S_ISUID:
144                 perms[3] = 'S'
145             if file[fs.A_MODE] & stat.S_IXUSR and file[fs.A_MODE] & stat.S_ISUID:
146                 perms[3] = 's'
147 
148             if file[fs.A_MODE] & stat.S_IRGRP:
149                 perms[4] = 'r'
150             if file[fs.A_MODE] & stat.S_IWGRP:
151                 perms[5] = 'w'
152             if file[fs.A_MODE] & stat.S_IXGRP:
153                 perms[6] = 'x'
154             if file[fs.A_MODE] & stat.S_ISGID:
155                 perms[6] = 'S'
156             if file[fs.A_MODE] & stat.S_IXGRP and file[fs.A_MODE] & stat.S_ISGID:
157                 perms[6] = 's'
158 
159             if file[fs.A_MODE] & stat.S_IROTH:
160                 perms[7] = 'r'
161             if file[fs.A_MODE] & stat.S_IWOTH:
162                 perms[8] = 'w'
163             if file[fs.A_MODE] & stat.S_IXOTH:
164                 perms[9] = 'x'
165             if file[fs.A_MODE] & stat.S_ISVTX:
166                 perms[9] = 'T'
167             if file[fs.A_MODE] & stat.S_IXOTH and file[fs.A_MODE] & stat.S_ISVTX:
168                 perms[9] = 't'
169 
170             linktarget = ''
171 
172             if file[fs.A_TYPE] == fs.T_DIR:
173                 perms[0] = 'd'
174             elif file[fs.A_TYPE] == fs.T_LINK:
175                 perms[0] = 'l'
176                 linktarget = ' -> %s' % (file[fs.A_TARGET],)
177 
178             perms = ''.join(perms)
179             ctime = time.localtime(file[fs.A_CTIME])
180 
181             line = '%s 1 %s %s %s %s %s%s' % \
182                 (perms,
183                  self.uid2name(file[fs.A_UID]),
184                  self.gid2name(file[fs.A_GID]),
185                  str(file[fs.A_SIZE]).rjust(len(str(largest))),
186                  time.strftime('%Y-%m-%d %H:%M', ctime),
187                  file[fs.A_NAME],
188                  linktarget)
189 
190             self.write('{0}\n'.format(line))
191 
192 
193 commands['/bin/ls'] = command_ls
194 commands['ls'] = command_ls
195 commands['/bin/dir'] = command_ls
196 commands['dir'] = command_ls
197
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/cowrie/commands/ls.py b/src/cowrie/commands/ls.py
--- a/src/cowrie/commands/ls.py
+++ b/src/cowrie/commands/ls.py
@@ -4,6 +4,7 @@
 from __future__ import absolute_import, division
 
 import getopt
+import os.path
 import stat
 import time
 
@@ -61,7 +62,7 @@
             for path in paths:
                 func(path)
 
-    def do_ls_normal(self, path):
+    def get_dir_files(self, path):
         try:
             if self.protocol.fs.isdir(path) and not self.showDirectories:
                 files = self.protocol.fs.get_path(path)[:]
@@ -69,8 +70,9 @@
                     dot = self.protocol.fs.getfile(path)[:]
                     dot[fs.A_NAME] = '.'
                     files.append(dot)
-                    # FIXME: should grab dotdot off the parent instead
-                    dotdot = self.protocol.fs.getfile(path)[:]
+                    dotdot = self.protocol.fs.getfile(os.path.split(path)[0])[:]
+                    if not dotdot:
+                        dotdot = self.protocol.fs.getfile(path)[:]
                     dotdot[fs.A_NAME] = '..'
                     files.append(dotdot)
                 else:
@@ -82,6 +84,10 @@
             self.write(
                 'ls: cannot access %s: No such file or directory\n' % (path,))
             return
+        return files
+
+    def do_ls_normal(self, path):
+        files = self.get_dir_files(path)
 
         line = [x[fs.A_NAME] for x in files]
         if not line:
@@ -104,26 +110,7 @@
         self.write('\n')
 
     def do_ls_l(self, path):
-        try:
-            if self.protocol.fs.isdir(path) and not self.showDirectories:
-                files = self.protocol.fs.get_path(path)[:]
-                if self.showHidden:
-                    dot = self.protocol.fs.getfile(path)[:]
-                    dot[fs.A_NAME] = '.'
-                    files.append(dot)
-                    # FIXME: should grab dotdot off the parent instead
-                    dotdot = self.protocol.fs.getfile(path)[:]
-                    dotdot[fs.A_NAME] = '..'
-                    files.append(dotdot)
-                else:
-                    files = [x for x in files if not x[fs.A_NAME].startswith('.')]
-                files.sort()
-            else:
-                files = (self.protocol.fs.getfile(path)[:],)
-        except Exception:
-            self.write(
-                'ls: cannot access %s: No such file or directory\n' % (path,))
-            return
+        files = self.get_dir_files(path)
 
         largest = 0
         if len(files):

{"golden_diff": "diff --git a/src/cowrie/commands/ls.py b/src/cowrie/commands/ls.py\n--- a/src/cowrie/commands/ls.py\n+++ b/src/cowrie/commands/ls.py\n@@ -4,6 +4,7 @@\n from __future__ import absolute_import, division\n \n import getopt\n+import os.path\n import stat\n import time\n \n@@ -61,7 +62,7 @@\n             for path in paths:\n                 func(path)\n \n-    def do_ls_normal(self, path):\n+    def get_dir_files(self, path):\n         try:\n             if self.protocol.fs.isdir(path) and not self.showDirectories:\n                 files = self.protocol.fs.get_path(path)[:]\n@@ -69,8 +70,9 @@\n                     dot = self.protocol.fs.getfile(path)[:]\n                     dot[fs.A_NAME] = '.'\n                     files.append(dot)\n-                    # FIXME: should grab dotdot off the parent instead\n-                    dotdot = self.protocol.fs.getfile(path)[:]\n+                    dotdot = self.protocol.fs.getfile(os.path.split(path)[0])[:]\n+                    if not dotdot:\n+                        dotdot = self.protocol.fs.getfile(path)[:]\n                     dotdot[fs.A_NAME] = '..'\n                     files.append(dotdot)\n                 else:\n@@ -82,6 +84,10 @@\n             self.write(\n                 'ls: cannot access %s: No such file or directory\\n' % (path,))\n             return\n+        return files\n+\n+    def do_ls_normal(self, path):\n+        files = self.get_dir_files(path)\n \n         line = [x[fs.A_NAME] for x in files]\n         if not line:\n@@ -104,26 +110,7 @@\n         self.write('\\n')\n \n     def do_ls_l(self, path):\n-        try:\n-            if self.protocol.fs.isdir(path) and not self.showDirectories:\n-                files = self.protocol.fs.get_path(path)[:]\n-                if self.showHidden:\n-                    dot = self.protocol.fs.getfile(path)[:]\n-                    dot[fs.A_NAME] = '.'\n-                    files.append(dot)\n-                    # FIXME: should grab dotdot off the parent instead\n-                    dotdot = self.protocol.fs.getfile(path)[:]\n-                    dotdot[fs.A_NAME] = '..'\n-                    files.append(dotdot)\n-                else:\n-                    files = [x for x in files if not x[fs.A_NAME].startswith('.')]\n-                files.sort()\n-            else:\n-                files = (self.protocol.fs.getfile(path)[:],)\n-        except Exception:\n-            self.write(\n-                'ls: cannot access %s: No such file or directory\\n' % (path,))\n-            return\n+        files = self.get_dir_files(path)\n \n         largest = 0\n         if len(files):\n", "issue": "'ls -al' incorrectly shows '..' files as duplicates of '.'\nWhen using ls inside a cowrie instance the '..' entry is just a duplicate of the '.' entry. The group and user information is often wrong. This is a very easy to check fingerprint of cowrie. \r\n\r\n**To Reproduce**\r\nSteps to reproduce the behavior:\r\n1. SSH into a cowrie instance.\r\n2. `cd /home/richard`\r\n3. `ls -al`\r\n4. The '..' entry has ownership 'richard richard'\r\n\r\n**Expected behavior**\r\nThe information for the parent folder should be retrieved. In the case of '/home' from '/home/richard' the owner of '/home' should read as 'root root'\r\n\n'ls -al' incorrectly shows '..' files as duplicates of '.'\nWhen using ls inside a cowrie instance the '..' entry is just a duplicate of the '.' entry. The group and user information is often wrong. This is a very easy to check fingerprint of cowrie. \r\n\r\n**To Reproduce**\r\nSteps to reproduce the behavior:\r\n1. SSH into a cowrie instance.\r\n2. `cd /home/richard`\r\n3. `ls -al`\r\n4. The '..' entry has ownership 'richard richard'\r\n\r\n**Expected behavior**\r\nThe information for the parent folder should be retrieved. In the case of '/home' from '/home/richard' the owner of '/home' should read as 'root root'\r\n\n", "before_files": [{"content": "# Copyright (c) 2009 Upi Tamminen <desaster@gmail.com>\n# See the COPYRIGHT file for more information\n\nfrom __future__ import absolute_import, division\n\nimport getopt\nimport stat\nimport time\n\nimport cowrie.shell.fs as fs\nfrom cowrie.shell.command import HoneyPotCommand\nfrom cowrie.shell.pwd import Group, Passwd\n\ncommands = {}\n\n\nclass command_ls(HoneyPotCommand):\n\n    def uid2name(self, uid):\n        try:\n            return Passwd().getpwuid(uid)[\"pw_name\"]\n        except Exception:\n            return str(uid)\n\n    def gid2name(self, gid):\n        try:\n            return Group().getgrgid(gid)[\"gr_name\"]\n        except Exception:\n            return str(gid)\n\n    def call(self):\n        path = self.protocol.cwd\n        paths = []\n        self.showHidden = False\n        self.showDirectories = False\n        func = self.do_ls_normal\n\n        # Parse options or display no files\n        try:\n            opts, args = getopt.gnu_getopt(self.args, '1@ABCFGHLOPRSTUWabcdefghiklmnopqrstuvwx',\n                                           ['help', 'version', 'param'])\n        except getopt.GetoptError as err:\n            self.write(\"ls: {}\\n\".format(err))\n            self.write(\"Try 'ls --help' for more information.\\n\")\n            return\n\n        for x, a in opts:\n            if x in ('-l'):\n                func = self.do_ls_l\n            if x in ('-a'):\n                self.showHidden = True\n            if x in ('-d'):\n                self.showDirectories = True\n\n        for arg in args:\n            paths.append(self.protocol.fs.resolve_path(arg, self.protocol.cwd))\n\n        if not paths:\n            func(path)\n        else:\n            for path in paths:\n                func(path)\n\n    def do_ls_normal(self, path):\n        try:\n            if self.protocol.fs.isdir(path) and not self.showDirectories:\n                files = self.protocol.fs.get_path(path)[:]\n                if self.showHidden:\n                    dot = self.protocol.fs.getfile(path)[:]\n                    dot[fs.A_NAME] = '.'\n                    files.append(dot)\n                    # FIXME: should grab dotdot off the parent instead\n                    dotdot = self.protocol.fs.getfile(path)[:]\n                    dotdot[fs.A_NAME] = '..'\n                    files.append(dotdot)\n                else:\n                    files = [x for x in files if not x[fs.A_NAME].startswith('.')]\n                files.sort()\n            else:\n                files = (self.protocol.fs.getfile(path)[:],)\n        except Exception:\n            self.write(\n                'ls: cannot access %s: No such file or directory\\n' % (path,))\n            return\n\n        line = [x[fs.A_NAME] for x in files]\n        if not line:\n            return\n        count = 0\n        maxlen = max([len(x) for x in line])\n\n        try:\n            wincols = self.protocol.user.windowSize[1]\n        except AttributeError:\n            wincols = 80\n\n        perline = int(wincols / (maxlen + 1))\n        for f in line:\n            if count == perline:\n                count = 0\n                self.write('\\n')\n            self.write(f.ljust(maxlen + 1))\n            count += 1\n        self.write('\\n')\n\n    def do_ls_l(self, path):\n        try:\n            if self.protocol.fs.isdir(path) and not self.showDirectories:\n                files = self.protocol.fs.get_path(path)[:]\n                if self.showHidden:\n                    dot = self.protocol.fs.getfile(path)[:]\n                    dot[fs.A_NAME] = '.'\n                    files.append(dot)\n                    # FIXME: should grab dotdot off the parent instead\n                    dotdot = self.protocol.fs.getfile(path)[:]\n                    dotdot[fs.A_NAME] = '..'\n                    files.append(dotdot)\n                else:\n                    files = [x for x in files if not x[fs.A_NAME].startswith('.')]\n                files.sort()\n            else:\n                files = (self.protocol.fs.getfile(path)[:],)\n        except Exception:\n            self.write(\n                'ls: cannot access %s: No such file or directory\\n' % (path,))\n            return\n\n        largest = 0\n        if len(files):\n            largest = max([x[fs.A_SIZE] for x in files])\n\n        for file in files:\n            if file[fs.A_NAME].startswith('.') and not self.showHidden:\n                continue\n\n            perms = ['-'] * 10\n            if file[fs.A_MODE] & stat.S_IRUSR:\n                perms[1] = 'r'\n            if file[fs.A_MODE] & stat.S_IWUSR:\n                perms[2] = 'w'\n            if file[fs.A_MODE] & stat.S_IXUSR:\n                perms[3] = 'x'\n            if file[fs.A_MODE] & stat.S_ISUID:\n                perms[3] = 'S'\n            if file[fs.A_MODE] & stat.S_IXUSR and file[fs.A_MODE] & stat.S_ISUID:\n                perms[3] = 's'\n\n            if file[fs.A_MODE] & stat.S_IRGRP:\n                perms[4] = 'r'\n            if file[fs.A_MODE] & stat.S_IWGRP:\n                perms[5] = 'w'\n            if file[fs.A_MODE] & stat.S_IXGRP:\n                perms[6] = 'x'\n            if file[fs.A_MODE] & stat.S_ISGID:\n                perms[6] = 'S'\n            if file[fs.A_MODE] & stat.S_IXGRP and file[fs.A_MODE] & stat.S_ISGID:\n                perms[6] = 's'\n\n            if file[fs.A_MODE] & stat.S_IROTH:\n                perms[7] = 'r'\n            if file[fs.A_MODE] & stat.S_IWOTH:\n                perms[8] = 'w'\n            if file[fs.A_MODE] & stat.S_IXOTH:\n                perms[9] = 'x'\n            if file[fs.A_MODE] & stat.S_ISVTX:\n                perms[9] = 'T'\n            if file[fs.A_MODE] & stat.S_IXOTH and file[fs.A_MODE] & stat.S_ISVTX:\n                perms[9] = 't'\n\n            linktarget = ''\n\n            if file[fs.A_TYPE] == fs.T_DIR:\n                perms[0] = 'd'\n            elif file[fs.A_TYPE] == fs.T_LINK:\n                perms[0] = 'l'\n                linktarget = ' -> %s' % (file[fs.A_TARGET],)\n\n            perms = ''.join(perms)\n            ctime = time.localtime(file[fs.A_CTIME])\n\n            line = '%s 1 %s %s %s %s %s%s' % \\\n                (perms,\n                 self.uid2name(file[fs.A_UID]),\n                 self.gid2name(file[fs.A_GID]),\n                 str(file[fs.A_SIZE]).rjust(len(str(largest))),\n                 time.strftime('%Y-%m-%d %H:%M', ctime),\n                 file[fs.A_NAME],\n                 linktarget)\n\n            self.write('{0}\\n'.format(line))\n\n\ncommands['/bin/ls'] = command_ls\ncommands['ls'] = command_ls\ncommands['/bin/dir'] = command_ls\ncommands['dir'] = command_ls\n", "path": "src/cowrie/commands/ls.py"}], "after_files": [{"content": "# Copyright (c) 2009 Upi Tamminen <desaster@gmail.com>\n# See the COPYRIGHT file for more information\n\nfrom __future__ import absolute_import, division\n\nimport getopt\nimport os.path\nimport stat\nimport time\n\nimport cowrie.shell.fs as fs\nfrom cowrie.shell.command import HoneyPotCommand\nfrom cowrie.shell.pwd import Group, Passwd\n\ncommands = {}\n\n\nclass command_ls(HoneyPotCommand):\n\n    def uid2name(self, uid):\n        try:\n            return Passwd().getpwuid(uid)[\"pw_name\"]\n        except Exception:\n            return str(uid)\n\n    def gid2name(self, gid):\n        try:\n            return Group().getgrgid(gid)[\"gr_name\"]\n        except Exception:\n            return str(gid)\n\n    def call(self):\n        path = self.protocol.cwd\n        paths = []\n        self.showHidden = False\n        self.showDirectories = False\n        func = self.do_ls_normal\n\n        # Parse options or display no files\n        try:\n            opts, args = getopt.gnu_getopt(self.args, '1@ABCFGHLOPRSTUWabcdefghiklmnopqrstuvwx',\n                                           ['help', 'version', 'param'])\n        except getopt.GetoptError as err:\n            self.write(\"ls: {}\\n\".format(err))\n            self.write(\"Try 'ls --help' for more information.\\n\")\n            return\n\n        for x, a in opts:\n            if x in ('-l'):\n                func = self.do_ls_l\n            if x in ('-a'):\n                self.showHidden = True\n            if x in ('-d'):\n                self.showDirectories = True\n\n        for arg in args:\n            paths.append(self.protocol.fs.resolve_path(arg, self.protocol.cwd))\n\n        if not paths:\n            func(path)\n        else:\n            for path in paths:\n                func(path)\n\n    def get_dir_files(self, path):\n        try:\n            if self.protocol.fs.isdir(path) and not self.showDirectories:\n                files = self.protocol.fs.get_path(path)[:]\n                if self.showHidden:\n                    dot = self.protocol.fs.getfile(path)[:]\n                    dot[fs.A_NAME] = '.'\n                    files.append(dot)\n                    dotdot = self.protocol.fs.getfile(os.path.split(path)[0])[:]\n                    if not dotdot:\n                        dotdot = self.protocol.fs.getfile(path)[:]\n                    dotdot[fs.A_NAME] = '..'\n                    files.append(dotdot)\n                else:\n                    files = [x for x in files if not x[fs.A_NAME].startswith('.')]\n                files.sort()\n            else:\n                files = (self.protocol.fs.getfile(path)[:],)\n        except Exception:\n            self.write(\n                'ls: cannot access %s: No such file or directory\\n' % (path,))\n            return\n        return files\n\n    def do_ls_normal(self, path):\n        files = self.get_dir_files(path)\n\n        line = [x[fs.A_NAME] for x in files]\n        if not line:\n            return\n        count = 0\n        maxlen = max([len(x) for x in line])\n\n        try:\n            wincols = self.protocol.user.windowSize[1]\n        except AttributeError:\n            wincols = 80\n\n        perline = int(wincols / (maxlen + 1))\n        for f in line:\n            if count == perline:\n                count = 0\n                self.write('\\n')\n            self.write(f.ljust(maxlen + 1))\n            count += 1\n        self.write('\\n')\n\n    def do_ls_l(self, path):\n        files = self.get_dir_files(path)\n\n        largest = 0\n        if len(files):\n            largest = max([x[fs.A_SIZE] for x in files])\n\n        for file in files:\n            if file[fs.A_NAME].startswith('.') and not self.showHidden:\n                continue\n\n            perms = ['-'] * 10\n            if file[fs.A_MODE] & stat.S_IRUSR:\n                perms[1] = 'r'\n            if file[fs.A_MODE] & stat.S_IWUSR:\n                perms[2] = 'w'\n            if file[fs.A_MODE] & stat.S_IXUSR:\n                perms[3] = 'x'\n            if file[fs.A_MODE] & stat.S_ISUID:\n                perms[3] = 'S'\n            if file[fs.A_MODE] & stat.S_IXUSR and file[fs.A_MODE] & stat.S_ISUID:\n                perms[3] = 's'\n\n            if file[fs.A_MODE] & stat.S_IRGRP:\n                perms[4] = 'r'\n            if file[fs.A_MODE] & stat.S_IWGRP:\n                perms[5] = 'w'\n            if file[fs.A_MODE] & stat.S_IXGRP:\n                perms[6] = 'x'\n            if file[fs.A_MODE] & stat.S_ISGID:\n                perms[6] = 'S'\n            if file[fs.A_MODE] & stat.S_IXGRP and file[fs.A_MODE] & stat.S_ISGID:\n                perms[6] = 's'\n\n            if file[fs.A_MODE] & stat.S_IROTH:\n                perms[7] = 'r'\n            if file[fs.A_MODE] & stat.S_IWOTH:\n                perms[8] = 'w'\n            if file[fs.A_MODE] & stat.S_IXOTH:\n                perms[9] = 'x'\n            if file[fs.A_MODE] & stat.S_ISVTX:\n                perms[9] = 'T'\n            if file[fs.A_MODE] & stat.S_IXOTH and file[fs.A_MODE] & stat.S_ISVTX:\n                perms[9] = 't'\n\n            linktarget = ''\n\n            if file[fs.A_TYPE] == fs.T_DIR:\n                perms[0] = 'd'\n            elif file[fs.A_TYPE] == fs.T_LINK:\n                perms[0] = 'l'\n                linktarget = ' -> %s' % (file[fs.A_TARGET],)\n\n            perms = ''.join(perms)\n            ctime = time.localtime(file[fs.A_CTIME])\n\n            line = '%s 1 %s %s %s %s %s%s' % \\\n                (perms,\n                 self.uid2name(file[fs.A_UID]),\n                 self.gid2name(file[fs.A_GID]),\n                 str(file[fs.A_SIZE]).rjust(len(str(largest))),\n                 time.strftime('%Y-%m-%d %H:%M', ctime),\n                 file[fs.A_NAME],\n                 linktarget)\n\n            self.write('{0}\\n'.format(line))\n\n\ncommands['/bin/ls'] = command_ls\ncommands['ls'] = command_ls\ncommands['/bin/dir'] = command_ls\ncommands['dir'] = command_ls\n", "path": "src/cowrie/commands/ls.py"}]}