]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephfs-shell: Fix 'du' command error
authorVarsha Rao <varao@redhat.com>
Wed, 10 Jul 2019 15:17:22 +0000 (20:47 +0530)
committerRishabh Dave <ridave@redhat.com>
Wed, 11 Sep 2019 13:30:05 +0000 (19:00 +0530)
This patch fixes the following:
* No error message outputed for non existing directories.
* Takes only single argument.
* When no arguments are passed, existing directories in the current directory
  are not displayed.
* Always '.' is concated to the path.

Fixes: https://tracker.ceph.com/issues/39641
Signed-off-by: Varsha Rao <varao@redhat.com>
src/tools/cephfs/cephfs-shell

index 1fa54bc07769c2b11540ca1dedcef052e7afa0c8..ea58a960ae51bde451fff3b200491bd3d5a0726d 100755 (executable)
@@ -1123,8 +1123,8 @@ sub-directories, files')
     du_parser = argparse.ArgumentParser(
         description='Disk Usage of a Directory')
     du_parser.add_argument('dirs', type=str, action=path_to_bytes,
-                           help='Name of the directory.', nargs='?',
-                           default='.')
+                           help='Name of the directory.', nargs='*',
+                           default='')
     du_parser.add_argument('-r', action='store_true',
                            help='Recursive Disk usage of all directories.')
 
@@ -1133,19 +1133,36 @@ sub-directories, files')
         """
         Disk Usage of a Directory
         """
+        dir_passed = args.dirs
         if args.dirs == b'':
-            args.dirs = cephfs.getcwd()
-        for dir_ in args.dirs:
+            dir_passed = cephfs.getcwd()
+            if len(dir_passed) > 1:
+                dir_passed = dir_passed.split()
+
+        for dir_ in dir_passed:
+            dir_trav = sorted(set(dirwalk(dir_)))
+            if args.dirs and not dir_trav:
+                dir_trav.append(dir_)
+            else:
+                dir_trav.append('.')
+
             if args.r:
-                for i in reversed(sorted(set(dirwalk(dir_)))):
-                    i = os.path.normpath(i)
-                    try:
-                        xattr = cephfs.getxattr(i, 'ceph.dir.rbytes')
-                        self.poutput('{:10s} {}'.format(
-                            humansize(int(xattr.decode('utf-8'))), '.'
-                            + i.decode('utf-8')))
-                    except libcephfs.Error:
-                        continue
+                dir_trav = reversed(dir_trav)
+
+            for i in dir_trav:
+                try:
+                    i_path = os.path.normpath(i)
+                    if (i != '.') and (i_path[0] == '/'):
+                        i = '.' + i_path
+
+                    xattr = cephfs.getxattr(i_path,
+                                            'ceph.dir.rbytes')
+                    self.poutput('{:10s} {}'.format(humansize(int(
+                                 xattr.decode('utf-8'))), i.decode('utf-8'))
+                except (libcephfs.Error, OSError):
+                    self.perror('{}: no such directory exists'.format(dir_),
+                                False)
+                    continue
             else:
                 dir_ = os.path.normpath(dir_)
                 self.poutput('{:10s} {}'.format(humansize(int(cephfs.getxattr(