From fec5d068a0056f5d9ec60e5fd3bbfad9b9f13b86 Mon Sep 17 00:00:00 2001
From: Pete Zaitcev <zaitcev@kotori.zaitcev.us>
Date: Wed, 18 Feb 2015 19:38:05 -0700
Subject: [PATCH] Fix crash with -l, -d /, and pseudo folders

Using -l, -d /, or a pseduo folder by itself works fine, but if you
combine all of them, this happens:

[zaitcev@guren s]$ swift list -d / testcont
amazon_lili.jpg
pseudodir/
rin_shibuya_pixiv.jpg
swift-c134855-5a.diff
[zaitcev@guren s]$ swift list -d / -l testcont
      151954 2014-06-20 17:13:52 amazon_lili.jpg
Traceback (most recent call last):
  File "/q/zaitcev/hail/python-swiftclient-tip/bin/swift", line 24, in <module>
    sys.exit(main())
  File "/q/zaitcev/hail/python-swiftclient-tip/swiftclient/shell.py", line 1301, in main
    globals()['st_%s' % args[0]](parser, argv[1:], output)
  File "/q/zaitcev/hail/python-swiftclient-tip/swiftclient/shell.py", line 414, in st_list
    total_bytes += item_bytes
TypeError: unsupported operand type(s) for +=: 'int' and 'NoneType'

The patch is a straightforward fix that assigns expected variables.

Change-Id: If24dcc2491e8b8982455107d2aca30c0491a398a
Closes-Bug: 1399678
---
 swiftclient/shell.py | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/swiftclient/shell.py b/swiftclient/shell.py
index ce779b33..439a92f3 100755
--- a/swiftclient/shell.py
+++ b/swiftclient/shell.py
@@ -410,9 +410,8 @@ def st_list(parser, args, output_manager):
                             output_manager.print_msg(
                                 item.get('name', item.get('subdir')))
                         else:
-                            item_bytes = item.get('bytes')
-                            total_bytes += item_bytes
                             if not container:    # listing containers
+                                item_bytes = item.get('bytes')
                                 byte_str = prt_bytes(item_bytes, options.human)
                                 count = item.get('count')
                                 total_count += count
@@ -431,19 +430,23 @@ def st_list(parser, args, output_manager):
                             else:    # list container contents
                                 subdir = item.get('subdir')
                                 if subdir is None:
+                                    item_bytes = item.get('bytes')
                                     byte_str = prt_bytes(
                                         item_bytes, options.human)
                                     date, xtime = item.get(
                                         'last_modified').split('T')
                                     xtime = xtime.split('.')[0]
                                 else:
-                                    byte_str = prt_bytes(0, options.human)
+                                    item_bytes = 0
+                                    byte_str = prt_bytes(
+                                        item_bytes, options.human)
                                     date = xtime = ''
                                     item_name = subdir
                                 if not options.totals:
                                     output_manager.print_msg(
                                         "%s %10s %8s %s", byte_str, date,
                                         xtime, item_name)
+                            total_bytes += item_bytes
 
                     # report totals
                     if options.long or options.human: